Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 98 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,71 @@
import os
import sys

# Modify PYTHONPATH so we can obtain the version data from setup module.
# pylint: disable=wrong-import-position
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'nvblox_torch')))
from setup import NVBLOX_VERSION_NUMBER

# Modify PYTHONPATH so we can import the helpers module.
# Define setup() function to properly detect version after Sphinx initializes
# pylint: disable=import-outside-toplevel,broad-exception-caught
def setup(app: object) -> None:
"""Sphinx setup function to detect version from sphinx-multiversion context.

This function runs after Sphinx initializes and has access to app.srcdir,
which points to the correct source directory for each version being built.
"""
import re
import subprocess

def _update_version_config(version: str) -> None:
"""Update version-dependent wheel URLs and names in config."""
app.config.nvblox_torch_docs_config['external_wheel_base_url'] = \
f'https://github.com/nvidia-isaac/nvblox/releases/download/v{version}'
app.config.nvblox_torch_docs_config['wheel_name_ubuntu_24_cuda_12'] = \
get_wheel_name(version, '24', '12')
app.config.nvblox_torch_docs_config['wheel_name_ubuntu_22_cuda_12'] = \
get_wheel_name(version, '22', '12')
app.config.nvblox_torch_docs_config['wheel_name_ubuntu_22_cuda_11'] = \
get_wheel_name(version, '22', '11')
app.config.nvblox_torch_docs_config['wheel_name_ubuntu_24_cuda_13'] = \
get_wheel_name(version, '24', '13')

# Try to get version from various sources
# 1. Check environment variable (sphinx-multiversion should set this)
smv_current_version = os.environ.get('SPHINX_MULTIVERSION_NAME')
if smv_current_version:
match = re.match(r'v?(\d+\.\d+\.\d+)', smv_current_version)
if match:
_update_version_config(match.group(1))
return

# 2. Try git in the source directory
try:
result = subprocess.run(['git', 'describe', '--all', '--exact-match', 'HEAD'],
capture_output=True,
text=True,
cwd=app.srcdir,
check=False)
if result.returncode == 0:
ref_name = result.stdout.strip()
match = re.search(r'v?(\d+\.\d+\.\d+)', ref_name)
if match:
_update_version_config(match.group(1))
return
except Exception:
pass # Git detection failed, continue to fallback

# 3. Fallback: read from setup.py in the source directory
# This is the most reliable method for sphinx-multiversion builds
setup_path = os.path.join(app.srcdir, '..', 'nvblox_torch', 'setup.py')
try:
with open(setup_path, 'r', encoding='utf-8') as f:
content = f.read()
match = re.search(r"NVBLOX_VERSION_NUMBER\s*=\s*['\"]([^'\"]+)['\"]", content)
if match:
_update_version_config(match.group(1))
except Exception:
pass # Use default version


# Modify PYTHONPATH so we can import the helpers module (for linkcheck only).
# pylint: disable=wrong-import-position
sys.path.insert(0, os.path.abspath('.'))
from helpers import TemporaryLinkcheckIgnore, to_datetime, is_expired

Expand Down Expand Up @@ -89,7 +148,6 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'nvidia_sphinx_theme'
html_title = f'nvblox_torch {NVBLOX_VERSION_NUMBER}'
html_show_sphinx = False
html_theme_options = {
'copyright_override': {
Expand Down Expand Up @@ -118,7 +176,7 @@

# Versioning (sphinx-multiversion)
smv_remote_whitelist = r'^.*$'
smv_branch_whitelist = r'^(public|v0.0.8|v0.0.9)$'
smv_branch_whitelist = r'^(public|v0.0.8-docs|v0.0.9)$'
smv_tag_whitelist = r'^(v0.0.8|v0.0.9)$'
html_sidebars = {'**': ['versioning.html', 'sidebar-nav-bs']}

Expand Down Expand Up @@ -156,20 +214,43 @@
# Macros dependent on release state
#####################################


def get_wheel_name(version: str, ubuntu: str, cuda: str) -> str:
"""Generate wheel filename based on version.

Args:
version: Version like "0.0.8" or "0.0.9"
ubuntu: Ubuntu version like "24" or "22"
cuda: CUDA version like "12" or "11" or "13"

Returns:
Wheel filename like "nvblox_torch-0.0.9.dev1+cu12ubuntu24-py3-none-linux_x86_64.whl"
"""
# Some versions have a patch or build number in their name
version_patches = {
'0.0.8': 'rc5',
}
build_numbers = {
'0.0.8': '863-',
}

patch = version_patches.get(version, '')
build = build_numbers.get(version, '')

return f'nvblox_torch-{version}{patch}+cu{cuda}ubuntu{ubuntu}-{build}py3-none-linux_x86_64.whl'


nvblox_torch_docs_config = {
'released': released,
'internal_wheel_base_url': 'https://urm.nvidia.com/artifactory/hw-nvblox-alpine-local/' + \
'pypi/release/nvblox_torch/',
'external_wheel_base_url': 'https://github.com/nvidia-isaac/nvblox/releases' + \
f'/download/v{NVBLOX_VERSION_NUMBER}',
'wheel_name_ubuntu_24_cuda_12': \
'nvblox_torch-0.0.9.dev1+cu12ubuntu24-py3-none-linux_x86_64.whl',
'wheel_name_ubuntu_22_cuda_12': \
'nvblox_torch-0.0.9.dev1+cu12ubuntu22-py3-none-linux_x86_64.whl',
'wheel_name_ubuntu_22_cuda_11': \
'nvblox_torch-0.0.9.dev1+cu11ubuntu22-py3-none-linux_x86_64.whl',
'wheel_name_ubuntu_24_cuda_13': \
'nvblox_torch-0.0.9.dev1+cu13ubuntu24-py3-none-linux_x86_64.whl',
# Note: external_wheel_base_url and wheel_name_* are updated by setup() function
# with version-specific values from each branch's setup.py file
'external_wheel_base_url': '',
'wheel_name_ubuntu_24_cuda_12': '',
'wheel_name_ubuntu_22_cuda_12': '',
'wheel_name_ubuntu_22_cuda_11': '',
'wheel_name_ubuntu_24_cuda_13': '',
'internal_git_url': 'ssh://[email protected]:12051/nvblox/nvblox.git',
'external_git_url': '[email protected]:nvidia-isaac/nvblox.git',
'internal_code_link_base_url': 'https://gitlab-master.nvidia.com/nvblox/nvblox/-/tree/main',
Expand Down
72 changes: 72 additions & 0 deletions docs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#
import dataclasses
import datetime
import os
import re


def to_datetime(date_str: str) -> datetime.datetime:
Expand All @@ -27,3 +29,73 @@ class TemporaryLinkcheckIgnore:
url: str
start_date: datetime.datetime
days: int


def get_version_from_multiversion_env() -> str:
"""Get version number from sphinx-multiversion environment.

When building with sphinx-multiversion, extract version from
SPHINX_MULTIVERSION_NAME environment variable or from the checked-out
branch's setup.py file (e.g., "v0.0.8" -> "0.0.8").

Falls back to reading from setup.py for local single-version builds.

Returns:
Version string like "0.0.8" or "0.0.9"
"""
# Check if running under sphinx-multiversion
smv_name = os.environ.get('SPHINX_MULTIVERSION_NAME')

# Debug output
print(f'[VERSION DEBUG] SPHINX_MULTIVERSION_NAME = {smv_name}')
print(f'[VERSION DEBUG] Current directory: {os.getcwd()}')
print(f'[VERSION DEBUG] __file__ location: {os.path.abspath(__file__)}')

if smv_name:
# Parse version from branch/tag name
# Handles: "v0.0.8-docs", "v0.0.9-docs", with or without 'v' prefix
match = re.match(r'v?(\d+\.\d+\.\d+)', smv_name)
if match:
version = match.group(1)
print(f'[VERSION DEBUG] Extracted version from env: {version}')
return version

# For "public" branch, read from current setup.py
if smv_name == 'public':
version = _read_version_from_setup()
print(f'[VERSION DEBUG] Public branch, read from setup.py: {version}')
return version

# Fallback: read from setup.py in the current working directory
# When sphinx-multiversion builds, it checks out each version to a temp dir,
# so we should read from THAT version's setup.py
version = _read_version_from_setup()
print(f'[VERSION DEBUG] Reading from setup.py: {version}')
return version


def _read_version_from_setup() -> str:
"""Read version from setup.py by parsing file content.

This avoids Python import caching issues.

Uses current working directory instead of __file__ location because
sphinx-multiversion changes CWD to the checked-out version's directory,
but __file__ still points to the original file location.
"""
# Use current working directory (which sphinx-multiversion sets correctly)
setup_path = os.path.join(os.getcwd(), '..', 'nvblox_torch', 'setup.py')
setup_path = os.path.abspath(setup_path)

print(f'[VERSION DEBUG] Reading version from: {setup_path}')

with open(setup_path, 'r', encoding='utf-8') as f:
content = f.read()

match = re.search(r"NVBLOX_VERSION_NUMBER\s*=\s*['\"]([^'\"]+)['\"]", content)
if match:
version = match.group(1)
print(f'[VERSION DEBUG] Found version in setup.py: {version}')
return version

raise ValueError(f'Could not find NVBLOX_VERSION_NUMBER in {setup_path}')
Loading