Mercurial > public > mercurial-scm > hg
comparison contrib/check-py3-compat.py @ 32212:65cd7e705ff6
policy: eliminate ".pure." from module name only if marked as dual
So we can switch cext/pure modules to new layout one by one.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 13 Aug 2016 17:21:58 +0900 |
parents | b85fa6bf298b |
children | 9b81fb217820 |
comparison
equal
deleted
inserted
replaced
32211:c48583859e04 | 32212:65cd7e705ff6 |
---|---|
11 | 11 |
12 import ast | 12 import ast |
13 import os | 13 import os |
14 import sys | 14 import sys |
15 import traceback | 15 import traceback |
16 | |
17 # Modules that have both Python and C implementations. | |
18 _dualmodules = ( | |
19 'base85.py', | |
20 'bdiff.py', | |
21 'diffhelpers.py', | |
22 'mpatch.py', | |
23 'osutil.py', | |
24 'parsers.py', | |
25 ) | |
16 | 26 |
17 def check_compat_py2(f): | 27 def check_compat_py2(f): |
18 """Check Python 3 compatibility for a file with Python 2""" | 28 """Check Python 3 compatibility for a file with Python 2""" |
19 with open(f, 'rb') as fh: | 29 with open(f, 'rb') as fh: |
20 content = fh.read() | 30 content = fh.read() |
53 # Try to import the module. | 63 # Try to import the module. |
54 # For now we only support mercurial.* and hgext.* modules because figuring | 64 # For now we only support mercurial.* and hgext.* modules because figuring |
55 # out module paths for things not in a package can be confusing. | 65 # out module paths for things not in a package can be confusing. |
56 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): | 66 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): |
57 assert f.endswith('.py') | 67 assert f.endswith('.py') |
58 name = f.replace('/', '.')[:-3].replace('.pure.', '.') | 68 name = f.replace('/', '.')[:-3] |
69 if f.endswith(_dualmodules): | |
70 name = name.replace('.pure.', '.') | |
59 try: | 71 try: |
60 importlib.import_module(name) | 72 importlib.import_module(name) |
61 except Exception as e: | 73 except Exception as e: |
62 exc_type, exc_value, tb = sys.exc_info() | 74 exc_type, exc_value, tb = sys.exc_info() |
63 # We walk the stack and ignore frames from our custom importer, | 75 # We walk the stack and ignore frames from our custom importer, |