Mercurial > public > mercurial-scm > hg
diff contrib/check-py3-compat.py @ 30094:f701fffd21d8
py3: make check-py3-compat.py load modules in standard manner
Otherwise no code transformation would be applied to the modules which are
imported only by imp.load_module().
This change means modules are imported from PYTHONPATH, not from the paths
given by command arguments. This isn't always correct, but seems acceptable.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 08 Oct 2016 17:22:07 +0200 |
parents | 68010ed1636d |
children | e8aeeb28e35e |
line wrap: on
line diff
--- a/contrib/check-py3-compat.py Sun Oct 09 08:31:39 2016 +0200 +++ b/contrib/check-py3-compat.py Sat Oct 08 17:22:07 2016 +0200 @@ -10,7 +10,7 @@ from __future__ import absolute_import, print_function import ast -import imp +import importlib import os import sys import traceback @@ -56,9 +56,9 @@ if f.startswith(('hgext/', 'mercurial/')) and not f.endswith('__init__.py'): assert f.endswith('.py') name = f.replace('/', '.')[:-3].replace('.pure.', '.') - with open(f, 'r') as fh: + if True: try: - imp.load_module(name, fh, f, ('py', 'r', imp.PY_SOURCE)) + importlib.import_module(name) except Exception as e: exc_type, exc_value, tb = sys.exc_info() # We walk the stack and ignore frames from our custom importer,