[PATCH 2 of 3] import-checker: treat "from mercurial import XXXX" style correctly

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Oct 16 12:34:10 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 7ab6646d00d4aa88820d87a1f728d641f9279caf
# Parent  738137a3404922e887894da69bca6382bc672e44
import-checker: treat "from mercurial import XXXX" style correctly

Before this patch, "import-checker.py" assumes that the name of
Mercurial module recognized by "imported_modules" doesn't have package
part: for example, "util".

This is reason why "import-checker.py" always builds fully qualified
module name up relatively, if the given module doesn't belong to
standard Python library.

But in fact, modules imported in "from mercurial import XXXX" style
already have fully qualified name: for example, "mercurial.util"
module imported by "mercurial.parsers" is treated as
"mercurial.mercurial.util" because of building module name up
relatively.

This prevents "import-checker.py" from correctly checking about cyclic
dependency in them.

This patch avoids building module name up relatively, also if module
name starts with "mercurial.", to treat modules imported in "from
mercurial import XXXX" style correctly.

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -169,7 +169,7 @@
         ignore = []
     path = path + [mod]
     for i in sorted(imports.get(mod, [])):
-        if i not in stdlib_modules:
+        if i not in stdlib_modules and not i.startswith('mercurial.'):
             i = mod.rsplit('.', 1)[0] + '.' + i
         if i in path:
             firstspot = path.index(i)


More information about the Mercurial-devel mailing list