Given two paths, return if path is a sub-path of dir. Moral equivalent of: Path(dir) in Path(path).parents Similar to the pathlib version: - Treats paths case-sensitively - Does not fully handle unnormalised paths (e.g. paths with "..") - Does not handle a mix of absolute and r
(path: str, dir: str)
| 420 | |
| 421 | |
| 422 | def is_sub_path_normabs(path: str, dir: str) -> bool: |
| 423 | """Given two paths, return if path is a sub-path of dir. |
| 424 | |
| 425 | Moral equivalent of: Path(dir) in Path(path).parents |
| 426 | |
| 427 | Similar to the pathlib version: |
| 428 | - Treats paths case-sensitively |
| 429 | - Does not fully handle unnormalised paths (e.g. paths with "..") |
| 430 | - Does not handle a mix of absolute and relative paths |
| 431 | Unlike the pathlib version: |
| 432 | - Fast |
| 433 | - On Windows, assumes input has been slash normalised |
| 434 | - Handles even fewer unnormalised paths (e.g. paths with "." and "//") |
| 435 | |
| 436 | As a result, callers should ensure that inputs have had os.path.abspath called on them |
| 437 | (note that os.path.abspath will normalise) |
| 438 | """ |
| 439 | if not dir.endswith(os.sep): |
| 440 | dir += os.sep |
| 441 | return path.startswith(dir) |
| 442 | |
| 443 | |
| 444 | if sys.platform == "linux" or sys.platform == "darwin": |
no test coverage detected
searching dependent graphs…