-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathconf.py
More file actions
155 lines (122 loc) · 5.24 KB
/
Copy pathconf.py
File metadata and controls
155 lines (122 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# SPDX-FileCopyrightText: Copyright (c) 2012-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
import os
import sys
from pathlib import Path
sys.path.insert(0, str((Path(__file__).parents[3] / "cuda_python" / "docs" / "exts").absolute()))
# -- Project information -----------------------------------------------------
project = "cuda.bindings"
copyright = "2021-2025, NVIDIA"
author = "NVIDIA"
# The full version, including alpha/beta/rc tags
release = os.environ["SPHINX_CUDA_BINDINGS_VER"]
def _github_examples_ref():
if ref := os.environ.get("CUDA_PYTHON_DOCS_GITHUB_REF"):
return ref
if int(os.environ.get("BUILD_PREVIEW", 0)) or int(os.environ.get("BUILD_LATEST", 0)):
return "main"
return f"v{release}"
GITHUB_EXAMPLES_REF = _github_examples_ref()
def _html_baseurl():
docs_domain = os.environ.get("CUDA_PYTHON_DOCS_DOMAIN", "https://nvidia.github.io/cuda-python")
if int(os.environ.get("BUILD_PREVIEW", 0)):
return f"{docs_domain}/pr-preview/pr-{os.environ['PR_NUMBER']}/cuda-bindings/latest/"
if int(os.environ.get("BUILD_LATEST", 0)):
return f"{docs_domain}/cuda-bindings/latest/"
return f"{docs_domain}/cuda-bindings/{release}/"
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.extlinks",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"myst_nb",
"sphinx_copybutton",
"release_toc",
"release_date",
"enum_documenter",
]
nb_execution_mode = "off"
numfig = True
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# Include object entries (methods, attributes, etc.) in the table of contents
# This enables the "On This Page" sidebar to show class methods and properties
# Requires Sphinx 5.1+
toc_object_entries = True
toc_object_entries_show_parents = "domain"
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_baseurl = _html_baseurl()
html_theme = "nvidia_sphinx_theme"
html_theme_options = {
"switcher": {
"json_url": "https://nvidia.github.io/cuda-python/cuda-bindings/nv-versions.json",
"version_match": release,
},
# Add light/dark mode and documentation version switcher
"navbar_center": [
"version-switcher",
"navbar-nav",
],
# Use custom secondary sidebar that includes autodoc entries
"secondary_sidebar_items": ["page-toc"],
# Show more TOC levels by default
"show_toc_level": 3,
}
if os.environ.get("CI"):
if int(os.environ.get("BUILD_PREVIEW", 0)):
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
html_theme_options["announcement"] = f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"
elif int(os.environ.get("BUILD_LATEST", 0)):
html_theme_options["announcement"] = (
"<em>Warning</em>: This documentation is built from the development branch!"
)
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = [] # ["_static"] does not exist in our environment
# skip cmdline prompts
copybutton_exclude = ".linenos, .gp"
extlinks = {
"cuda-bindings-example": (
f"https://github.com/NVIDIA/cuda-python/blob/{GITHUB_EXAMPLES_REF}/cuda_bindings/examples/%s",
"%s",
),
"cuda-bindings-examples": (
f"https://github.com/NVIDIA/cuda-python/tree/{GITHUB_EXAMPLES_REF}/cuda_bindings/examples%s",
"%s",
),
}
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"nvvm": ("https://docs.nvidia.com/cuda/libnvvm-api/", None),
"nvjitlink": ("https://docs.nvidia.com/cuda/nvjitlink/", None),
"cufile": ("https://docs.nvidia.com/gpudirect-storage/api-reference-guide/", None),
}
def rewrite_source(app, docname, source):
if docname.startswith("release/"):
source[0] = source[0].replace(".. module:: cuda.bindings\n\n", "", 1)
suppress_warnings = [
# for warnings about multiple possible targets, see NVIDIA/cuda-python#152
"ref.python",
]
def setup(app):
app.connect("source-read", rewrite_source)