MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / to_relative_path

Function to_relative_path

src/tool_system/utils/path_utils.py:9–17  ·  view source on GitHub ↗

Convert an absolute path to a relative one if shorter.

(absolute: str, cwd: str | Path)

Source from the content-addressed store, hash-verified

7
8
9def to_relative_path(absolute: str, cwd: str | Path) -> str:
10 """Convert an absolute path to a relative one if shorter."""
11 try:
12 rel = os.path.relpath(absolute, str(cwd))
13 except ValueError:
14 return absolute
15 if len(rel) < len(absolute):
16 return rel
17 return absolute
18
19
20def suggest_path_under_cwd(path: str, cwd: str | Path) -> str | None:

Callers 4

_grep_fallback_pythonFunction · 0.85
_glob_callFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected