Mercurial > public > mercurial-scm > hg-stable
comparison contrib/check-py3-compat.py @ 29763:8faac092bb0c
py3: make check-py3-compat.py use correct module name at loading pure modules
Before this patch, check-py3-compat.py implies unintentional ".pure"
sub-package name at loading pure modules, because module name is
composed by just replacing "/" in the path to actual ".py" file by
".".
This makes pure modules belong to "mercurial.pure" package, and
prevents them from importing a module belonging to "mercurial" package
relatively by "from . import foo" or so.
This is reason why pure modules fail to import another module
relatively only at examination by check-py3-compat.py.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 09 Aug 2016 02:28:34 +0900 |
parents | 1c22400db72d |
children | 68010ed1636d |
comparison
equal
deleted
inserted
replaced
29762:297a0dc50320 | 29763:8faac092bb0c |
---|---|
53 # Try to import the module. | 53 # Try to import the module. |
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] | 58 name = f.replace('/', '.')[:-3].replace('.pure.', '.') |
59 with open(f, 'r') as fh: | 59 with open(f, 'r') as fh: |
60 try: | 60 try: |
61 imp.load_module(name, fh, '', ('py', 'r', imp.PY_SOURCE)) | 61 imp.load_module(name, fh, '', ('py', 'r', imp.PY_SOURCE)) |
62 except Exception as e: | 62 except Exception as e: |
63 exc_type, exc_value, tb = sys.exc_info() | 63 exc_type, exc_value, tb = sys.exc_info() |