Rewrite ``path`` through ``mappings``. First prefix match wins. ``reverse=False``: rewrites source-prefix → target-prefix (forward). ``reverse=True``: rewrites target-prefix → source-prefix (reverse). Relative paths and absolute paths with no matching prefix are returned unchanged
(mappings: list[PathMapping], path: str | Path, reverse: bool = False)
| 198 | |
| 199 | |
| 200 | def _apply_mapping(mappings: list[PathMapping], path: str | Path, reverse: bool = False) -> str: |
| 201 | """Rewrite ``path`` through ``mappings``. First prefix match wins. |
| 202 | |
| 203 | ``reverse=False``: rewrites source-prefix → target-prefix (forward). |
| 204 | ``reverse=True``: rewrites target-prefix → source-prefix (reverse). |
| 205 | |
| 206 | Relative paths and absolute paths with no matching prefix are returned |
| 207 | unchanged (as ``str``). |
| 208 | """ |
| 209 | p = Path(path) |
| 210 | if not p.is_absolute(): |
| 211 | return str(path) |
| 212 | resolved = p.resolve() |
| 213 | for m in mappings: |
| 214 | src, dst = (m.target, m.source) if reverse else (m.source, m.target) |
| 215 | if resolved == src or resolved.is_relative_to(src): |
| 216 | rel = resolved.relative_to(src) |
| 217 | return str(dst / rel) if str(rel) != "." else str(dst) |
| 218 | return str(path) |
| 219 | |
| 220 | |
| 221 | _db_path_mapping: list[PathMapping] | None = None |
no outgoing calls
no test coverage detected