Skip to content

1.16 part 12/18: Almanac: the book as a PDF, Almanac HD and the Golden Record - #183

Closed
epheterson wants to merge 1 commit into
line/1.16.0-11-almanac-pagefrom
line/1.16.0-12-almanac-book-hd
Closed

epheterson wants to merge 1 commit into
line/1.16.0-11-almanac-pagefrom
line/1.16.0-12-almanac-book-hd

Conversation

@epheterson

@epheterson epheterson commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Part 12 of 18 of Zimi 1.16.0: Almanac: the book as a PDF, Almanac HD and the Golden Record. Base: line/1.16.0-11-almanac-page (part 11); the diff shows only this part's files. The PR carries the not-a-release label and the version stays 1.15.7, so merging it cuts no release. Merge in order (1 to 17, then 18) with a merge commit, not a squash.

What this is

Three things the Almanac needs off the page. The book of tables is typeset as a PDF by the server without a browser. Almanac HD is fetched once, in two sizes, from the release. The Golden Record pictures become WebP with a credit for each. The Almanac ZIM's own source is also updated; the built ZIM lands on top of part 16.

What changes

  • zimi/almanacbook.py (new): lays out the book's HTML with PyMuPDF's HTML engine (Story) in Charis SIL, then draws running heads and feet, contents page numbers with dotted leaders, links, the outline, and small vector pictures. render(html, paper) returns the PDF bytes.
  • zimi/almanacmath.py (new): lays out Presentation MathML (Temml's output) in Noto Sans Math and draws it onto a PDF page as embedded text, with TeX-style script sizes, fractions on the maths axis and fences stretched to their content. It refuses DOCTYPEs and entities.
  • zimi/almanacpdf.py: the browser-driven PDF path is replaced. A render runs as its own process (python -m zimi.almanacbook) under a time limit, one at a time with a short queue behind it (past that the server answers busy), and the same document asked again returns the PDF already made. A frozen desktop build renders on the request's thread.
  • zimi/almanachd.py: Almanac HD is one ZIM, zimi_almanac_maxi_<month>, in two sizes, one installed at a time: HD (one release file) and Maximum (zimsplit chunks fetched into a hidden staging folder, each checked against its sha256, the whole book checked before it replaces HD). Reading the release manifest is part of the Ask first, Automatically or Never setting; ZIMI_OFFLINE is Never. Older copies are listed, not deleted.
  • scripts/build_almanac_hd.py, scripts/build_almanac_maxi.py: tiles are cut at each source's native resolution (nothing magnified), with Cassini moon and Phobos tone tables, hole filling and shaded terrain maps added, and the two flavours are built from a pinned tile source. scripts/publish_almanac_tiles.py (new) packs, splits, checks and pins that source; it uploads only with --upload.
  • zimi/assets/almanac-tiles.json gains hd_size and max_size; .github/workflows/almanac-hd.yml notes the memory the build needs and adds tifffile.
  • scripts/verify_almanac_qids.py: audits each curated Q-ID against English Wikipedia (wrong item, disambiguation page, missing page); --landmarks audits zimi/static/earth/landmarks-v1.json against Wikidata and checks every link key almanac-earth.js asks for, exiting 1 so it can gate a release.
  • zimi/static/golden-record/*.webp replace the .gif files; credits.json names each picture's owner and whether it is public domain.
  • zimi/builtin/almanac/index.html, local.js, zimi.txt: the ZIM's page loads its scripts in order with a retry for a busy server (kiwix-serve), serves the all-satellites snapshot, drops the old credit line, and the title becomes "Zimi Almanac".

How to review

  • Read first: almanacpdf.py (the subprocess, time limit and queue: a hang or leak holds the server), then almanachd.py (consent before any network read, the sha256 checks, what is removed when a size replaces the other).
  • Then almanacmath.py layout (the parser handles client-sent text) and almanacbook.py render (fetches nothing; images come only from the book's own archive).
  • Risk: data loss in almanachd.py (HD and Maximum swap, older copies never deleted unasked), network calls (manifest and chunk fetches), and a PDF render's memory and time on a long book.
  • Skip: the 47 renamed golden-record/*.webp (binary), tests/test_almanac_hd_sizes.py beyond its docstring.
  • Rides here: tests/test_older_copies_delete.py first passes at this tip (Storage's "Older copies" Delete is the HD change). The ZIM's index.html loads scripts that land in parts 13 to 16.

Tests

  • PDF: tests/test_almanac_pdf.py (the /almanac/pdf route: size limit, nothing fetched, one render at a time in its own process killed at its time, the file removed after its time, 501 where PyMuPDF is missing).
  • HD: tests/test_almanac_hd.py, tests/test_almanac_hd_sizes.py, tests/test_older_copies_delete.py, tests/test_almanac_zim_size.py.
  • Browser: tests/test_almanac_hd_browser.py, tests/test_almanac_hd_climb_browser.py, tests/test_almanac_hd_holes_browser.py.
  • Own ZIMs in a real kiwix-serve: tests/test_own_zims_kiwix_serve.py (skips without kiwix-serve unless CI requires it).
  • Q-IDs: tests/test_almanac_qids.cjs. Tests named for this part that first pass in parts 16 and 17: the HD build, release and workflow tests, the ZIM and Golden Record tests.

Summary by cubic

Typesets the Almanac's book as a PDF without a browser, makes Almanac HD one ZIM in two sizes installed one at a time, and serves the Golden Record pictures as WebP with credits for each.

PDF

  • Replaces the headless-Chromium path with PyMuPDF's Story engine, which typesets the page's own HTML in Charis SIL.
  • zimi/almanacbook.py draws the running heads and feet, contents page numbers with dotted leaders, links, the outline, and vector pictures; zimi/almanacmath.py typesets Presentation MathML in Noto Sans Math as embedded, subsetted text.
  • Renders run in their own process under a time limit, one at a time with a short queue (past that the server answers busy); a frozen desktop build renders on the requesting thread.
  • Nothing the client sends is fetched (images come only from the book's own archive), and the route answers 501 where PyMuPDF is missing; the MathML parser rejects DOCTYPEs and entities.

Almanac HD

  • Almanac HD is one ZIM in two sizes: HD (zimi_almanac_maxi_<month>, one release file, some layers cut short to fit it) and Maximum (zimi_almanac_ultra_<month>, zimsplit chunks fetched into a hidden staging folder), each chunk checked against its sha256 with the whole book verified before it replaces the other.
  • Reading the release manifest stays behind the Ask / Automatically / Never setting; older copies are listed, never deleted unasked.
  • Tiles are cut at each source's native resolution (nothing magnified) for every world in the 3D view, with Cassini moon and Phobos tone tables, hole filling, and shaded terrain maps; scripts/publish_almanac_tiles.py packs, chunks and pins that source, and the two builds draw from it and a hand-built craft folder.
  • The tile build needs a big machine and no longer finishes on a standard GitHub runner; scripts/verify_almanac_qids.py audits the curated Q-IDs against English Wikipedia and the 3D view's landmarks against Wikidata, exiting 1 so it can gate a release.
  • The built ZIM's title is now "Zimi Almanac", its page loads scripts in order with a retry for a busy kiwix-serve, serves the all-satellites snapshot, and a test holds the ZIM to its size budget by storing data files as a compressible type.

Written for commit 1182462. Summary will update on new commits.

View guided diff Turn on auto-fix

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@epheterson epheterson added the not-a-release Ships nothing; CI skips the version check label Nov 23, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Sorry @epheterson, your pull request is larger than the review limit of 150,000 diff characters

@epheterson
epheterson force-pushed the line/1.16.0-11-almanac-page branch from 8d0916f to b6b2e5a Compare November 23, 2026 10:07
@epheterson
epheterson force-pushed the line/1.16.0-12-almanac-book-hd branch from f6719e6 to a82ebed Compare November 23, 2026 10:07
@epheterson
epheterson force-pushed the line/1.16.0-11-almanac-page branch from b6b2e5a to 5c6a4ad Compare November 23, 2026 10:12
@epheterson
epheterson force-pushed the line/1.16.0-12-almanac-book-hd branch from a82ebed to e335882 Compare November 23, 2026 10:12
@epheterson
epheterson force-pushed the line/1.16.0-11-almanac-page branch from 5c6a4ad to 387e48d Compare November 23, 2026 10:52
@epheterson
epheterson force-pushed the line/1.16.0-12-almanac-book-hd branch from e335882 to 98d1b9e Compare November 23, 2026 10:52
@epheterson
epheterson force-pushed the line/1.16.0-11-almanac-page branch from 387e48d to 4dfe97a Compare November 23, 2026 16:37
@epheterson
epheterson force-pushed the line/1.16.0-12-almanac-book-hd branch from 98d1b9e to 193d2a9 Compare November 23, 2026 16:37
@epheterson
epheterson force-pushed the line/1.16.0-11-almanac-page branch from 4dfe97a to eace8c2 Compare November 23, 2026 16:44
@epheterson
epheterson force-pushed the line/1.16.0-12-almanac-book-hd branch from 193d2a9 to 1182462 Compare November 23, 2026 16:45
@epheterson

Copy link
Copy Markdown
Owner Author

Reviewed here; included in the release PR #189.

@epheterson epheterson closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

not-a-release Ships nothing; CI skips the version check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant