Mercurial > hg-stable
changeset 32252: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 | c48583859e04 |
children | bc2e23354cc0 |
files | contrib/check-py3-compat.py contrib/import-checker.py mercurial/__init__.py |
diffstat | 3 files changed, 27 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-py3-compat.py Fri Aug 12 11:06:14 2016 +0900 +++ b/contrib/check-py3-compat.py Sat Aug 13 17:21:58 2016 +0900 @@ -14,6 +14,16 @@ import sys import traceback +# Modules that have both Python and C implementations. +_dualmodules = ( + 'base85.py', + 'bdiff.py', + 'diffhelpers.py', + 'mpatch.py', + 'osutil.py', + 'parsers.py', +) + def check_compat_py2(f): """Check Python 3 compatibility for a file with Python 2""" with open(f, 'rb') as fh: @@ -55,7 +65,9 @@ # out module paths for things not in a package can be confusing. if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): assert f.endswith('.py') - name = f.replace('/', '.')[:-3].replace('.pure.', '.') + name = f.replace('/', '.')[:-3] + if f.endswith(_dualmodules): + name = name.replace('.pure.', '.') try: importlib.import_module(name) except Exception as e:
--- a/contrib/import-checker.py Fri Aug 12 11:06:14 2016 +0900 +++ b/contrib/import-checker.py Sat Aug 13 17:21:58 2016 +0900 @@ -24,6 +24,16 @@ 'mercurial.node', ) +# Modules that have both Python and C implementations. +_dualmodules = ( + 'base85.py', + 'bdiff.py', + 'diffhelpers.py', + 'mpatch.py', + 'osutil.py', + 'parsers.py', +) + # Modules that must be aliased because they are commonly confused with # common variables and can create aliasing and readability issues. requirealias = { @@ -691,7 +701,8 @@ used_imports = {} any_errors = False for source_path in argv[1:]: - modname = dotted_name_of_path(source_path, trimpure=True) + trimpure = source_path.endswith(_dualmodules) + modname = dotted_name_of_path(source_path, trimpure=trimpure) localmods[modname] = source_path for localmodname, source_path in sorted(localmods.items()): for src, modname, name, line in sources(source_path, localmodname):
--- a/mercurial/__init__.py Fri Aug 12 11:06:14 2016 +0900 +++ b/mercurial/__init__.py Sat Aug 13 17:21:58 2016 +0900 @@ -165,7 +165,8 @@ if not spec: return None - if fullname.startswith('mercurial.pure.'): + if (fullname.startswith('mercurial.pure.') + and fullname.replace('.pure.', '.') in _dualmodules): spec.name = spec.name.replace('.pure.', '.') # TODO need to support loaders from alternate specs, like zip