changeset 22975:461342e1c8aa

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 17 Oct 2014 02:07:05 +0900
parents 6bd43614d387
children 886711722db6
files contrib/import-checker.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/import-checker.py	Fri Oct 17 02:07:05 2014 +0900
+++ b/contrib/import-checker.py	Fri Oct 17 02:07:05 2014 +0900
@@ -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))