|
| 1 | +# Docs Build and Versioning |
| 2 | + |
| 3 | +This folder contains the Sphinx documentation source and build tooling for local development and GitHub Pages publishing. |
| 4 | + |
| 5 | +## Contents |
| 6 | + |
| 7 | +- [Prerequisites](#prerequisites) |
| 8 | +- [Make Targets](#make-targets) |
| 9 | +- [Multiversion Implementation (No sphinx-multiversion)](#multiversion-implementation-no-sphinx-multiversion) |
| 10 | + - [What Gets Built](#what-gets-built) |
| 11 | + - [Version Selection Rules](#version-selection-rules) |
| 12 | + - [How the Sidebar Switcher Works](#how-the-sidebar-switcher-works) |
| 13 | +- [Purge and Rebuild Behavior](#purge-and-rebuild-behavior) |
| 14 | +- [Local Build and Testing](#local-build-and-testing) |
| 15 | +- [GitHub Pages Deployment](#github-pages-deployment) |
| 16 | +- [Notes and Troubleshooting](#notes-and-troubleshooting) |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- Python environment with docs dependencies installed: |
| 21 | + - `pip install --require-hashes --no-deps -r requirements-docs.lock` |
| 22 | + - or (less strict) `pip install -r requirements-docs.txt` |
| 23 | +- Install the Enchant C library (required by `sphinxcontrib-spelling`): |
| 24 | + - macOS (Homebrew): `brew install enchant` |
| 25 | + - Windows (Chocolatey): `choco install enchant` |
| 26 | +- Run commands from the repo root with `make -C docs ...`, or from this folder with `make ...`. |
| 27 | + |
| 28 | +## Make Targets |
| 29 | + |
| 30 | +The `docs/Makefile` supports these explicit targets: |
| 31 | + |
| 32 | +- `make help` |
| 33 | + - Shows Sphinx make-mode help and all supported builder targets. |
| 34 | +- `make html` |
| 35 | + - Standard single-version HTML build into `docs/build/html`. |
| 36 | +- `make spelling` |
| 37 | + - Runs the spelling builder (`sphinxcontrib-spelling`). |
| 38 | +- `make md` |
| 39 | + - Builds Markdown output to `docs/build/markdown` and copies images/static assets. |
| 40 | +- `make html-multiversion` |
| 41 | + - Builds versioned docs without `sphinx-multiversion` using `scripts/build_versioned_docs.sh`. |
| 42 | +- `make html-multiversion-preview` |
| 43 | + - Same as above, plus local branches for preview/testing. |
| 44 | + |
| 45 | +Catch-all behavior is enabled: |
| 46 | + |
| 47 | +- Any unknown target is forwarded to `sphinx-build -M`. |
| 48 | +- Example: `make clean`, `make linkcheck`, `make dirhtml`. |
| 49 | + |
| 50 | +## Multiversion Implementation (No sphinx-multiversion) |
| 51 | + |
| 52 | +Versioned docs are generated by: |
| 53 | + |
| 54 | +- `docs/scripts/build_versioned_docs.sh` (entrypoint) |
| 55 | +- `docs/scripts/build_versioned_docs.py` (orchestrator) |
| 56 | +- `docs/scripts/select_versions.py` (version selection rules) |
| 57 | + |
| 58 | +### What Gets Built |
| 59 | + |
| 60 | +- `main` branch is always built and published as `current`. |
| 61 | +- Selected release tags are built from git tags. |
| 62 | +- Output layout: |
| 63 | + - `docs/build/html/current/index.html` |
| 64 | + - `docs/build/html/vX.Y.Z/index.html` |
| 65 | + - `docs/build/html/versions.json` |
| 66 | + - `docs/build/html/index.html` (redirects to `current/index.html`) |
| 67 | + |
| 68 | +### Version Selection Rules |
| 69 | + |
| 70 | +`scripts/select_versions.py` applies these rules: |
| 71 | + |
| 72 | +1. Identify the highest major version present in tags. |
| 73 | +2. Include the latest patch release for the last 5 minor series in that major. |
| 74 | +3. Include the latest available release for each of the last 3 majors. |
| 75 | +4. De-duplicate and sort descending (newest first). |
| 76 | + |
| 77 | +Example ordering: |
| 78 | + |
| 79 | +- `current` |
| 80 | +- `v0.16.0` |
| 81 | +- `v0.15.5` |
| 82 | +- `v0.14.0` |
| 83 | +- `v0.13.0` |
| 84 | +- `v0.12.1` |
| 85 | + |
| 86 | +### How the Sidebar Switcher Works |
| 87 | + |
| 88 | +- `scripts/build_versioned_docs.py` writes `versions.json` with `name`, `url`, and `is_latest`. |
| 89 | +- `docs/conf.py` loads this manifest via `DOCS_VERSIONS_FILE`. |
| 90 | +- `docs/_templates/versions.html` renders the version list in the RTD sidebar. |
| 91 | +- Links target `.../index.html` explicitly to avoid directory-listing behavior in local `file://` browsing. |
| 92 | + |
| 93 | +## Purge and Rebuild Behavior |
| 94 | + |
| 95 | +Each versioned build is clean: |
| 96 | + |
| 97 | +- `docs/build/html` is removed before rebuilding. |
| 98 | +- Temporary git worktrees under `docs/build/.worktrees` are removed after build. |
| 99 | +- `git worktree prune` runs at the end. |
| 100 | + |
| 101 | +This ensures old/stale version folders are purged from the publish artifact. |
| 102 | + |
| 103 | +## Local Build and Testing |
| 104 | + |
| 105 | +Use this command order during docs development: |
| 106 | + |
| 107 | +1. Quick content/format validation while iterating: |
| 108 | + |
| 109 | +```bash |
| 110 | +make -C docs html |
| 111 | +``` |
| 112 | + |
| 113 | +1. Always run spelling before finalizing: |
| 114 | + |
| 115 | +```bash |
| 116 | +make -C docs spelling |
| 117 | +``` |
| 118 | + |
| 119 | +1. If your change could affect versioned output or version switcher behavior: |
| 120 | + |
| 121 | +```bash |
| 122 | +make -C docs html-multiversion |
| 123 | +``` |
| 124 | + |
| 125 | +1. If you need to test branch previews in the version menu: |
| 126 | + |
| 127 | +```bash |
| 128 | +make -C docs html-multiversion-preview |
| 129 | +``` |
| 130 | + |
| 131 | +Practical rule of thumb: |
| 132 | + |
| 133 | +- Doc text/layout change only: `html` + `spelling` |
| 134 | +- Versioning/switcher/build-script change: `html` + `spelling` + `html-multiversion` |
| 135 | +- Branch preview verification: add `html-multiversion-preview` |
| 136 | + |
| 137 | +### Open docs |
| 138 | + |
| 139 | +- Direct file open: |
| 140 | + - `docs/build/html/index.html` |
| 141 | +- Recommended local server (more browser-consistent): |
| 142 | + |
| 143 | +```bash |
| 144 | +cd docs/build/html |
| 145 | +python3 -m http.server 8000 |
| 146 | +``` |
| 147 | + |
| 148 | +Then open [http://localhost:8000](http://localhost:8000). |
| 149 | + |
| 150 | +## GitHub Pages Deployment |
| 151 | + |
| 152 | +The workflow is in `.github/workflows/main-docs.yml`. |
| 153 | + |
| 154 | +On push to `main` or release tags: |
| 155 | + |
| 156 | +1. Checkout full history and tags. |
| 157 | +2. Install docs dependencies. |
| 158 | +3. Run `bash docs/scripts/build_versioned_docs.sh`. |
| 159 | +4. Upload `docs/build/html` as Pages artifact. |
| 160 | +5. Deploy with GitHub Pages actions. |
| 161 | + |
| 162 | +The deployed root redirects to `current/index.html`. |
| 163 | + |
| 164 | +## Notes and Troubleshooting |
| 165 | + |
| 166 | +- If version links look wrong, inspect `docs/build/html/versions.json`. |
| 167 | +- If tags seem missing, verify local git tags are fetched: |
| 168 | + - `git fetch --tags` |
| 169 | +- If local browser shows folder listing, use the explicit `index.html` URLs or run a local HTTP server. |
| 170 | + |
0 commit comments