MCPcopy
hub / github.com/psf/black / best_effort_relative_path

Function best_effort_relative_path

src/black/files.py:279–289  ·  view source on GitHub ↗
(path: Path, root: Path)

Source from the content-addressed store, hash-verified

277
278
279def best_effort_relative_path(path: Path, root: Path) -> Path:
280 # Precondition: resolves_outside_root_or_cannot_stat(path, root) is False
281 try:
282 return path.absolute().relative_to(root)
283 except ValueError:
284 pass
285 root_parent = next((p for p in path.parents if _cached_resolve(p) == root), None)
286 if root_parent is not None:
287 return path.relative_to(root_parent)
288 # something adversarial, fallback to path guaranteed by precondition
289 return _cached_resolve(path).relative_to(root)
290
291
292def _path_is_ignored(

Callers 1

get_sourcesFunction · 0.90

Calls 1

_cached_resolveFunction · 0.85

Tested by

no test coverage detected