From patchwork Sat Jul 4 02:44:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 2, V2] import-checker: recurse into subtree of sys.path only if __init__.py exists From: Yuya Nishihara X-Patchwork-Id: 9891 Message-Id: To: mercurial-devel@selenic.com Date: Sat, 04 Jul 2015 11:44:34 +0900 # HG changeset patch # User Yuya Nishihara # Date 1435974843 -32400 # Sat Jul 04 10:54:03 2015 +0900 # Node ID b759bd4b1a6b581f95994481fe2dbbc7c5617487 # Parent 84518051bc3b851f736872df045d662de548b3c9 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. diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -195,6 +195,9 @@ def list_stdlib_modules(): 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 @@ def list_stdlib_modules(): 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