comparison contrib/import-checker.py @ 27621:39845b064041

import-checker: list package directory as stdlib module Before this patch, a directory containing __init__.py wasn't counted as a module and __init__.pyc was listed as foo.bar.__init__ module.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 27 Dec 2015 23:37:14 +0900
parents 0c60843b55b5
children f3fb24e36d61
comparison
equal deleted inserted replaced
27620:0c60843b55b5 27621:39845b064041
176 for m in sys.builtin_module_names: 176 for m in sys.builtin_module_names:
177 yield m 177 yield m
178 # These modules only exist on windows, but we should always 178 # These modules only exist on windows, but we should always
179 # consider them stdlib. 179 # consider them stdlib.
180 for m in ['msvcrt', '_winreg']: 180 for m in ['msvcrt', '_winreg']:
181 yield m
182 # These get missed too
183 for m in 'ctypes', 'email', 'logging', 'multiprocessing':
184 yield m 181 yield m
185 yield 'builtins' # python3 only 182 yield 'builtins' # python3 only
186 for m in 'fcntl', 'grp', 'pwd', 'termios': # Unix only 183 for m in 'fcntl', 'grp', 'pwd', 'termios': # Unix only
187 yield m 184 yield m
188 stdlib_prefixes = set([sys.prefix, sys.exec_prefix]) 185 stdlib_prefixes = set([sys.prefix, sys.exec_prefix])
212 for i, d in reversed(list(enumerate(dirs))): 209 for i, d in reversed(list(enumerate(dirs))):
213 if (not os.path.exists(os.path.join(top, d, '__init__.py')) 210 if (not os.path.exists(os.path.join(top, d, '__init__.py'))
214 or top == libpath and d in ('hgext', 'mercurial')): 211 or top == libpath and d in ('hgext', 'mercurial')):
215 del dirs[i] 212 del dirs[i]
216 for name in files: 213 for name in files:
217 if name == '__init__.py':
218 continue
219 if not name.endswith(('.py', '.so', '.pyc', '.pyo', '.pyd')): 214 if not name.endswith(('.py', '.so', '.pyc', '.pyo', '.pyd')):
220 continue 215 continue
221 full_path = os.path.join(top, name) 216 if name.startswith('__init__.py'):
217 full_path = top
218 else:
219 full_path = os.path.join(top, name)
222 rel_path = full_path[len(libpath) + 1:] 220 rel_path = full_path[len(libpath) + 1:]
223 mod = dotted_name_of_path(rel_path) 221 mod = dotted_name_of_path(rel_path)
224 yield mod 222 yield mod
225 223
226 stdlib_modules = set(list_stdlib_modules()) 224 stdlib_modules = set(list_stdlib_modules())