MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _resolve_source_path

Function _resolve_source_path

graphify/reflect.py:668–714  ·  view source on GitHub ↗

Locate a node's ``source_file`` on disk, returning an existing file or None. ``source_file`` is stored relative to the PROJECT root, but graph.json may live in `` /graphify-out/`` (so its own dir is not the root) or directly at the root (``extract --out .``). Resolve the root in th

(src: str, graph_path: Path)

Source from the content-addressed store, hash-verified

666
667
668def _resolve_source_path(src: str, graph_path: Path) -> Path | None:
669 """Locate a node's ``source_file`` on disk, returning an existing file or None.
670
671 ``source_file`` is stored relative to the PROJECT root, but graph.json may
672 live in ``<root>/graphify-out/`` (so its own dir is not the root) or directly
673 at the root (``extract --out .``). Resolve the root in the most-likely order
674 and return the first candidate where the file actually exists, so a defeated
675 heuristic or a stale marker can never strand the file (every node would then
676 look "changed"). The same search runs at write and read time, so the writer
677 and reader resolve to the same file.
678
679 Order: the committed ``.graphify_root`` marker (#686/#1423 — authoritative for
680 an absolute/elsewhere ``GRAPHIFY_OUT`` override); then the layout-appropriate
681 root *first* — graph.json's parent's parent for the ``graphify-out`` layout,
682 or graph.json&#x27;s own dir for a flat layout — which avoids matching a same-named
683 file one directory up; then the other of the two; then the cwd.
684 """
685 if not src:
686 return None
687 p = Path(src)
688 if p.is_absolute():
689 return p if p.is_file() else None
690 gp = Path(graph_path)
691 out_dir = gp.parent
692 candidates: list[Path] = []
693 try:
694 recorded = (out_dir / ".graphify_root").read_text(encoding="utf-8-sig").strip()
695 if recorded:
696 candidates.append(Path(recorded))
697 except (OSError, ValueError):
698 pass # unreadable/non-UTF-8 marker -> fall through (best-effort)
699 # Layout-appropriate root first (precision), then the other (robustness).
700 if out_dir.name == GRAPHIFY_OUT_NAME:
701 candidates += [out_dir.parent, out_dir]
702 else:
703 candidates += [out_dir, out_dir.parent]
704 candidates.append(Path("."))
705 seen: set[str] = set()
706 for base in candidates:
707 key = str(base)
708 if key in seen:
709 continue
710 seen.add(key)
711 cand = base / p
712 if cand.is_file():
713 return cand
714 return None
715
716
717def _content_hash(path: Path) -> str:

Callers 2

_code_fingerprintFunction · 0.85
_is_staleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected