@@ -102,10 +102,34 @@ def write_sway_yaml(dlm_path: Path, out: Path) -> None: |
| 102 | 102 | f"{dlm_path}: no trained adapter found at ~/.dlm/store/{handle.dlm_id}/adapter; " |
| 103 | 103 | "train the document with `dlm train` before generating a sway suite." |
| 104 | 104 | ) |
| 105 | | - spec = build_spec_dict(handle, dlm_source=str(dlm_path.resolve())) |
| 105 | + spec = build_spec_dict(handle, dlm_source=_portable_dlm_source(dlm_path)) |
| 106 | 106 | out.write_text(_render_annotated_yaml(spec, handle, dlm_path), encoding="utf-8") |
| 107 | 107 | |
| 108 | 108 | |
| 109 | +def _portable_dlm_source(dlm_path: Path) -> str: |
| 110 | + """Return a ``dlm_source`` string that survives cross-machine checkout. |
| 111 | + |
| 112 | + F09 (Audit 03) — the pre-fix code unconditionally wrote an |
| 113 | + absolute path (``/Users/mfwolffe/.../fortran.dlm``) which breaks |
| 114 | + when the autogen'd ``sway.yaml`` is committed to a repo and |
| 115 | + re-run from a different working tree (CI agents, another dev's |
| 116 | + checkout). The cwd-relative form is round-trippable across |
| 117 | + machines; only fall back to absolute when the ``.dlm`` lives |
| 118 | + outside the cwd (e.g. a global user dir) where relativization |
| 119 | + doesn't resolve on a fresh checkout. |
| 120 | + """ |
| 121 | + abs_path = dlm_path.resolve() |
| 122 | + cwd = Path.cwd().resolve() |
| 123 | + try: |
| 124 | + # ``is_relative_to`` lands in 3.9+; this path is guaranteed |
| 125 | + # to exist because sway requires ``>=3.11``. |
| 126 | + if abs_path.is_relative_to(cwd): |
| 127 | + return str(abs_path.relative_to(cwd)) |
| 128 | + except ValueError: |
| 129 | + pass |
| 130 | + return str(abs_path) |
| 131 | + |
| 132 | + |
| 109 | 133 | def _render_annotated_yaml(spec: dict[str, Any], handle: DlmHandle, dlm_path: Path) -> str: |
| 110 | 134 | """Render the spec as YAML with a provenance header + per-probe intent lines (D5). |
| 111 | 135 | |