MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / _apply_mapping

Function _apply_mapping

src/cocoindex_code/settings.py:200–218  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

198
199
200def _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

Callers 2

format_path_for_displayFunction · 0.85
normalize_input_pathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected