Skip to content

Automate generation of switcher.json for Sphinx version dropdown and Introducing incremental documentation builds for dev productivity#68

Open
sankalps0549 wants to merge 6 commits intomainfrom
feature/switcher-automation
Open

Automate generation of switcher.json for Sphinx version dropdown and Introducing incremental documentation builds for dev productivity#68
sankalps0549 wants to merge 6 commits intomainfrom
feature/switcher-automation

Conversation

@sankalps0549
Copy link
Collaborator

@sankalps0549 sankalps0549 commented Mar 4, 2026

Description

This PR introduces the generate_switcher.py script which reads the git tags available to generate the switcher.json file required by the sphinx documentation version switcher. The script validates version.json against the latest git tag on every run, with safeguards to block faulty version progressions (e.g., 27.0.027.0.2).
Two new flags, --incremental and --include-current, are added to build-docs to speed up local development by skipping already-built tags and allowing the current working tree version to be previewed without creating a git tag.

Fixes # (issue)
#67 - [FEATURE] Automatic generation of switcher.json for sphinx documentation
#69 - [FEATURE] Add --incremental and --include-current flags for faster local docs builds

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document
  • My code follows the style guidelines of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I have added a note to CHANGELOG.md describing my changes
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Changes in this PR

  • Added generate_switcher.py for generating the switcher file required by sphinx documentation version switcher
  • Updated run.py build-docs command to generate the switcher before generating the documentation pages
  • Added the --skip-switcher flag to skip the generation of switcher file (for debugging scenarios)
  • Added --incremental flag to build-docs to only build version tags that don't already have output directories, significantly speeding up repeated local builds
  • Added --include-current flag to build-docs and generate-switcher to build and include the current working tree version from version.json (when newer than the latest tag) without requiring a git tag
  • Added generate-switcher command to run.py with --include-current support (for debugging)
  • Added dirty working tree guard for incremental builds to prevent git checkout failures
  • Added switcher.json distribution to all version output directories after incremental builds to keep dropdowns in sync
  • Added version progression validation that always runs (even without --include-current) to catch skipped versions early in CI
  • Added 55 unit tests for generate_switcher.py covering tag parsing, version sorting, progression rules, and version.json validation

Version Rules

From Version (git tag latest) To Version (version.json) Valid? Rule Error Message / Notes
27.0.0 27.0.0 ⚠️ Same No change from latest tag Uses tag as latest, version.json ignored
27.0.0 27.0.1 ✅ Pass Sequential patch increment Valid progression
27.0.0 27.0.2 ❌ FAIL Cannot skip patch versions Expected v27.0.1
27.0.0 26.0.5 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored
27.0.0 26.0.9 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored
27.0.0 27.1.0 ✅ Pass Valid minor bump with patch reset to 0 Correct progression
27.0.0 27.1.1 ❌ FAIL Patch must be 0 when bumping minor Expected v27.1.0
27.0.0 27.2.0 ❌ FAIL Cannot skip minor versions Expected v27.1.0
27.0.0 26.2.3 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored
27.0.0 26.1.0 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored
27.0.0 28.0.0 ✅ Pass Valid major bump with minor=0, patch=0 Correct progression
27.0.0 28.0.1 ❌ FAIL Patch must be 0 when bumping major Expected v28.0.0
27.0.0 28.1.0 ❌ FAIL Minor must be 0 when bumping major Expected v28.0.0
27.0.0 28.1.1 ❌ FAIL Minor and patch must be 0 when bumping major Expected v28.0.0
27.0.0 29.0.0 ❌ FAIL Cannot skip major versions Expected v28.0.0
27.0.0 26.0.3 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored
27.0.0 24.0.4 ⚠️ Older Version older than latest tag Uses tag v27.0.0 as latest, version.json ignored

Legend

  • Pass: Valid version progression, script succeeds, version added to switcher.json
  • FAIL: Invalid progression, script exits with error code 1, no switcher.json generated
  • ⚠️ Same: version.json matches latest tag, uses tag as latest, version.json NOT added
  • ⚠️ Older: version.json is older than latest tag, uses tag as latest, version.json NOT added

@sankalps0549 sankalps0549 requested a review from Copilot March 4, 2026 22:09
@sankalps0549 sankalps0549 self-assigned this Mar 4, 2026
@sankalps0549 sankalps0549 added the enhancement New feature or request label Mar 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automation to generate the Sphinx version-switcher data (switcher.json) from git tags (and version.json), and wires it into the docs build so the dropdown is no longer maintained manually.

Changes:

  • Introduces scripts/generate_switcher.py to generate docs/source/_static/switcher.json from git tags (with version progression checks against version.json).
  • Extends run.py build-docs to generate the switcher before building docs, plus adds run.py generate-switcher and --skip-switcher.
  • Updates docs/README guidance and CI checkout behavior; removes the committed switcher.json and ignores it going forward.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
scripts/generate_switcher.py New script to generate switcher.json and validate version progression
run.py Adds generate-switcher command + integrates switcher generation into build-docs
docs/source/readme.rst Updates docs instructions to reflect auto-generation and new flag
docs/source/_static/switcher.json Removes previously committed switcher.json (now generated)
README.md Updates top-level docs build notes + adds debug command
.gitignore Ignores generated switcher.json
.github/workflows/ci.yml Ensures tags are available in CI docs build via fetch-depth: 0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sankalps0549 sankalps0549 changed the title Automate generation of switcher.json for Sphinx version dropdown Automate generation of switcher.json for Sphinx version dropdown and Introducing incremental documentation builds for dev productivity Mar 10, 2026
@sankalps0549
Copy link
Collaborator Author

Hi @osinjoku,
I think we can go ahead and dismiss the security/bandit issues. They appear to be low-severity warnings, mostly triggered by our use of subprocess for running git and other Python commands.

"""Fetch all git tags from the repository."""
try:
result = subprocess.run(
['git', 'tag', '-l'], cwd=ROOT_DIR, capture_output=True, text=True, check=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use GitPython?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Automatic generation of switcher.json for sphinx documentation

3 participants