Re: [PATCH 2 of 3] py3: make check-py3-compat.py load modules in standard manner

2016-10-09 Thread Kevin Bullock
> On Oct 9, 2016, at 09:17, Yuya Nishihara  wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara 
> # Date 1475940127 -7200
> #  Sat Oct 08 17:22:07 2016 +0200
> # Node ID fbd4b7cbb2930550f164f1fef3c3a8a64011a4c8
> # Parent  83c488687f45a76c18a91a4f80ed1c921a00a30e
> 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.

This patch seems to have broken the py2.6 build, although it was masked by 
breakage from the dict comprehension. Now that that's fixed as of 
, the 
buildbot shows the error:



(ignoring the test-clone.t failure which Augie has a patch in-flight to fix).

It looks like importlib wasn't added until 2.7: 


Yuya, can you take a look?

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 2 of 3] py3: make check-py3-compat.py load modules in standard manner

2016-10-09 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# Date 1475940127 -7200
#  Sat Oct 08 17:22:07 2016 +0200
# Node ID fbd4b7cbb2930550f164f1fef3c3a8a64011a4c8
# Parent  83c488687f45a76c18a91a4f80ed1c921a00a30e
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.

diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -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 @@ def check_compat_py3(f):
 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,
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -16,41 +16,27 @@
   $ hg files 'set:(**.py) - grep(pygments)' | sed 's|\\|/|g' \
   > | xargs $PYTHON3 contrib/check-py3-compat.py \
   > | sed 's/[0-9][0-9]*)$/*)/'
-  hgext/convert/bzr.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at bzr.py:*)
-  hgext/convert/convcmd.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at 
convcmd.py:*)
-  hgext/convert/cvs.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at cvs.py:*)
-  hgext/convert/darcs.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at darcs.py:*)
-  hgext/convert/filemap.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at 
filemap.py:*)
-  hgext/convert/git.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at git.py:*)
-  hgext/convert/gnuarch.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at 
gnuarch.py:*)
-  hgext/convert/hg.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at hg.py:*)
-  hgext/convert/monotone.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at 
monotone.py:*)
-  hgext/convert/p4.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at p4.py:*)
-  hgext/convert/subversion.py: error importing:  Parent module 
'hgext.convert' not loaded, cannot perform relative import (error at 
subversion.py:*)
-  hgext/convert/transport.py: error importing:  No module named 
'svn.client' (error at transport.py:*)
-  hgext/fsmonitor/watchmanclient.py: error importing:  Parent 
module 'hgext.fsmonitor' not loaded, cannot perform relative import (error at 
watchmanclient.py:*)
-  hgext/journal.py: error importing:  Parent module 'hgext' not 
loaded, cannot perform relative import (error at journal.py:*)
-  hgext/largefiles/basestore.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
basestore.py:*)
-  hgext/largefiles/lfcommands.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
lfcommands.py:*)
-  hgext/largefiles/localstore.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
localstore.py:*)
-  hgext/largefiles/overrides.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
overrides.py:*)
-  hgext/largefiles/proto.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
proto.py:*)
-  hgext/largefiles/remotestore.py: error importing:  Parent 
module 'hgext.largefiles' not loaded, cannot perform relative import (error at 
remotestore.py:*)
-  hgext/largefiles/reposetup.py: error importing:  Parent module 
'hgext.largefiles' not loaded, cannot perform relative import (error at 
reposetup.py:*)
-  hgext/largefiles/storefactory.py: error importing:  Parent 
module 'hgext.largefiles' not loaded, cannot perform relative import (error at 
storefactory.py:*)
-  hgext/largefiles/uisetup.py: error importing