Patchwork [10,of,12] policy: eliminate ".pure." from module name only if marked as dual

login
register
mail settings
Submitter Yuya Nishihara
Date May 7, 2017, 1:45 a.m.
Message ID <75ce28f234b4e0d0f0ad.1494121551@mimosa>
Download mbox | patch
Permalink /patch/20508/
State Accepted
Headers show

Comments

Yuya Nishihara - May 7, 2017, 1:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471076518 -32400
#      Sat Aug 13 17:21:58 2016 +0900
# Node ID 75ce28f234b4e0d0f0ad65f5657d12a76bba0d8e
# Parent  105a90d392d5ea39260dfe90426cc812f98998fd
policy: eliminate ".pure." from module name only if marked as dual

So we can switch cext/pure modules to new layout one by one.

Patch

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
@@ -14,6 +14,16 @@  import os
 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 @@  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 f.endswith(_dualmodules):
+            name = name.replace('.pure.', '.')
         try:
             importlib.import_module(name)
         except Exception as e:
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -24,6 +24,16 @@  allowsymbolimports = (
     '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 @@  def main(argv):
     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):
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -165,7 +165,8 @@  if sys.version_info[0] >= 3:
             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