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

Function parse_lib_path

scripts/update_lib/file_utils.py:58–72  ·  view source on GitHub ↗

Extract the Lib/... portion from a path containing /Lib/. Example: parse_lib_path("cpython/Lib/test/foo.py") -> Path("Lib/test/foo.py")

(path: pathlib.Path | str)

Source from the content-addressed store, hash-verified

56
57
58def parse_lib_path(path: pathlib.Path | str) -> pathlib.Path:
59 """
60 Extract the Lib/... portion from a path containing /Lib/.
61
62 Example:
63 parse_lib_path("cpython/Lib/test/foo.py") -> Path("Lib/test/foo.py")
64 """
65 path_str = str(path).replace("\\", "/")
66 lib_marker = "/Lib/"
67
68 if lib_marker not in path_str:
69 raise ValueError(f"Path must contain '/Lib/' or '\\Lib\\' (got: {path})")
70
71 idx = path_str.index(lib_marker)
72 return pathlib.Path(path_str[idx + 1 :])
73
74
75def is_lib_path(path: pathlib.Path) -> bool:

Callers 11

quickFunction · 0.90
mainFunction · 0.90
copy_libFunction · 0.90
patch_fileFunction · 0.90
patch_directoryFunction · 0.90
test_parse_directoryMethod · 0.90
lib_to_test_pathFunction · 0.85

Calls 3

strFunction · 0.85
replaceMethod · 0.45
indexMethod · 0.45

Tested by 5

test_parse_directoryMethod · 0.72