MCPcopy Index your code
hub / github.com/RustPython/RustPython / resolve_module_path

Function resolve_module_path

scripts/update_lib/file_utils.py:145–170  ·  view source on GitHub ↗

Resolve module path, trying file or directory. Args: name: Module name (e.g., "dataclasses", "json") prefix: CPython directory prefix prefer: "file" to try .py first, "dir" to try directory first

(
    name: str, prefix: str = "cpython", prefer: str = "file"
)

Source from the content-addressed store, hash-verified

143
144
145def resolve_module_path(
146 name: str, prefix: str = "cpython", prefer: str = "file"
147) -> pathlib.Path:
148 """
149 Resolve module path, trying file or directory.
150
151 Args:
152 name: Module name (e.g., "dataclasses", "json")
153 prefix: CPython directory prefix
154 prefer: "file" to try .py first, "dir" to try directory first
155 """
156 file_path = pathlib.Path(f"{prefix}/Lib/{name}.py")
157 dir_path = pathlib.Path(f"{prefix}/Lib/{name}")
158
159 if prefer == "file":
160 if file_path.exists():
161 return file_path
162 if dir_path.exists():
163 return dir_path
164 return file_path
165 else:
166 if dir_path.exists():
167 return dir_path
168 if file_path.exists():
169 return file_path
170 return dir_path
171
172
173def construct_lib_path(prefix: str, *parts: str) -> pathlib.Path:

Callers 5

_expand_shortcutFunction · 0.90
get_lib_pathsFunction · 0.90
get_test_pathsFunction · 0.90
get_soft_depsFunction · 0.90
resolve_test_pathFunction · 0.85

Calls 1

existsMethod · 0.95

Tested by

no test coverage detected