A polyfill for pathlib.Path.is_relative_to (string-based implementation). Does NOT involve filesystem operations.
(path, parent)
| 5 | |
| 6 | |
| 7 | def is_relative_to(path, parent): |
| 8 | """ |
| 9 | A polyfill for pathlib.Path.is_relative_to (string-based implementation). |
| 10 | Does NOT involve filesystem operations. |
| 11 | """ |
| 12 | path = os.path.normpath(path) |
| 13 | parent = os.path.normpath(parent) |
| 14 | |
| 15 | if path == parent: |
| 16 | return True |
| 17 | |
| 18 | if not parent.endswith(os.sep): |
| 19 | parent += os.sep |
| 20 | |
| 21 | return path.startswith(parent) |
| 22 | |
| 23 | |
| 24 | def relative_to(path, parent): |
no outgoing calls
no test coverage detected