self.msgout(3, "find_module -> Excluded", fullname)
if name in sys.builtin_module_names:
return (None, None, ("", "", _C_BUILTIN))
return _find_module(name, path)
"""Print a report to stdout, listing the found modules with their
paths, as well as modules that are missing, or seem to be missing.
print(" %-25s %s" % ("Name", "File"))
print(" %-25s %s" % ("----", "----"))
keys = sorted(self.modules.keys())
print("%-25s" % key, m.__file__ or "")
missing, maybe = self.any_missing_maybe()
print("Missing modules:")
mods = sorted(self.badmodules[name].keys())
print("?", name, "imported from", ', '.join(mods))
# Print modules that may be missing, but then again, maybe not...
print("Submodules that appear to be missing, but could also be", end=' ')
print("global names in the parent package:")
mods = sorted(self.badmodules[name].keys())
print("?", name, "imported from", ', '.join(mods))
"""Return a list of modules that appear to be missing. Use
any_missing_maybe() if you want to know which modules are
certain to be missing, and which *may* be missing.
missing, maybe = self.any_missing_maybe()
def any_missing_maybe(self):
"""Return two lists, one with modules that are certainly missing
and one with modules that *may* be missing. The latter names could
either be submodules *or* just global names in the package.
The reason it can't always be determined is that it's impossible to
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 co.replace(co_consts=tuple(consts), co_filename=new_filename)
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: