[PATCH 3 of 3] import-checker: check modules for pure Python build correctly

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Oct 16 12:34:11 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1413479225 -32400
#      Fri Oct 17 02:07:05 2014 +0900
# Node ID 6b4ed11ecbfdcff34d47b93f5c7c20193788da79
# Parent  7ab6646d00d4aa88820d87a1f728d641f9279caf
import-checker: check modules for pure Python build correctly

Before this patch, "import-checker.py" just replaces "/" in specified
filenames by ".". This makes modules for pure Python build belong to
"mercurial.pure" package, and prevents "import-checker.py" from
correctly checking about cyclic dependency in them.

This patch discards "pure" component from fully qualified name of such
modules.

To avoid discarding "pure" from the module name of standard libraries
unexpectedly, this patch allows "dotted_name_of_path" to discard
"pure" only from Mercurial specific modules, which are specified via
command line arguments.

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -8,11 +8,13 @@
 import BaseHTTPServer
 import zlib
 
-def dotted_name_of_path(path):
+def dotted_name_of_path(path, trimpure=False):
     """Given a relative path to a source file, return its dotted module name.
 
     >>> dotted_name_of_path('mercurial/error.py')
     'mercurial.error'
+    >>> dotted_name_of_path('mercurial/pure/parsers.py', trimpure=True)
+    'mercurial.parsers'
     >>> dotted_name_of_path('zlibmodule.so')
     'zlib'
     """
@@ -20,6 +22,8 @@
     parts[-1] = parts[-1].split('.', 1)[0] # remove .py and .so and .ARCH.so
     if parts[-1].endswith('module'):
         parts[-1] = parts[-1][:-6]
+    if trimpure:
+        return '.'.join(p for p in parts if p != 'pure')
     return '.'.join(parts)
 
 
@@ -220,7 +224,7 @@
     any_errors = False
     for source_path in argv[1:]:
         f = open(source_path)
-        modname = dotted_name_of_path(source_path)
+        modname = dotted_name_of_path(source_path, trimpure=True)
         src = f.read()
         used_imports[modname] = sorted(
             imported_modules(src, ignore_nested=True))


More information about the Mercurial-devel mailing list