comparison contrib/check-py3-compat.py @ 30095:e8aeeb28e35e

py3: remove superfluous indent from check-py3-compat.py
author Yuya Nishihara <yuya@tcha.org>
date Sat, 08 Oct 2016 17:22:40 +0200
parents f701fffd21d8
children b85fa6bf298b
comparison
equal deleted inserted replaced
30094:f701fffd21d8 30095:e8aeeb28e35e
54 # For now we only support mercurial.* and hgext.* modules because figuring 54 # For now we only support mercurial.* and hgext.* modules because figuring
55 # out module paths for things not in a package can be confusing. 55 # out module paths for things not in a package can be confusing.
56 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): 56 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'):
57 assert f.endswith('.py') 57 assert f.endswith('.py')
58 name = f.replace('/', '.')[:-3].replace('.pure.', '.') 58 name = f.replace('/', '.')[:-3].replace('.pure.', '.')
59 if True: 59 try:
60 try: 60 importlib.import_module(name)
61 importlib.import_module(name) 61 except Exception as e:
62 except Exception as e: 62 exc_type, exc_value, tb = sys.exc_info()
63 exc_type, exc_value, tb = sys.exc_info() 63 # We walk the stack and ignore frames from our custom importer,
64 # We walk the stack and ignore frames from our custom importer, 64 # import mechanisms, and stdlib modules. This kinda/sorta
65 # import mechanisms, and stdlib modules. This kinda/sorta 65 # emulates CPython behavior in import.c while also attempting
66 # emulates CPython behavior in import.c while also attempting 66 # to pin blame on a Mercurial file.
67 # to pin blame on a Mercurial file. 67 for frame in reversed(traceback.extract_tb(tb)):
68 for frame in reversed(traceback.extract_tb(tb)): 68 if frame.name == '_call_with_frames_removed':
69 if frame.name == '_call_with_frames_removed': 69 continue
70 continue 70 if 'importlib' in frame.filename:
71 if 'importlib' in frame.filename: 71 continue
72 continue 72 if 'mercurial/__init__.py' in frame.filename:
73 if 'mercurial/__init__.py' in frame.filename: 73 continue
74 continue 74 if frame.filename.startswith(sys.prefix):
75 if frame.filename.startswith(sys.prefix): 75 continue
76 continue 76 break
77 break
78 77
79 if frame.filename: 78 if frame.filename:
80 filename = os.path.basename(frame.filename) 79 filename = os.path.basename(frame.filename)
81 print('%s: error importing: <%s> %s (error at %s:%d)' % ( 80 print('%s: error importing: <%s> %s (error at %s:%d)' % (
82 f, type(e).__name__, e, filename, frame.lineno)) 81 f, type(e).__name__, e, filename, frame.lineno))
83 else: 82 else:
84 print('%s: error importing module: <%s> %s (line %d)' % ( 83 print('%s: error importing module: <%s> %s (line %d)' % (
85 f, type(e).__name__, e, frame.lineno)) 84 f, type(e).__name__, e, frame.lineno))
86 85
87 if __name__ == '__main__': 86 if __name__ == '__main__':
88 if sys.version_info[0] == 2: 87 if sys.version_info[0] == 2:
89 fn = check_compat_py2 88 fn = check_compat_py2
90 else: 89 else: