Skip to content

site-build: build the PDF of a site that publishes one, and serve it at _pdf/ - #106

Merged
mmcky merged 7 commits into
mainfrom
site-build/pdf
Nov 27, 2026
Merged

mmcky merged 7 commits into
mainfrom
site-build/pdf

Conversation

@mmcky

@mmcky mmcky commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

The rest of QuantEcon/project-monorepo#77 starts with the PDF. Five of the six sites publish one (publishes: [html, pdf, notebooks] in site.yml: intro, advanced, programming, intermediate and jax; dp publishes none). Their series build it and serve it at _pdf/, where the theme's "Book (PDF)" link points. Until now the site build made the HTML and the notebooks only.

What it adds

  • The PDF, strict, from the cache. For a site whose site.yml publishes pdf, a step after the notebooks runs build-lectures with the pdflatex builder and -W --keep-going. build-lectures adds -n, so the build matches the HTML's -n -W. It reads the cache the HTML build filled, so it executes nothing. A failed build uploads its reports as execution-reports-<key>-pdf. LaTeX comes with the full image and with the GPU machine image, which the GPU series' own PDF builds use.
  • Served at _pdf/. quantecon-book-theme shows the "Book (PDF)" link only when _build/html/_pdf/ is a folder as it renders the pages. The series build the PDF first and copy it in. Here, as for the notebooks, the folder is made before the HTML build, so the HTML build stays the one that executes the pages. The PDF is then copied in, as the series copy theirs (cp _build/latex/*.pdf _build/html/_pdf/).
  • ImageMagick (38c4d3a). Jupyter Book's PDF build turns on sphinx.ext.imgconverter, which needs convert for an image LaTeX can't take, an SVG or a GIF. Three jax pages have a remote SVG logo that MyST's html_image makes an image of, so jax's strict PDF failed without it in the first run. Every leg that builds a PDF now installs ImageMagick, as lecture-jax's workflows do, unless convert is already there: as root in a container, and with sudo on the GPU machine. It takes 6 to 22 seconds.
  • Checked. The copy step fails when the build wrote no PDF, when no page links to one under /_pdf/ (the theme didn't see the folder), or when a page links to a PDF the build didn't make. The theme names the link after latex_documents' targetname. The HTML artefact then carries the PDF with the pages.
  • Docs: the workflow's header (a step 9, and the PDF leaves "what it does not do"), README.md's build paragraph, and sites/README.md's publishes row and strictness note.
  • One line from the review of site-build: jax joins the base environment on the GPU leg #105: sites/jax/site.yml's Sources line now leads with the pin it was last read at (3431f12, 2026-11-27).

Checked

  • The build (run 45923688718 at 38c4d3a, green on every leg). Each PDF step read the cache and executed nothing. The steps took 71 s for jax, 102 s intro, 110 s programming, 182 s advanced and 631 s intermediate. intro's and advanced's PDFs build strict (-n -W), although their series build theirs with -n alone. Every content page links to the one PDF its site made; the only pages without the link are index.html, index_toc.html and the redirect pages.
  • Against each series' own PDF (the evidence comment: site-build: build the PDF of a site that publishes one, and serve it at _pdf/ #106 (comment)). Page counts are identical (995, 1906, 446, 3906, 403), and so are the outlines. Each section's text was compared with digits removed, and every word change falls into a class. Those are: upstream changes since the series' last publish, checked against the upstream diffs; the pool's bibliography rulings; one pool asset path; link texts taken from another site's current titles; execution output (dates, draws, a live API search, environment paths); and layout.
  • tools/tests give 330 passed and 1 skipped; actionlint and pool-check are clean.

Not compared: the figures, which are images in the PDF and were validated through the HTML in each site's own PR.

Copilot: not requested (Matt, 2026-11-22).

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG

mmcky and others added 5 commits November 27, 2026 09:30
…at _pdf/

Part of the rest of QuantEcon/project-monorepo#77. A site whose site.yml
publishes pdf (intro, advanced, programming, intermediate and jax) gets
its PDF as the series build theirs: the pdflatex builder, strict (-n -W),
from the execution cache the HTML build filled, so it executes nothing.
The PDF is copied into _build/html/_pdf/, which is made before the HTML
build, as _notebooks/ is, so quantecon-book-theme shows each page's
"Book (PDF)" link; the copy step then checks that every /_pdf/ link the
pages carry names a file it copied.

LaTeX comes with the full image (QuantEcon/actions' quantecon container)
and with the GPU machine image, whose series build their PDFs on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
From the organiser's review of #105: the line now leads
with 3431f12, the pin in sync/state.yml, read 2026-11-27, and keeps the
first read (7d8050c, 2026-11-17) after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
The first run's jax leg failed its strict PDF on "Unable to run the image
conversion command 'convert'": sphinx.ext.imgconverter, which Jupyter
Book's PDF build turns on, converts the remote SVG logo that MyST's
html_image makes an image of on three of jax's pages
(inventory_dynamics_jax, kesten_processes_jax and jax's troubleshooting
page). lecture-jax's own workflows install ImageMagick for this; neither
the full image nor the GPU machine image has it. Every leg that builds a
PDF now installs it (as root in a container, with sudo on the GPU
machine), unless `convert` is there already. The other four PDF sites
built theirs without it, intro's and advanced's strict included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
@mmcky

mmcky commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Validation at 38c4d3a (run 45923688718, green on every leg)

The first run, at 2bd6fe2 (45921465212), was green on every leg but jax. jax's strict PDF failed on Unable to run the image conversion command 'convert'. MyST's html_image makes an image of a remote SVG logo on three jax pages (inventory_dynamics_jax, kesten_processes_jax and jax's troubleshooting page), and LaTeX can't take an SVG. lecture-jax's own workflows install ImageMagick for this. 38c4d3a installs it on every leg that builds a PDF: 6 seconds in a container, about 20 on the GPU machine. intro's and advanced's PDFs built strict (-n -W) in both runs, although their own builds use -n alone.

The build

Site PDF step Pages Pages linking to the PDF
intro 102 s 995 60 of 66
advanced 182 s 1906 83 of 85
programming 110 s 446 29 of 31
intermediate 631 s 3906 164 of 176
jax 71 s 403 36 of 50

Each PDF step read the cache the HTML build filled, and no notebook executed in the leg. The copy step found one PDF per site, and every /_pdf/ link on the pages names it. The pages without the link are index.html, index_toc.html and the redirect pages for old lecture names.

Against each series' own PDF

The baseline is each series' live PDF, from its last publish run: intro 530ede2 (2026-10-09), advanced 63ef0be (2026-11-22), programming 85586e6 (2026-10-12), intermediate 0dc4fe7 (2026-11-23) and jax 7d8050c (2026-11-11). From those commits to the pins, the series changed 6, 8, 11, 0 and 5 lectures. Each section of the PDF's outline (a part or a lecture) is extracted with pdftotext and compared with its counterpart by title. Digits are removed first, and timings, object addresses and running headers are set aside. A letters-only comparison then separates layout from word changes, and each word change is classified below.

Site Pages, pool / own Sections Same text Layout only Word changes
intro 995 / 995 73 / 73 59 2 12
advanced 1906 / 1906 91 / 91 37 36 16
programming 446 / 446 33 / 33 20 2 11
intermediate 3906 / 3906 183 / 183 165 11 7
jax 403 / 403 43 / 43 23 2 18

No section is missing from either side or extra in one, and every word change falls into one of these classes:

  • Upstream changes since the series' last publish: 28 sections (6 intro, 8 advanced, 9 programming, 5 jax), each in a lecture that changed. I checked their content edits against the upstream diffs, and each is there: --upgrade dropped from in-cell installs, intro's sort=True and resample(, programming's typo fixes and rewrites ("altogether", "Insufficient", requests.get, "provided by the builtins module"), and advanced's Kaleido call, marker= and "intermediate lecture series". Their other word changes fall into the classes below.
  • Link texts from another site: a {doc} link to another site's lecture takes that site's title at build time. advanced's links to intermediate's perm_income_cons and perm_income read "Permanent Income II: LQ Techniques" and "The Permanent Income Model", intermediate's titles today. The live advanced PDF, built 2026-11-22, has the earlier "Optimal Savings II: LQ Techniques" and "Optimal Savings I: The Permanent Income Model".
  • The pool's bibliography (Matt's rulings of 2026-11-02 and the house style, as the HTML validations of site-build: the base environment, the full image with the list; intro joins #84, site-build: advanced joins the base environment #86, site-build: intermediate joins the base environment on the GPU leg #99 and site-build: jax joins the base environment on the GPU leg #105 found): months dropped, Econometrica's subtitle dropped, and the corrected entries. Those are Papoulis for "Athanasios and Pillai", Bertsimas and Tsitsiklis, Hu and Guo, Pareto for "Vilfredo", and Hansen and Sargent (1995) against Hansen et al. (2020) where advanced's keys were corrected. This covers each site's Bibliography and the in-text citations of intro's lp_intro and wealth_tax and of advanced's classical_filtering, lu_tricks, doubts_or_variability and risk_aversion_or_mistaken_beliefs.
  • The pool's asset paths: one plt.savefig path in intro's long_run_growth (_static/lecture_specific/long_run_growth/ to _static/long_run_growth/).
  • Execution: dates printed by statsmodels and nvidia-smi (intermediate's ols, mle and status page, programming's status page, and 12 jax sections); a timing's unit (intermediate's lagrangian_lqdp); the layout of a printed table of e-notation numbers (advanced's hansen_jagannathan_1991); simulated draws (intro's markov_chains_I, intermediate's finite_markov); the live World Bank search in intro's inequality; an iteration print in intermediate's odu; the environment's path (/opt/conda against the runner's miniconda) and the build directory in programming's python_essentials; and chang_credible's GLPK notice, gone as in the HTML. Eigenvector and other sign changes count as layout here, since signs are not letters. In the HTML validation they were platform round-off.
  • Layout: line breaks, hyphenation, maths spacing, and page breaks that move a running header, a figure caption or a "(continued from previous page)" marker (intro's inequality too). This includes the maths text pdftotext reads in advanced's dovis_accounting_mf and entropy.

Not compared: the figures, which are images in the PDF and were compared through the HTML for each site in its own PR.

Each PDF is in its leg's html-<key> artefact under _pdf/.

@mmcky
mmcky marked this pull request as ready for review November 27, 2026 02:09
mmcky and others added 2 commits November 27, 2026 13:56
- The copy step's "no page links to a PDF" error can print: under
  pipefail a grep that found nothing failed the assignment before the
  check, so the step failed with no reason given.
- On main the execution cache is saved when the HTML build succeeded,
  whatever a later step did. It is the HTML build's alone, so a failed
  notebooks or PDF build (a LaTeX error, an apt mirror down while
  ImageMagick installs) no longer throws a cold build's execution away.
  The header's step 11 says so.
- apt-get update waits for the dpkg lock too (DPkg::Lock::Timeout=600).
- The notebooks and PDF builds reuse the HTML build's Sphinx environment
  ("0 added, 0 changed, 0 removed"): the comments, README.md and
  sites/README.md say that, not "from the cache the HTML build filled".
- The copy step's comment notes that the theme's link is from the domain's
  root, right for the five PDF sites; a PDF site served under a path would
  pass the check and 404.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
@mmcky
mmcky merged commit aa281d3 into main Nov 27, 2026
9 checks passed
@mmcky
mmcky deleted the site-build/pdf branch November 27, 2026 06:58
mmcky added a commit that referenced this pull request Nov 27, 2026
…#106 (#108)

## Why

The reviews of #102 (`tools/stage-site --local-links`) and #106 (the PDF) left points to take after their merges. This PR takes them. None changes what any site builds or publishes today.

## tools/stage-site (from the reviews of #102)

- **A left-over original that changes nothing.** An earlier `--clean` that kept an edited lecture leaves its original under `_build/stage-site-originals/`, and staging refused while it was there. It now refuses only when the original differs from the pool's lecture as it is now. Once the lecture has been put back by hand, replacing the original loses nothing.
- **The originals folder.** Staging refuses when `_build/stage-site-originals` is a link or a file. It also refuses when a lecture's place in that folder holds a link, dangling ones included. A dangling link is not `.exists()`, so copying the original would have written through it. The confinement `--clean` uses refuses a folder that is itself a link, whose target it would otherwise confine to.
- **The paragraph reading is main's.** This PR first changed how `tools/stage-site` reads paragraphs, so that inline literals are found as CommonMark finds them. After four review rounds, that hand-written reading still disagreed with markdown-it on 9 of 62 cases, against 21 for main's. The maintainer chose to split it out (Matt, 2026-11-27, in the project-monorepo session: "Split; markdown-it next (Recommended)"). So `prose_mask` is main's again, and a separate PR will read paragraphs and code spans with markdown-it and MyST's plugins, exact by construction.

## site-build.yml (from the review of #106)

- **The cache save** runs on `always()` with the outcome of the HTML build and of its execution report. A job that times out or is cancelled in a later step, the PDF build say, still keeps a cold build's execution. The header's cache paragraph and `sites/README.md` no longer say "after a green build".
- **The PDF copy step's grep:** finding nothing (exit 1) is reported by the check after it. A real error (exit 2, such as an unreadable folder) now fails the step with grep's own message. `|| true` had let that pass green.
- `sites/README.md`'s `publishes` row no longer says "the same way" twice, and a comment left short by rewrapping is rewrapped.

## Checked

- **On the pool** (at `aa281d3`): the reading is main's, so every pool lecture reads as on main (0 lines differ), and dp's `--local-links` plan is the same 31 links in 13 lectures, byte for byte.
- **Tests:** 361 passed and 1 skipped (at `5498ef2`). Each fix has a test that fails without it: the left-over original that matches (put back and staged again), a dangling link where an original goes, a folder there, and an originals folder that is a link or a file, at staging and at `--clean`.
- **The copy step**, its script taken from the workflow and run under `bash --noprofile --norc -eo pipefail` on local cases:
  - a good build passes;
  - a wrong name fails with its message;
  - no link fails with its message;
  - an unreadable folder fails with grep's "Permission denied" (with `|| true` it passed).
- actionlint is clean; pool-check is clean.

This PR's site build runs all six sites, since it touches `tools/stage-site`. Every leg restores main's cache.

Copilot: not requested (Matt, 2026-11-22).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
mmcky added a commit that referenced this pull request Nov 28, 2026
## Why

The last open part of QuantEcon/project-monorepo#77. Its acceptance criteria:
- "A pull request that touches one shared lecture rebuilds every product that lists it and no other";
- "A planted broken lecture fails every product that holds it and no other product's build".

Today every pull request and push to `main` that touches a build input builds all six sites. A fix to one intro lecture also rebuilds intermediate, programming and jax on the GPU machines. For pushes to `main` the owner chose the same narrowing on 2026-11-27, in the project-monorepo session: "Affected only (Recommended)". The schedule and a manual run still build every site.

## What it adds

- **`tools/affected-sites`** reads the changed paths and prints the sites, of those named, that they reach:
  - a lecture, or its own `_static/<slug>/` files: the sites whose `_toc.yml` lists it, at any depth of parts, chapters and sections;
  - a `_static/_shared/` asset: the sites of the lectures the ledger records as using it, or every site when it records none;
  - a `_static/<dir>/` that is no pool lecture's folder: every site;
  - a site's own file: that site (`sites/README.md` reaches none);
  - `tools/sync` and `sync/state.yml`: the sites in the `series` environment, here or at the base, since only those run `tools/sync` (today dp). `sync.yml`'s near-daily pin refresh starts no run, but the next push takes it in, and it builds dp alone;
  - any other build input: every site. That covers the bibliography, any other pool file, a build tool, `_base/`, `sync/manifest.yml` (which `tools/stage-site` reads for every site) and the workflow. These are the workflow's path filter outside the pool and the sites, and a test keeps the two lists in step;
  - anything else (documentation, the tests, another workflow, the other sync records): none.

  With `--base`, the contents lists and the ledger are read at the base too. So a lecture a change drops still builds the sites that listed it, and a shared asset its old users' sites. Paths come NUL-separated with `-z`. The tool refuses a `--base` that is no commit, and a contents list or ledger it can't parse, with exit 2. Links between sites don't widen the set: intersphinx resolves them against the other site's published inventory, not this build.
- **`site-build.yml`**'s first job chooses the sites:
  - **A pull request** is compared with its base.
  - **A push** is compared with the head of the last build on `main` that succeeded, not the commit before it. That build may be a push, scheduled or manual one, but never a pull request's. A run cancelled while it waits (the concurrency group keeps one waiting), cancelled by hand, or failed then leaves nothing unbuilt: the next push takes its change in. A step of its own reads that run through the API, with `actions: read`. It runs only on a push, and is the only step that holds the token.
  - **While a site stays red on `main`,** no build succeeds, so each push builds all that has changed since the last green build. The header says to mend a red site first. It also says to re-run an older push build's failed jobs, not all its jobs.
  - **The schedule and a manual run** take every site, and so does a base that can't be found or fetched.
  - The diff is `git diff --no-renames --name-only -z`. A renamed or moved file counts by its old path as well as its new one, and a name git would quote keeps its bytes. Only the base commit is fetched: a diff of two trees needs no history.
  - **A change to the rule itself** (the tool or this workflow) builds every site without asking the tool, so a broken tool can't skip its own build.
  - The job writes "Sites built: … " and the reason to the run summary. When a change reaches no site, the build job is skipped, since GitHub refuses an empty matrix.
- **The header:** who builds what, and how a push is compared. "What it does not do" now puts mystmd and the shared cache in the second phase, after the cutovers, which takes in the note deferred from #110.
- **Docs:** README's build paragraph and tools table, and `sites/README.md`'s "Building a site in CI".

## Checked

- **Tests:** 501 passed and 1 skipped. They cover:
  - every rule (24 cases), including a section nested in a part and the series inputs;
  - a site moved out of the series environment, read at the base, and a site with no `site.yml`;
  - over a real git history: a dropped lecture, the ledger read at the base, a renamed lecture, an asset moved between two lectures' folders, and a name git would quote;
  - a key with no site, a base that is no commit, and a contents list that can't be parsed;
  - the workflow, read for its path filter (both events), its diff flags, the rule check, the push base's query step, and that only that step holds the token.

  Six of the new tests fail on the first version of the tool, and dropping the ledger's base reading fails one. actionlint and pool-check are clean.
- **On the real pool,** with the workflow's own diff command:
  - `git mv lectures/os_stochastic.md lectures/os_stochastic_v2.md` builds dp and intermediate;
  - moving an `about_py` figure into `os_stochastic`'s folder builds dp, programming and intermediate;
  - a new `_static/lecture_specific/…` builds all six;
  - `about_py/café.png` builds programming;
  - the pin refresh `fc2ea1f` builds dp alone.
- **On tonight's merges** (each squash commit against its parent):

  | Merge | Sites it would build |
  |---|---|
  | the refresh #107 (two intro lectures) | intro alone, instead of all six |
  | #101 (pool-check, its tests, `sites/README.md`) | none; it built all six |
  | #110 (the README) | none |
  | #106 (`site-build.yml`) | all six |
  | #109 (`tools/stage-site`) | all six |

- **Real runs, each from a throwaway draft against this branch, now closed:**
  - #112 planted a failing cell in a lecture that dp and intermediate list. Only those two legs ran, and both failed in the strict build on the planted error.
  - #113 changed only `sites/README.md`. The matrix job reported no site, and the build job was skipped.

  The evidence comments below have the details.
- **This PR's own build** changes the workflow, so it builds all six: the "rule itself" path.
- **The push path** can't run before the merge. Its query, run now against this repository, returns 31f29fc (#101), the last build on `main` that succeeded. The first push after the merge carries this workflow, so it builds all six. The "Sites built" summaries of the first two push builds on `main` are to be read after the merge. The first should say it touches the rule, against 31f29fc. The second should be compared with the merge commit, if the first went green.

The validation rule: this changes which sites build, not how. The legs that run are unchanged steps, so a full output comparison isn't needed. The planted test is the evidence.

Copilot: not requested (Matt, 2026-11-22).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant