diff --git a/cuda_python/docs/source/conf.py b/cuda_python/docs/source/conf.py index f7b447f9dac6..ea436569bb5c 100644 --- a/cuda_python/docs/source/conf.py +++ b/cuda_python/docs/source/conf.py @@ -103,8 +103,27 @@ def _html_baseurl(): # - https://stackoverflow.com/a/61694897/2344149 # - https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-rst_epilog CUDA_PYTHON_DOMAIN = os.environ.get("CUDA_PYTHON_DOMAIN", "https://nvidia.github.io/cuda-python") +_build_release_docs = os.environ.get("IS_RELEASE") == "true" +_bindings_docs_path = f"{release}/" if _build_release_docs else "latest" +_bindings_docs_url = f"{CUDA_PYTHON_DOMAIN}/cuda-bindings/{_bindings_docs_path}" + rst_epilog = f""" .. _cuda.core: {CUDA_PYTHON_DOMAIN}/cuda-core/latest -.. _cuda.bindings: {CUDA_PYTHON_DOMAIN}/cuda-bindings/latest +.. _cuda.bindings: {_bindings_docs_url} .. _cuda.pathfinder: {CUDA_PYTHON_DOMAIN}/cuda-pathfinder/latest """ + + +def _pin_bindings_toctree(_app, docname, source): + if docname != "index": + return + + entry = " cuda.bindings " + if entry not in source[0]: + raise ValueError("Expected the cuda.bindings toctree entry in index.rst") + source[0] = source[0].replace(entry, f" cuda.bindings <{_bindings_docs_url}>", 1) + + +def setup(app): + if _build_release_docs: + app.connect("source-read", _pin_bindings_toctree) diff --git a/cuda_python/docs/source/index.rst b/cuda_python/docs/source/index.rst index 199758f0cf8f..b3a0a6b91d4e 100644 --- a/cuda_python/docs/source/index.rst +++ b/cuda_python/docs/source/index.rst @@ -39,8 +39,8 @@ All of the previously available functionality from the ``cuda-python`` package w be available, please refer to the `cuda.bindings`_ documentation for installation guide and further detail. .. - The urls above can be auto-inserted by Sphinx (see rst_epilog in conf.py), but - not for the urls below, which must be hard-coded due to Sphinx limitation... + In release builds, conf.py replaces the cuda.bindings toctree URL below + with the matching versioned URL used by the inline link. .. toctree:: :maxdepth: 2