MCPcopy Create free account
hub / github.com/ipython/ipython / find_mod

Function find_mod

IPython/utils/module_paths.py:41–70  ·  view source on GitHub ↗

Find module `module_name` on sys.path, and return the path to module `module_name`. - If `module_name` refers to a module directory, then return path to __init__ file. - If `module_name` is a directory without an __init__file, return None. - If module is missing or does no

(module_name)

Source from the content-addressed store, hash-verified

39#-----------------------------------------------------------------------------
40
41def find_mod(module_name):
42 """
43 Find module `module_name` on sys.path, and return the path to module `module_name`.
44
45 - If `module_name` refers to a module directory, then return path to __init__ file.
46 - If `module_name` is a directory without an __init__file, return None.
47 - If module is missing or does not have a `.py` or `.pyw` extension, return None.
48 - Note that we are not interested in running bytecode.
49 - Otherwise, return the fill path of the module.
50
51 Parameters
52 ----------
53 module_name : str
54
55 Returns
56 -------
57 module_path : str
58 Path to module `module_name`, its __init__.py, or None,
59 depending on above conditions.
60 """
61 loader = importlib.util.find_spec(module_name)
62 module_path = loader.origin
63 if module_path is None:
64 return None
65 else:
66 split_path = module_path.split(".")
67 if split_path[-1] in ["py", "pyw"]:
68 return module_path
69 else:
70 return None

Callers 1

runMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected