Skip to main content
scripts/build_docs.py · chapter Tests and team tooling, file 23 · 493 lines · open in the repository

What it does

Build the documentation site in docs-site/ (Mintlify) from the code and docs/ (decision 0011). The site is a guided tour of the whole codebase that cannot go stale: written by hand docs-site/index.mdx, docs-site/ask.mdx, the tour chapters docs-site/tour/*.mdx (the story of each stage), and docs-site/reading_order.json (which files each chapter covers, in reading order) generated here one page per file under docs-site/reference/ (its docstring, what is inside, what it uses and what uses it, and the full source), the data contracts, decisions, diagrams, status and handoffs, the file list and diagrams inside each chapter (between the GENERATED markers), and docs.json Every tracked code, config and tooling file must be in reading_order.json, so new work always gets a place in the tour. tests/test_docs_site.py runs --check, and the commit hook runs the tests, so a commit whose docs are out of date is refused until you run this script.
Look at the site locally with the Mintlify CLI (Node 20.17+): cd docs-site && npx mint dev

What is inside

  • ORDER_FILE · line 35
  • GENERATED_DIRS · line 36: rebuilt from scratch each time
  • GENERATED_FILES · line 37
  • HAND_WRITTEN · line 38
  • RESULTS · line 39: scripts/export_results.py writes it
  • RUNNING · line 40: every command, in order: the “Run it” page
  • AI_USAGE · line 41
  • START · line 42
  • END · line 43
  • COVERED · line 46: Files that must have a place in the tour: tracked code, config, tests and team tooling.
  • LANG · line 49
  • SHELL_WORDS · line 51
  • SKIP_DIRS · line 56
  • repo_url() · line 60: The repository’s web address, from reading_order.json (the same on every machine).
  • tracked_files() · line 65: The files git tracks. The commit hook tests a copy of the staged files with no .git folder; there, every file on disk is a staged one.
  • page_of(path) · line 75: The site page of a source file, e.g. src/common/study.py -> reference/src/common/study.
  • escape(text) · line 83: Plain text made safe for MDX: braces and ’<’ would otherwise be read as code.
  • FENCE · line 89
  • mdx(markdown) · line 92: Markdown made safe for MDX: text outside code blocks and code spans is escaped.
  • fence_for(code) · line 110: A code fence longer than any run of backticks in the code.
  • docstring_markdown(doc) · line 116: A docstring as Markdown: blocks indented under a line ending in ’:’ become code blocks.
  • first_paragraph(doc) · line 137
  • yaml_text(s) · line 143
  • frontmatter(title, description, sidebar) · line 147
  • module_name(path) · line 158: The import name of a file under src/, e.g. src/common/study.py -> common.study.
  • imports_of(tree, modules) · line 166: Project files this file imports, in first-use order.
  • comment_header(text, suffix) · line 180: The leading comment block of a non-Python file, as plain text.
  • describe(path, text, modules) · line 198: What a reference page says about one file.
  • reference_page(path, chapter, number, info, used_by, url) · line 252
  • chapter_block(chapter, infos, diagrams) · line 284: The generated part of a tour chapter: its diagrams and its files, in reading order.
  • markdown_page(md, fallback_title, base, images) · line 300: A Markdown file from base (a folder in the repo) as an MDX page: its first heading becomes the title. With images, relative image links point to that folder of the site instead.
  • link_target(relative, base) · line 314: Where a relative link inside a Markdown file in base should point on the site.
  • diagram_pages() · line 326: docs/architecture/*.mmd, paired with their guides: {name: {title, diagram, guide}}.
  • diagram_page(name, d) · line 346
  • load_order() · line 355
  • coverage_problems(order, tracked) · line 359
  • build() · line 368: Every generated file, as {path relative to docs-site/: content}.
  • docs_json(order, decisions, diagrams, handoffs, logs, has_results) · line 416: The site’s settings and navigation (generated: edit this function, not docs.json).
  • same(path, content) · line 446
  • stale(out) · line 452: Generated files that differ from what is on disk, are missing, or should be gone.
  • main() · line 463

Connections

Uses: src/common/settings.py

Source

scripts/build_docs.py