Skip to content
129 changes: 98 additions & 31 deletions docs/_ext/nvblox_torch_doc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,52 @@

from sphinx.application import Sphinx

UNKNOWN_VERSION = 'unknown'

WHEEL_BASE_URL = 'https://github.com/nvidia-isaac/nvblox/releases/download'


def get_wheel_url_0_0_8(cuda_version: str, ubuntu_version: str) -> str:
"""Get the wheel URL for version 0.0.8.

It is a special case because it has build number in the wheel filename.
"""
# pylint: disable=line-too-long
return f'{WHEEL_BASE_URL}/v0.0.8/nvblox_torch-0.0.8rc5+cu{cuda_version}ubuntu{ubuntu_version}-863-py3-none-linux_x86_64.whl'


def get_wheel_url_general(version: str, cuda_version: str, ubuntu_version: str) -> str:
"""Get the wheel URL for a given version, CUDA version, and Ubuntu version.
"""
# pylint: disable=line-too-long
return f'{WHEEL_BASE_URL}/v{version}/nvblox_torch-{version}+cu{cuda_version}ubuntu{ubuntu_version}-py3-none-linux_x86_64.whl'


def get_wheel_url(version: str, cuda_version: str, ubuntu_version: str) -> str:
"""Get the wheel URL for a given version, CUDA version, and Ubuntu version.
"""
if version == '0.0.8':
return get_wheel_url_0_0_8(cuda_version, ubuntu_version)
else:
return get_wheel_url_general(version, cuda_version, ubuntu_version)


def get_smv_version_number(app: Sphinx) -> str:
"""Get the version number from the sphinx-multiversion current version.

"""
smv_current_version = getattr(app.config, 'smv_current_version', None)
if smv_current_version is None:
return UNKNOWN_VERSION

# Extract 0.0.9 from branch name like v0.0.9-docs_test
match = re.search(r'v(\d+\.\d+\.\d+)', smv_current_version)
if not match:
return UNKNOWN_VERSION
version = match.group(1)

return version


def nvblox_torch_pip_install_code_block(app: Sphinx, _: Any, source: List[str]) -> None:
"""Replaces the :nvblox_torch_pip_install_code_block: directive with a code block.
Expand All @@ -23,36 +69,25 @@ def nvblox_torch_pip_install_code_block(app: Sphinx, _: Any, source: List[str])
"""

def replacer(_: Any) -> str:
release_state = app.config.nvblox_torch_docs_config['released']
internal_wheel_base_url = app.config.nvblox_torch_docs_config['internal_wheel_base_url']
external_wheel_base_url = app.config.nvblox_torch_docs_config['external_wheel_base_url']
wheel_name_ubuntu_24_cuda_12 = app.config.nvblox_torch_docs_config[
'wheel_name_ubuntu_24_cuda_12']
wheel_name_ubuntu_22_cuda_12 = app.config.nvblox_torch_docs_config[
'wheel_name_ubuntu_22_cuda_12']
wheel_name_ubuntu_22_cuda_11 = app.config.nvblox_torch_docs_config[
'wheel_name_ubuntu_22_cuda_11']
wheel_name_ubuntu_24_cuda_13 = app.config.nvblox_torch_docs_config[
'wheel_name_ubuntu_24_cuda_13']
if release_state:
pip_install_target_ubuntu_24_cuda_12 = \
f'{external_wheel_base_url}/{wheel_name_ubuntu_24_cuda_12}'
pip_install_target_ubuntu_22_cuda_12 = \
f'{external_wheel_base_url}/{wheel_name_ubuntu_22_cuda_12}'
pip_install_target_ubuntu_22_cuda_11 = \
f'{external_wheel_base_url}/{wheel_name_ubuntu_22_cuda_11}'
pip_install_target_ubuntu_24_cuda_13 = \
f'{external_wheel_base_url}/{wheel_name_ubuntu_24_cuda_13}'
else:
pip_install_target_ubuntu_24_cuda_12 = \
f'{internal_wheel_base_url}/{wheel_name_ubuntu_24_cuda_12}'
pip_install_target_ubuntu_22_cuda_12 = \
f'{internal_wheel_base_url}/{wheel_name_ubuntu_22_cuda_12}'
pip_install_target_ubuntu_22_cuda_11 = \
f'{internal_wheel_base_url}/{wheel_name_ubuntu_22_cuda_11}'
pip_install_target_ubuntu_24_cuda_13 = \
f'{internal_wheel_base_url}/{wheel_name_ubuntu_24_cuda_13}'
return f"""

version = get_smv_version_number(app)

wheel_name_ubuntu_24_cuda_12 = get_wheel_url(version, '12', '24')
wheel_name_ubuntu_22_cuda_12 = get_wheel_url(version, '12', '22')
wheel_name_ubuntu_22_cuda_11 = get_wheel_url(version, '11', '22')
wheel_name_ubuntu_24_cuda_13 = get_wheel_url(version, '13', '24')


pip_install_target_ubuntu_24_cuda_12 = \
f'{wheel_name_ubuntu_24_cuda_12}'
pip_install_target_ubuntu_22_cuda_12 = \
f'{wheel_name_ubuntu_22_cuda_12}'
pip_install_target_ubuntu_22_cuda_11 = \
f'{wheel_name_ubuntu_22_cuda_11}'
pip_install_target_ubuntu_24_cuda_13 = \
f'{wheel_name_ubuntu_24_cuda_13}'

rst_string = f"""

To install ``nvblox_torch`` via ``pip`` on a supported platform, run the following commands:

Expand All @@ -77,7 +112,11 @@ def replacer(_: Any) -> str:

sudo apt-get install python3-pip libglib2.0-0 libgl1 # Open3D dependencies
pip3 install {pip_install_target_ubuntu_22_cuda_11}

"""
# Only add the CUDA 13.0 tab if the version is not 0.0.8.
# TODO(dtingdahl) handle this in a more elegant way to support future releases.
if version != '0.0.8':
rst_string += f"""
.. tab:: Ubuntu 24.04 + CUDA 13.0

.. code-block:: bash
Expand All @@ -87,6 +126,7 @@ def replacer(_: Any) -> str:
pip3 install {pip_install_target_ubuntu_24_cuda_13}

"""
return rst_string

source[0] = re.sub(r':nvblox_torch_pip_install_code_block:', replacer, source[0])

Expand Down Expand Up @@ -162,9 +202,36 @@ def replacer(match: re.Match) -> str:
source[0] = re.sub(r':nvblox_code_link:`<(?P<relative_path>.*)>`', replacer, source[0])


def current_version_name(app: Sphinx, _: Any, source: List[str]) -> None:
"""Replaces the :current_version_name: directive with the current version name.

This uses the sphinx-multiversion context if available, otherwise falls back
to the Sphinx version config value.

Usage in RST:
Current Version: :current_version_name:

"""

def replacer(_: Any) -> str:
# Try to get the version from sphinx-multiversion's environment
# When sphinx-multiversion builds, it sets the 'smv_current_version' in the environment
smv_current_version = getattr(app.config, 'smv_current_version', None)
if smv_current_version:

# Extract version number from string containing v0.0.9
version = get_smv_version_number(app)
return version
else:
raise ValueError('Failed to get current version name. Build with make multi-doc.')

source[0] = re.sub(r':current_version_name:', replacer, source[0])


def setup(app: Sphinx) -> None:
app.connect('source-read', nvblox_torch_pip_install_code_block)
app.connect('source-read', nvblox_torch_git_clone_code_block)
app.connect('source-read', nvblox_code_link)
app.connect('source-read', download_test_dataset)
app.connect('source-read', current_version_name)
app.add_config_value('nvblox_torch_docs_config', {}, 'env')
20 changes: 2 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
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.
# 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 +85,7 @@
# 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_title = 'nvblox'
html_show_sphinx = False
html_theme_options = {
'copyright_override': {
Expand Down Expand Up @@ -158,18 +154,6 @@

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',
'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
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Depending on your use-case, you may interact with ``nvblox`` through either Pyth
Quickstart
==========

Current Version: :current_version_name:

:nvblox_torch_pip_install_code_block:

Expand Down
Loading