import-checker: recurse into subtree of sys.path only if __init__.py exists
authorYuya Nishihara <yuya@tcha.org>
Sat, 04 Jul 2015 10:54:03 +0900
changeset 25733 f99c066f5f9a
parent 25732 b94df10cc3b5
child 25734 9086d0c1def3
import-checker: recurse into subtree of sys.path only if __init__.py exists We can't assume that the site-packages is the only directory that has Python files but is not handled as a package. For example, we have dist-packages directory on Debian.
contrib/import-checker.py
--- a/contrib/import-checker.py	Fri Jul 03 06:56:03 2015 +0900
+++ b/contrib/import-checker.py	Sat Jul 04 10:54:03 2015 +0900
@@ -195,6 +195,9 @@
         if 'site-packages' in libpath:
             continue
         for top, dirs, files in os.walk(libpath):
+            for i, d in reversed(list(enumerate(dirs))):
+                if not os.path.exists(os.path.join(top, d, '__init__.py')):
+                    del dirs[i]
             for name in files:
                 if name == '__init__.py':
                     continue
@@ -202,8 +205,6 @@
                         or name.endswith('.pyd')):
                     continue
                 full_path = os.path.join(top, name)
-                if 'site-packages' in full_path:
-                    continue
                 rel_path = full_path[len(libpath) + 1:]
                 mod = dotted_name_of_path(rel_path)
                 yield mod