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

Function _expand_shortcut

scripts/update_lib/cmd_quick.py:279–322  ·  view source on GitHub ↗

Expand simple name to cpython/Lib path if it exists. Examples: dataclasses -> cpython/Lib/dataclasses.py (if exists) json -> cpython/Lib/json/ (if exists) test_types -> cpython/Lib/test/test_types.py (if exists) regrtest -> cpython/Lib/test/libregrtest (from DEPE

(path: pathlib.Path)

Source from the content-addressed store, hash-verified

277
278
279def _expand_shortcut(path: pathlib.Path) -> pathlib.Path:
280 """Expand simple name to cpython/Lib path if it exists.
281
282 Examples:
283 dataclasses -> cpython/Lib/dataclasses.py (if exists)
284 json -> cpython/Lib/json/ (if exists)
285 test_types -> cpython/Lib/test/test_types.py (if exists)
286 regrtest -> cpython/Lib/test/libregrtest (from DEPENDENCIES)
287 """
288 # Only expand if it's a simple name (no path separators) and doesn't exist
289 if "/" in str(path) or path.exists():
290 return path
291
292 name = str(path)
293
294 # Check DEPENDENCIES table for path overrides (e.g., regrtest)
295 from update_lib.deps import DEPENDENCIES
296
297 if name in DEPENDENCIES and "lib" in DEPENDENCIES[name]:
298 lib_paths = DEPENDENCIES[name]["lib"]
299 if lib_paths:
300 override_path = construct_lib_path("cpython", lib_paths[0])
301 if override_path.exists():
302 return override_path
303
304 # Test shortcut: test_foo -> cpython/Lib/test/test_foo
305 if name.startswith("test_"):
306 resolved = resolve_module_path(f"test/{name}", "cpython", prefer="dir")
307 if resolved.exists():
308 return resolved
309
310 # Library shortcut: foo -> cpython/Lib/foo
311 resolved = resolve_module_path(name, "cpython", prefer="file")
312 if resolved.exists():
313 return resolved
314
315 # Extension module shortcut: winreg -> cpython/Lib/test/test_winreg
316 # For C/Rust extension modules that have no Python source but have tests
317 resolved = resolve_module_path(f"test/test_{name}", "cpython", prefer="dir")
318 if resolved.exists():
319 return resolved
320
321 # Return original (will likely fail later with a clear error)
322 return path
323
324
325def main(argv: list[str] | None = None) -> int:

Calls 5

construct_lib_pathFunction · 0.90
resolve_module_pathFunction · 0.90
strFunction · 0.85
existsMethod · 0.45
startswithMethod · 0.45