Mercurial > hg
comparison contrib/check-py3-compat.py @ 32374:194b0f781132
import-checker: drop workaround for pure modules
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 13 Aug 2016 12:29:53 +0900 |
parents | df448de7cf3b |
children | 778dc37ce683 |
comparison
equal
deleted
inserted
replaced
32373:5700825889fb | 32374:194b0f781132 |
---|---|
12 import ast | 12 import ast |
13 import importlib | 13 import importlib |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 import traceback | 16 import traceback |
17 | |
18 # Modules that have both Python and C implementations. | |
19 _dualmodules = ( | |
20 ) | |
21 | 17 |
22 def check_compat_py2(f): | 18 def check_compat_py2(f): |
23 """Check Python 3 compatibility for a file with Python 2""" | 19 """Check Python 3 compatibility for a file with Python 2""" |
24 with open(f, 'rb') as fh: | 20 with open(f, 'rb') as fh: |
25 content = fh.read() | 21 content = fh.read() |
58 # For now we only support mercurial.* and hgext.* modules because figuring | 54 # For now we only support mercurial.* and hgext.* modules because figuring |
59 # 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. |
60 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): | 56 if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): |
61 assert f.endswith('.py') | 57 assert f.endswith('.py') |
62 name = f.replace('/', '.')[:-3] | 58 name = f.replace('/', '.')[:-3] |
63 if f.endswith(_dualmodules): | |
64 name = name.replace('.pure.', '.') | |
65 try: | 59 try: |
66 importlib.import_module(name) | 60 importlib.import_module(name) |
67 except Exception as e: | 61 except Exception as e: |
68 exc_type, exc_value, tb = sys.exc_info() | 62 exc_type, exc_value, tb = sys.exc_info() |
69 # We walk the stack and ignore frames from our custom importer, | 63 # We walk the stack and ignore frames from our custom importer, |