feat(compile_formal_docs): mirror docs/ subtree so formal docs can embed assets#14
Merged
Merged
Conversation
…bed assets
adafmt#56 needs the SDS to embed architecture diagrams via
image("../diagrams/foo.svg"). The previous build copied .typ sources
flat into the temp directory, so any ../<dir>/ asset reference pointed
outside the Typst project root — typst rejected it with
"cannot read file outside of project root".
Fix: mirror the project's whole docs/ subtree into the temp build
(generated *.pdf excluded — build outputs, not inputs), overlay the
shared templates next to the mirrored .typ sources, and compile each
document with `--root` at the docs mirror. Cross-directory asset
references now resolve while #import "core.typ" (a same-directory
import) still works.
This is a general docs-asset solution: any asset under docs/ is
reachable, not just docs/diagrams/. No project-specific special case.
Tests: tests/test_compile_formal_docs.py — find_project_root, dry-run,
plain-doc compile (regression guard), embedded-diagram compile (the
adafmt#56 regression — fails pre-fix with the outside-root error),
and stale-PDF-in-docs tolerance. typst-dependent tests skip cleanly
when typst is absent. Full suite 139 passing.
Refs: adafmt#56
…chanics GPT PR #14 review suggested a non-typst test so the docs-mirror mechanics stay covered on runners without typst installed. Monkeypatches subprocess.run and asserts the compile command is rooted at the docs mirror, the .typ source is mirrored under <root>/formal/, and the sibling diagram asset is mirrored under <root>/diagrams/ at invocation time. Refs: adafmt#56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prerequisite for adafmt#56. The SDS needs to embed architecture diagrams via
image("../diagrams/foo.svg"), butcompile_formal_docs.pycopied.typsources flat into the temp build directory — so any../<dir>/asset reference pointed outside the Typst project root and typst rejected it:Fix
Mirror the project's whole
docs/subtree into the temp build, overlay the shared templates next to the mirrored.typsources, and compile each document with--rootat the docs mirror:temp/docs/formal/— the.typsources +core.typ/utility.typtemp/docs/diagrams/(and any otherdocs/subdir) — mirrored assetstypst compile --root temp/docs temp/docs/formal/<doc>.typ <project>/docs/formal/<doc>.pdfCross-directory asset references (
../diagrams/...) now resolve inside the Typst root, while#import "core.typ"(a same-directory import) still works because the templates are overlaid next to the mirrored sources.General docs-asset solution — any asset under
docs/is reachable, not justdocs/diagrams/. No project-specific special case. Generated*.pdffiles are excluded from the mirror (build outputs, not compile inputs).Tests
tests/test_compile_formal_docs.py— new, 6 tests:find_project_rootfrom the formal dir / returns None when absent.dry_rundoes not compile.*.pdfunderdocs/does not break the temp-mirror copy.typst-dependent tests
skipifcleanly whentypstis not on PATH. Full suite: 139 passing (133 baseline + 6 new).End-to-end verification
Ran the fixed script against adafmt's real
docs/56-diagrams-sync-pdfbranch (SDS with three#figure(image(...))embeds):Consumer impact
compile_formal_docs.pyis invoked by consumers'make docs-formal. The change is backward-compatible: a project whose formal docs reference no cross-directory assets compiles exactly as before (covered by theplain formal doc compilesregression test). The only behavioral change is that cross-directorydocs/-relative asset references — which previously failed — now succeed.Refs