6
def module_has_submodule(package, module_name):
7
"""See if 'module' is in 'package'."""
8
name = ".".join([package.__name__, module_name])
9
if name in sys.modules:
11
for finder in sys.meta_path:
12
if finder.find_module(name):
14
for entry in package.__path__: # No __path__, then not a package.
16
# Try the cached finder.
17
finder = sys.path_importer_cache[entry]
19
# Implicit import machinery should be used.
21
file_, _, _ = imp.find_module(module_name, [entry])
27
# Else see if the finder knows of a loader.
28
elif finder.find_module(name):
33
# No cached finder, so try and make one.
34
for hook in sys.path_hooks:
37
# XXX Could cache in sys.path_importer_cache
38
if finder.find_module(name):
41
# Once a finder is found, stop the search.
44
# Continue the search for a finder.
48
# Try the implicit import machinery if searching a directory.
49
if os.path.isdir(entry):
51
file_, _, _ = imp.find_module(module_name, [entry])
57
# XXX Could insert None or NullImporter
59
# Exhausted the search, so the module cannot be found.