Resolve the selected graph's project without interpreting paths via CWD.
(gp: Path)
| 554 | |
| 555 | |
| 556 | def graph_root_for(gp: Path) -> Path: |
| 557 | """Resolve the selected graph's project without interpreting paths via CWD.""" |
| 558 | try: |
| 559 | text = (gp.parent / ".graphify_root").read_text(encoding="utf-8-sig").strip() |
| 560 | if text: |
| 561 | root = Path(text) |
| 562 | if root.is_absolute(): |
| 563 | try: |
| 564 | resolved = root.resolve() |
| 565 | except RuntimeError: |
| 566 | pass # Path resolution can report a symlink loop this way. |
| 567 | else: |
| 568 | if resolved.is_dir(): |
| 569 | return resolved |
| 570 | except (OSError, UnicodeError, ValueError): |
| 571 | pass |
| 572 | |
| 573 | # CLI-written absolute markers cover shared output. Otherwise strip only |
| 574 | # an exact, traversal-free relative output suffix, never a CWD-resolved one. |
| 575 | output = Path(GRAPHIFY_OUT) |
| 576 | parts = output.parts |
| 577 | if (parts and not output.is_absolute() and ".." not in parts |
| 578 | and gp.parent.parts[-len(parts):] == parts): |
| 579 | return gp.parent.parents[len(parts) - 1] |
| 580 | return gp.parent |
| 581 | |
| 582 | |
| 583 | def default_graph_json() -> str: |
no test coverage detected