Mercurial > hg
comparison contrib/import-checker.py @ 25733:f99c066f5f9a
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 04 Jul 2015 10:54:03 +0900 |
parents | cd1daab5d036 |
children | 9086d0c1def3 |
comparison
equal
deleted
inserted
replaced
25732:b94df10cc3b5 | 25733:f99c066f5f9a |
---|---|
193 if not any(libpath.startswith(p) for p in stdlib_prefixes): # no-py24 | 193 if not any(libpath.startswith(p) for p in stdlib_prefixes): # no-py24 |
194 continue | 194 continue |
195 if 'site-packages' in libpath: | 195 if 'site-packages' in libpath: |
196 continue | 196 continue |
197 for top, dirs, files in os.walk(libpath): | 197 for top, dirs, files in os.walk(libpath): |
198 for i, d in reversed(list(enumerate(dirs))): | |
199 if not os.path.exists(os.path.join(top, d, '__init__.py')): | |
200 del dirs[i] | |
198 for name in files: | 201 for name in files: |
199 if name == '__init__.py': | 202 if name == '__init__.py': |
200 continue | 203 continue |
201 if not (name.endswith('.py') or name.endswith('.so') | 204 if not (name.endswith('.py') or name.endswith('.so') |
202 or name.endswith('.pyd')): | 205 or name.endswith('.pyd')): |
203 continue | 206 continue |
204 full_path = os.path.join(top, name) | 207 full_path = os.path.join(top, name) |
205 if 'site-packages' in full_path: | |
206 continue | |
207 rel_path = full_path[len(libpath) + 1:] | 208 rel_path = full_path[len(libpath) + 1:] |
208 mod = dotted_name_of_path(rel_path) | 209 mod = dotted_name_of_path(rel_path) |
209 yield mod | 210 yield mod |
210 | 211 |
211 stdlib_modules = set(list_stdlib_modules()) | 212 stdlib_modules = set(list_stdlib_modules()) |