|
9 | 9 |
|
10 | 10 | # -- Path setup -------------------------------------------------------------- |
11 | 11 |
|
| 12 | +import inspect |
12 | 13 | import os |
13 | 14 | import sys |
14 | 15 | from pathlib import Path |
|
94 | 95 | # Add any paths that contain custom static files (such as style sheets) here, |
95 | 96 | # relative to this directory. They are copied after the builtin static files, |
96 | 97 | # so a file named "default.css" will overwrite the builtin "default.css". |
97 | | -html_static_path = ["_static"] |
| 98 | +html_static_path = [] # ["_static"] does not exist in our environment |
98 | 99 |
|
99 | 100 | # skip cmdline prompts |
100 | 101 | copybutton_exclude = ".linenos, .gp" |
|
107 | 108 | "cufile": ("https://docs.nvidia.com/gpudirect-storage/api-reference-guide/", None), |
108 | 109 | } |
109 | 110 |
|
| 111 | +def _sanitize_generated_docstring(lines): |
| 112 | + doc_lines = inspect.cleandoc("\n".join(lines)).splitlines() |
| 113 | + if not doc_lines: |
| 114 | + return |
| 115 | + |
| 116 | + if "(" in doc_lines[0] and ")" in doc_lines[0]: |
| 117 | + doc_lines = doc_lines[1:] |
| 118 | + while doc_lines and not doc_lines[0].strip(): |
| 119 | + doc_lines.pop(0) |
| 120 | + |
| 121 | + if not doc_lines: |
| 122 | + lines[:] = [] |
| 123 | + return |
| 124 | + |
| 125 | + lines[:] = [".. code-block:: text", ""] |
| 126 | + lines.extend(f" {line}" if line else " " for line in doc_lines) |
| 127 | + |
| 128 | + |
| 129 | +def autodoc_process_docstring(app, what, name, obj, options, lines): |
| 130 | + if name.startswith("cuda.bindings."): |
| 131 | + _sanitize_generated_docstring(lines) |
| 132 | + |
| 133 | + |
| 134 | +def rewrite_source(app, docname, source): |
| 135 | + text = source[0] |
| 136 | + |
| 137 | + if docname.startswith("release/"): |
| 138 | + text = text.replace(".. module:: cuda.bindings\n\n", "", 1) |
| 139 | + |
| 140 | + source[0] = text |
| 141 | + |
110 | 142 | suppress_warnings = [ |
111 | 143 | # for warnings about multiple possible targets, see NVIDIA/cuda-python#152 |
112 | 144 | "ref.python", |
113 | 145 | ] |
| 146 | + |
| 147 | + |
| 148 | +def setup(app): |
| 149 | + app.connect("autodoc-process-docstring", autodoc_process_docstring) |
| 150 | + app.connect("source-read", rewrite_source) |
0 commit comments