[PATCH 5 of 5 RFC] osutil: switch to placeholder module that imports cpy/pure selectively

Yuya Nishihara yuya at tcha.org
Sat Aug 13 06:15:27 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1470969317 -32400
#      Fri Aug 12 11:35:17 2016 +0900
# Node ID e1318b322922baf91a146d92b1ee21cc0e509c04
# Parent  3d8b3e09190aaacc3c57ae37b265838df4accb1a
osutil: switch to placeholder module that imports cpy/pure selectively

You have to do "make clean" to test this change. Otherwise, the existing
osutil.so would be loaded directly. Also, you need "make clean" to go back
to previous revisions.

Nit: should we move osutil.c to mercurial/cpy?

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
@@ -55,7 +55,9 @@ def check_compat_py3(f):
     # 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 not f.endswith('osutil.py'):
+            name = name.replace('.pure.', '.')
         with open(f, 'r') as fh:
             try:
                 imp.load_module(name, fh, '', ('py', 'r', imp.PY_SOURCE))
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -688,7 +688,8 @@ def main(argv):
     used_imports = {}
     any_errors = False
     for source_path in argv[1:]:
-        modname = dotted_name_of_path(source_path, trimpure=True)
+        trimpure = not source_path.endswith('osutil.py')
+        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):
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -27,7 +27,6 @@ modulepolicy = policy.policy
     'mercurial.bdiff',
     'mercurial.diffhelpers',
     'mercurial.mpatch',
-    'mercurial.osutil',
     'mercurial.parsers',
 ])
 
diff --git a/mercurial/osutil.py b/mercurial/osutil.py
new file mode 100644
--- /dev/null
+++ b/mercurial/osutil.py
@@ -0,0 +1,11 @@
+# osutil.py - native operating system services
+#
+# Copyright 2007 Matt Mackall and others
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+from . import policy
+globals().update(policy.uimportvars(u'osutil'))
diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -14,7 +14,7 @@ import socket
 import stat as statmod
 import sys
 
-from . import policy
+from .. import policy
 modulepolicy = policy.policy
 policynocffi = policy.policynocffi
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -577,7 +577,7 @@ extmodules = [
                                     'mercurial/pathencode.c'],
               include_dirs=common_include_dirs,
               depends=common_depends),
-    Extension('mercurial.osutil', ['mercurial/osutil.c'],
+    Extension('mercurial.cpy.osutil', ['mercurial/osutil.c'],
               include_dirs=common_include_dirs,
               extra_link_args=osutil_ldflags,
               depends=common_depends),


More information about the Mercurial-devel mailing list