Mercurial > hg
comparison contrib/import-checker.py @ 20197:761f2929a6ad
import-checker: refactor sys.path prefix check (issue4129)
This patch refactors the logic in contrib/import-checker.py responsible for
checking the beginnings of the paths in sys.path. In particular, it adds a
variable that defines the set of allowed prefixes.
The primary purpose of this change is to make it easier to add more allowed
prefixes. This will be useful in resolving issue4129, which involves making
the function list_stdlib_modules() work when run from a virtualenv.
author | Chris Jerdonek <chris.jerdonek@gmail.com> |
---|---|
date | Sun, 22 Dec 2013 14:10:26 -0800 |
parents | c65a6937b828 |
children | f5393a9dc4e5 |
comparison
equal
deleted
inserted
replaced
20196:59198508b0bd | 20197:761f2929a6ad |
---|---|
46 yield m | 46 yield m |
47 # These get missed too | 47 # These get missed too |
48 for m in 'ctypes', 'email': | 48 for m in 'ctypes', 'email': |
49 yield m | 49 yield m |
50 yield 'builtins' # python3 only | 50 yield 'builtins' # python3 only |
51 stdlib_prefixes = set([sys.prefix, sys.exec_prefix]) | |
51 for libpath in sys.path: | 52 for libpath in sys.path: |
52 # We want to walk everything in sys.path that starts with | 53 # We want to walk everything in sys.path that starts with something |
53 # either sys.prefix or sys.exec_prefix. | 54 # in stdlib_prefixes. |
54 if not (libpath.startswith(sys.prefix) | 55 for prefix in stdlib_prefixes: |
55 or libpath.startswith(sys.exec_prefix)): | 56 if libpath.startswith(prefix): |
57 break | |
58 else: | |
56 continue | 59 continue |
57 if 'site-packages' in libpath: | 60 if 'site-packages' in libpath: |
58 continue | 61 continue |
59 for top, dirs, files in os.walk(libpath): | 62 for top, dirs, files in os.walk(libpath): |
60 for name in files: | 63 for name in files: |