tell which names are imported when "from module import *" is done
with an extension module, short of actually importing it.
for name in self.badmodules:
if name in self.excludes:
pkg = self.modules.get(pkgname)
if pkgname in self.badmodules[name]:
# The package tried to import this module itself and
# failed. It's definitely missing.
elif subname in pkg.globalnames:
# It's a global in the package: definitely not missing.
# It could be missing, but the package did an "import *"
# from a non-Python module, so we simply can't be sure.
# It's not a global in the package, the package didn't
# do funny star imports, it's very likely to be missing.
# The symbol could be inserted into the package from the
# outside, but since that's not good style we simply list
def replace_paths_in_code(self, co):
new_filename = original_filename = os.path.normpath(co.co_filename)
for f, r in self.replace_paths:
if original_filename.startswith(f):
new_filename = r + original_filename[len(f):]
if self.debug and original_filename not in self.processed_paths:
if new_filename != original_filename:
self.msgout(2, "co_filename %r changed to %r" \
% (original_filename,new_filename,))
self.msgout(2, "co_filename %r remains unchanged" \
self.processed_paths.append(original_filename)
consts = list(co.co_consts)
for i in range(len(consts)):
if isinstance(consts[i], type(co)):
consts[i] = self.replace_paths_in_code(consts[i])
return types.CodeType(co.co_argcount, co.co_kwonlyargcount,
co.co_nlocals, co.co_stacksize, co.co_flags,
co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name,
co.co_firstlineno, co.co_lnotab, co.co_freevars,
opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:")
except getopt.error as msg:
addpath = addpath + a.split(os.pathsep)
# Provide default arguments
# Set the path based on sys.path and the script directory
path[0] = os.path.dirname(script)
# Create the module finder and turn its crank
mf = ModuleFinder(path, debug, exclude)
mf.import_hook(arg[:-2], None, ["*"])
return mf # for -i debugging
if __name__ == '__main__':
except KeyboardInterrupt: