|
10 | 10 | # add these directories to sys.path here. If the directory is relative to the
|
11 | 11 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
12 | 12 | import os
|
13 |
| -import sys |
14 |
| -from unittest.mock import MagicMock |
15 |
| - |
16 |
| -from cuda.core.experimental._system import System |
17 | 13 |
|
18 | 14 | # sys.path.insert(0, os.path.abspath('.'))
|
19 | 15 |
|
|
104 | 100 | napoleon_google_docstring = False
|
105 | 101 | napoleon_numpy_docstring = True
|
106 | 102 |
|
107 |
| - |
108 |
| -# Mock the System class and its methods |
109 |
| -class MockSystem: |
110 |
| - def __init__(self, *args, **kwargs): |
111 |
| - pass |
112 |
| - |
113 |
| - driver_version = MagicMock() |
114 |
| - driver_version.__doc__ = System.driver_version.__doc__ |
115 |
| - num_devices = MagicMock() |
116 |
| - num_devices.__doc__ = System.num_devices.__doc__ |
117 |
| - devices = MagicMock() |
118 |
| - devices.__doc__ = System.devices.__doc__ |
119 |
| - |
120 |
| - |
121 |
| -sys.modules["cuda.core.experimental._system.System"] = MagicMock(System=MockSystem) |
122 |
| - |
123 |
| -# Add 'cuda.core.experimental.system' to autodoc_mock_imports |
124 |
| -autodoc_mock_imports = ["cuda.core.experimental.system"] |
125 |
| - |
126 | 103 | section_titles = ["Returns"]
|
127 | 104 |
|
128 | 105 |
|
129 | 106 | def autodoc_process_docstring(app, what, name, obj, options, lines):
|
130 |
| - if name.startswith("cuda.core.experimental.system"): |
| 107 | + if name.startswith("cuda.core.experimental._system.System"): |
| 108 | + name = name.replace("._system.System", ".system") |
131 | 109 | # patch the docstring (in lines) *in-place*. Should docstrings include section titles other than "Returns",
|
132 | 110 | # this will need to be modified to handle them.
|
| 111 | + while lines: |
| 112 | + lines.pop() |
133 | 113 | attr = name.split(".")[-1]
|
134 | 114 | from cuda.core.experimental._system import System
|
135 | 115 |
|
136 |
| - lines_new = getattr(System, attr).__doc__.split("\n") |
137 |
| - formatted_lines = [] |
138 |
| - for line in lines_new: |
| 116 | + original_lines = getattr(System, attr).__doc__.split("\n") |
| 117 | + new_lines = [] |
| 118 | + new_lines.append(f".. py:data:: {name}") |
| 119 | + new_lines.append("") |
| 120 | + for line in original_lines: |
139 | 121 | title = line.strip()
|
140 | 122 | if title in section_titles:
|
141 |
| - formatted_lines.append(line.replace(title, f".. rubric:: {title}")) |
| 123 | + new_lines.append(line.replace(title, f".. rubric:: {title}")) |
142 | 124 | elif line.strip() == "-" * len(title):
|
143 |
| - formatted_lines.append(" " * len(title)) |
| 125 | + new_lines.append(" " * len(title)) |
144 | 126 | else:
|
145 |
| - formatted_lines.append(line) |
146 |
| - n_pops = len(lines) |
147 |
| - lines.extend(formatted_lines) |
148 |
| - for _ in range(n_pops): |
149 |
| - lines.pop(0) |
| 127 | + new_lines.append(line) |
| 128 | + lines.extend(new_lines) |
150 | 129 |
|
151 | 130 |
|
152 | 131 | def setup(app):
|
|
0 commit comments