Skip to content

Commit 6127587

Browse files
authored
Automate generation of switcher.json for Sphinx version dropdown and Introducing incremental documentation builds for dev productivity (#68)
* Automate generation of switcher.json for Sphinx version dropdown * Adding check to stop invalid minor and patch updates at once * incremental and current builds added for dev env * Version name sanitization * Review comments, and tests addition * Review comments * Introducing gitpython
1 parent 29d7479 commit 6127587

File tree

11 files changed

+1049
-76
lines changed

11 files changed

+1049
-76
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151

5252
steps:
5353
- uses: actions/checkout@v5
54+
with:
55+
fetch-depth: 0 # Fetch all history and tags
5456

5557
- name: Set up Python
5658
uses: actions/setup-python@v5

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ instance/
7171

7272
# Sphinx documentation
7373
docs/_build/
74+
docs/source/_static/switcher.json
7475

7576
# PyBuilder
7677
.pybuilder/

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,46 @@ python run.py build
6868
python run.py build-docs
6969
```
7070

71-
> ***Note: When releasing a new version, update ``switcher.json`` in ``docs/source/_static/`` to include the new tag in the version dropdown for documentation.***
71+
The documentation version switcher (`switcher.json`) is automatically generated from git tags during the build process. Only tagged versions are included by default to ensure all links work correctly.
7272

7373
Options:
7474
- `--skip-build` (`-s`): Skip building before generating docs
7575
- `--local` (`-l`): Build documentation locally for a single version (skips multi-version build)
76+
- `--skip-switcher`: Skip generating switcher.json (useful for offline builds or custom switcher configurations)
77+
- `--include-current`: Include current working tree version from version.json in switcher (useful during development before tagging)
78+
- `--incremental`: Only build versions that don't have existing output directories (speeds up development by skipping already-built versions)
79+
80+
**Debug command:** To manually generate `switcher.json` without building docs:
81+
```sh
82+
python run.py generate-switcher
83+
```
84+
85+
**Development workflow:** When working on a version bump before tagging:
86+
```sh
87+
# Build docs including your current unreleased version
88+
# This will:
89+
# 1. Build all tagged versions via sphinx_multiversion
90+
# 2. Build current working tree version via sphinx
91+
# 3. Add current version to switcher.json as latest
92+
python run.py build-docs --include-current
93+
```
94+
95+
**Note:** By default, if `version.json` contains a version newer than the latest git tag, it will be validated but NOT added to the switcher (to prevent broken links). Use `--include-current` to build and include it during development, or create a git tag to include it permanently.
96+
97+
**Fast development iteration:**
98+
```sh
99+
# First build (builds all versions)
100+
python run.py build-docs --include-current
101+
102+
# Subsequent builds (only rebuilds current version, skips existing tagged versions)
103+
python run.py build-docs --include-current --incremental
104+
```
105+
106+
**How `--incremental` works:**
107+
- Checks which version directories already exist in `docs/build/html/`
108+
- For missing tagged versions: checks out each tag, builds docs, then restores your branch
109+
- For current version (with `--include-current`): only builds if directory doesn't exist
110+
- Useful during development to avoid rebuilding all historical versions every time
76111

77112
The documentation can be accessed locally by serving the docs/build/html/ folder:
78113
```sh

docs/source/_static/switcher.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/source/readme.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,10 +1259,29 @@ The project includes a ``run.py`` script with several useful commands:
12591259

12601260
- ``--skip-build`` (``-s``): Skip building the package before generating docs
12611261
- ``--local`` (``-l``): Build documentation locally for a single version (skips multi-version build)
1262+
- ``--skip-switcher``: Skip generating switcher.json (useful for offline builds or custom switcher configurations)
1263+
- ``--include-current``: Build and include current working tree version from version.json (useful during development before tagging)
1264+
- ``--incremental``: Only build versions that don't have existing output directories (speeds up development by skipping already-built versions)
12621265

12631266
.. note::
1264-
When releasing a new version, update ``switcher.json`` in ``docs/source/_static/``
1265-
to include the new tag in the version dropdown.
1267+
The documentation version switcher (``switcher.json``) is automatically generated from
1268+
git tags during the build process. Only tagged versions are included to ensure all
1269+
documentation links work correctly. If ``version.json`` is newer than the latest tag,
1270+
create a git tag to include it in the version switcher.
1271+
1272+
**Incremental Builds for Development:**
1273+
1274+
For faster iteration during development, combine ``--include-current`` with ``--incremental``:
1275+
1276+
.. code-block:: bash
1277+
1278+
# First build (builds all versions)
1279+
python run.py build-docs --include-current
1280+
1281+
# Subsequent builds (only rebuilds current version)
1282+
python run.py build-docs --include-current --incremental
1283+
1284+
The ``--incremental`` flag preserves existing version builds and only builds what's missing, significantly speeding up documentation updates during development.
12661285

12671286
**Viewing Documentation Locally**
12681287

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=75.0"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pyright]
6+
extraPaths = ["scripts"]

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ markers =
33
unit: Unit tests that run quickly and test small pieces of functionality
44
integration: Integration tests that check multiple components together
55
core: Core functionality tests
6+
scripts: Scripts tests
7+
generate_switcher: Tests for scripts/generate_switcher.py
68
file_set(set_name): Mark test to run on a specific FileSet
79
json_file_name(file_name): Mark test to use a specific JSON file for expected data
810
cad_manager: Tests the CADManager class

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ black==26.3.1
22
build==1.2.2.post1
33
coverage==7.6.12
44
docopt==0.6.2
5+
gitpython==3.1.46
56
packaging==24.2
67
pathspec==1.0.4
78
polib==1.2.0

0 commit comments

Comments
 (0)