MCPcopy Index your code
hub / github.com/ipython/ipython / find_mod

Function find_mod

IPython/utils/module_paths.py:43–78  ·  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 not

(module_name: str)

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.90

Calls 1

find_specMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…