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)
| 56 | |
| 57 | |
| 58 | def 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 | |
| 75 | def is_lib_path(path: pathlib.Path) -> bool: |