import-checker: don't treat modules as relative one if not found
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 18 May 2015 02:52:58 +0900
changeset 25175 10e6c4b7121b
parent 25174 86298718b01c
child 25176 665a9deae8dd
import-checker: don't treat modules as relative one if not found The previous patch ensures all module names are recorded in `imports` as absolute names, so we no longer need to treat modules as ones imported relatively from the target source if they appear to not be from the stdlib.
contrib/import-checker.py
--- a/contrib/import-checker.py	Mon May 18 02:52:55 2015 +0900
+++ b/contrib/import-checker.py	Mon May 18 02:52:58 2015 +0900
@@ -293,8 +293,6 @@
     while visit:
         path = visit.pop(0)
         for i in sorted(imports.get(path[-1], [])):
-            if i not in stdlib_modules and not i.startswith('mercurial.'):
-                i = mod.rsplit('.', 1)[0] + '.' + i
             if len(path) < shortest.get(i, 1000):
                 shortest[i] = len(path)
                 if i in path:
@@ -316,10 +314,12 @@
 def find_cycles(imports):
     """Find cycles in an already-loaded import graph.
 
-    >>> imports = {'top.foo': ['bar', 'os.path', 'qux'],
-    ...            'top.bar': ['baz', 'sys'],
-    ...            'top.baz': ['foo'],
-    ...            'top.qux': ['foo']}
+    All module names recorded in `imports` should be absolute one.
+
+    >>> imports = {'top.foo': ['top.bar', 'os.path', 'top.qux'],
+    ...            'top.bar': ['top.baz', 'sys'],
+    ...            'top.baz': ['top.foo'],
+    ...            'top.qux': ['top.foo']}
     >>> print '\\n'.join(sorted(find_cycles(imports)))
     top.bar -> top.baz -> top.foo -> top.bar
     top.foo -> top.qux -> top.foo