Skip to content

Conversation

@david-tingdahl-nvidia
Copy link
Contributor

Problem

When building multi-version documentation with sphinx-multiversion for
branches v0.0.8-docs and v0.0.9-docs, both versions incorrectly displayed
"nvblox_torch 0.0.9" in the page titles and all wheel download URLs pointed
to v0.0.9 files, regardless of which version was being built.

Root Cause

Multiple interacting issues:

  1. Python Module Caching: The original approach imported version from setup.py at module level. Python's import system cached the first imported module, causing all subsequent builds to reuse the same cached version (0.0.9) across all versions.

  2. Timing Issues: conf.py is executed before sphinx-multiversion sets up version-specific source directories, so CWD-based detection failed.

  3. Config Dictionary Creation: The nvblox_torch_docs_config dictionary was created at module import time with hardcoded/default version values, before the correct version could be detected.

Solution

Use Sphinx's setup() function which runs after initialization and provides
app.srcdir pointing to each version's checked-out source directory.

The setup() function:

  1. Detects the version by reading setup.py from app.srcdir (the correct version-specific checkout directory)
  2. Updates app.config.html_title with the correct version
  3. Updates app.config.nvblox_torch_docs_config with version-specific:
    • external_wheel_base_url (e.g., /download/v0.0.8/ vs /download/v0.0.9/)
    • wheel_name_* entries with correct version and patch (rc5 vs .dev1)

Changes

docs/conf.py (both v0.0.8-docs and v0.0.9-docs):

  • Removed module-level version import from helpers.py/setup.py
  • Set NVBLOX_VERSION_NUMBER to default value (overridden in setup())
  • Added setup(app) function that:
    • Detects version from app.srcdir/nvblox_torch/setup.py
    • Updates html_title dynamically
    • Updates nvblox_torch_docs_config dictionary entries
  • Added get_wheel_name() helper function (v0.0.9-docs)
  • Added _get_wheel_name() nested function (v0.0.8-docs)
  • Changed smv_branch_whitelist from v0.0.8|v0.0.9 to v0.0.8-docs|v0.0.9-docs

docs/_templates/versioning.html (v0.0.8-docs):

  • Created version selector sidebar template for sphinx-multiversion

docs/helpers.py (v0.0.9-docs):

  • Added get_version_from_multiversion_env() function (initially, later unused)
  • Added _read_version_from_setup() with CWD-based detection (later unused)
  • Note: These are not actively used in final solution but remain for reference

Results

Each version now correctly displays:

v0.0.8-docs:

  • Title: "nvblox_torch 0.0.8"
  • Wheel URL: download/v0.0.8/
  • Wheel filename: nvblox_torch-0.0.8rc5+cu12ubuntu24-py3-none-linux_x86_64.whl

v0.0.9-docs:

  • Title: "nvblox_torch 0.0.9"
  • Wheel URL: download/v0.0.9/
  • Wheel filename: nvblox_torch-0.0.9.dev1+cu12ubuntu24-py3-none-linux_x86_64.whl

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

david-tingdahl-nvidia and others added 5 commits January 28, 2026 17:53
  ## Problem

  When building multi-version documentation with sphinx-multiversion for
  branches v0.0.8-docs and v0.0.9-docs, both versions incorrectly displayed
  "nvblox_torch 0.0.9" in the page titles and all wheel download URLs pointed
  to v0.0.9 files, regardless of which version was being built.

  ## Root Cause

  Multiple interacting issues:

  1. **Python Module Caching**: The original approach imported version from
     setup.py at module level. Python's import system cached the first
     imported module, causing all subsequent builds to reuse the same cached
     version (0.0.9) across all versions.

  2. **Timing Issues**: conf.py is executed before sphinx-multiversion sets
     up version-specific source directories, so CWD-based detection failed.

  3. **Config Dictionary Creation**: The nvblox_torch_docs_config dictionary
     was created at module import time with hardcoded/default version values,
     before the correct version could be detected.

  ## Solution

  Use Sphinx's setup() function which runs after initialization and provides
  app.srcdir pointing to each version's checked-out source directory.

  The setup() function:
  1. Detects the version by reading setup.py from app.srcdir (the correct
     version-specific checkout directory)
  2. Updates app.config.html_title with the correct version
  3. Updates app.config.nvblox_torch_docs_config with version-specific:
     - external_wheel_base_url (e.g., /download/v0.0.8/ vs /download/v0.0.9/)
     - wheel_name_* entries with correct version and patch (rc5 vs .dev1)

  ## Changes

  **docs/conf.py (both v0.0.8-docs and v0.0.9-docs)**:
  - Removed module-level version import from helpers.py/setup.py
  - Set NVBLOX_VERSION_NUMBER to default value (overridden in setup())
  - Added setup(app) function that:
    - Detects version from app.srcdir/nvblox_torch/setup.py
    - Updates html_title dynamically
    - Updates nvblox_torch_docs_config dictionary entries
  - Added get_wheel_name() helper function (v0.0.9-docs)
  - Added _get_wheel_name() nested function (v0.0.8-docs)
  - Changed smv_branch_whitelist from v0.0.8|v0.0.9 to v0.0.8-docs|v0.0.9-docs

  **docs/_templates/versioning.html (v0.0.8-docs)**:
  - Created version selector sidebar template for sphinx-multiversion

  **docs/helpers.py (v0.0.9-docs)**:
  - Added get_version_from_multiversion_env() function (initially, later unused)
  - Added _read_version_from_setup() with CWD-based detection (later unused)
  - Note: These are not actively used in final solution but remain for reference

  ## Results

  Each version now correctly displays:

  **v0.0.8-docs:**
  - Title: "nvblox_torch 0.0.8"
  - Wheel URL: download/v0.0.8/
  - Wheel filename: nvblox_torch-0.0.8rc5+cu12ubuntu24-py3-none-linux_x86_64.whl

  **v0.0.9-docs:**
  - Title: "nvblox_torch 0.0.9"
  - Wheel URL: download/v0.0.9/
  - Wheel filename: nvblox_torch-0.0.9.dev1+cu12ubuntu24-py3-none-linux_x86_64.whl

  Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The global variable is no longer needed. Version detection and config
updates are now handled entirely within the setup() function scope.

Changes:
- Remove NVBLOX_VERSION_NUMBER global variable declaration
- Remove global keyword and assignment in _update_version_config()
- Remove html_title line that referenced the global
- Initialize nvblox_torch_docs_config with empty strings

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@david-tingdahl-nvidia
Copy link
Contributor Author

will try other/cleaner method

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants