forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.py
214 lines (169 loc) · 7.7 KB
/
conf.py
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# This code is part of Qiskit.
#
# (C) Copyright IBM 2018.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
from __future__ import annotations
# pylint: disable=invalid-name,missing-function-docstring
"""Sphinx documentation builder."""
import datetime
import doctest
import importlib
import inspect
import os
import re
from pathlib import Path
project = "Qiskit"
project_copyright = f"2017-{datetime.date.today().year}, Qiskit Development Team"
author = "Qiskit Development Team"
# The short X.Y version
version = "1.1"
# The full version, including alpha/beta/rc tags
release = "1.1.0"
language = "en"
rst_prolog = f".. |version| replace:: {version}"
extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.doctest",
# This is used by qiskit/documentation to generate links to github.com.
"sphinx.ext.linkcode",
"matplotlib.sphinxext.plot_directive",
"reno.sphinxext",
"sphinxcontrib.katex",
]
templates_path = ["_templates"]
# Number figures, tables and code-blocks if they have a caption.
numfig = True
# Available keys are 'figure', 'table', 'code-block' and 'section'. '%s' is the number.
numfig_format = {"table": "Table %s"}
# Relative to source directory, affects general discovery, and html_static_path and html_extra_path.
exclude_patterns = ["_build", "**.ipynb_checkpoints"]
# This adds the module name to e.g. function API docs. We use the default of True because our
# module pages sometimes have functions from submodules on the page, and we want to make clear
# that you must include the submodule to import it. We should strongly consider reorganizing our
# code to avoid this, i.e. re-exporting the submodule members from the top-level module. Once fixed
# and verified by only having a single `.. currentmodule::` in the file, we can turn this back to
# False.
add_module_names = True
# A list of prefixes that are ignored for sorting the Python module index
# (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F).
modindex_common_prefix = ["qiskit."]
# ----------------------------------------------------------------------------------
# Intersphinx
# ----------------------------------------------------------------------------------
intersphinx_mapping = {
"rustworkx": ("https://www.rustworkx.org/", None),
"qiskit-ibm-runtime": ("https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/", None),
"qiskit-aer": ("https://qiskit.github.io/qiskit-aer/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"python": ("https://docs.python.org/3/", None),
}
# ----------------------------------------------------------------------------------
# HTML theme
# ----------------------------------------------------------------------------------
html_theme = "alabaster"
html_last_updated_fmt = "%Y/%m/%d"
# ----------------------------------------------------------------------------------
# Autodoc
# ----------------------------------------------------------------------------------
# Note that setting autodoc defaults here may not have as much of an effect as you may expect; any
# documentation created by autosummary uses a template file (in autosummary in the templates path),
# which likely overrides the autodoc defaults.
# Move type hints from signatures to the parameter descriptions (except in overload cases, where
# that's not possible).
autodoc_typehints = "description"
# Only add type hints from signature to description body if the parameter has documentation. The
# return type is always added to the description (if in the signature).
autodoc_typehints_description_target = "documented_params"
autoclass_content = "both"
autosummary_generate = True
autosummary_generate_overwrite = False
# The pulse library contains some names that differ only in capitalisation, during the changeover
# surrounding SymbolPulse. Since these resolve to autosummary filenames that also differ only in
# capitalisation, this causes problems when the documentation is built on an OS/filesystem that is
# enforcing case-insensitive semantics. This setting defines some custom names to prevent the clash
# from happening.
autosummary_filename_map = {
"qiskit.pulse.library.Constant": "qiskit.pulse.library.Constant_class.rst",
"qiskit.pulse.library.Sawtooth": "qiskit.pulse.library.Sawtooth_class.rst",
"qiskit.pulse.library.Triangle": "qiskit.pulse.library.Triangle_class.rst",
"qiskit.pulse.library.Cos": "qiskit.pulse.library.Cos_class.rst",
"qiskit.pulse.library.Sin": "qiskit.pulse.library.Sin_class.rst",
"qiskit.pulse.library.Gaussian": "qiskit.pulse.library.Gaussian_class.rst",
"qiskit.pulse.library.Drag": "qiskit.pulse.library.Drag_class.rst",
"qiskit.pulse.library.Square": "qiskit.pulse.library.Square_fun.rst",
"qiskit.pulse.library.Sech": "qiskit.pulse.library.Sech_fun.rst",
}
# We only use Google-style docstrings, and allowing Napoleon to parse Numpy-style docstrings both
# slows down the build (a little) and can sometimes result in _regular_ section headings in
# module-level documentation being converted into surprising things.
napoleon_google_docstring = True
napoleon_numpy_docstring = False
# ----------------------------------------------------------------------------------
# Doctest
# ----------------------------------------------------------------------------------
doctest_default_flags = (
doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
| doctest.IGNORE_EXCEPTION_DETAIL
| doctest.DONT_ACCEPT_TRUE_FOR_1
)
# Leaving this string empty disables testing of doctest blocks from docstrings.
# Doctest blocks are structures like this one:
# >> code
# output
doctest_test_doctest_blocks = ""
# ----------------------------------------------------------------------------------
# Plot directive
# ----------------------------------------------------------------------------------
plot_html_show_formats = False
# ----------------------------------------------------------------------------------
# Source code links
# ----------------------------------------------------------------------------------
REPO_ROOT = Path(__file__).resolve().parents[1]
def linkcode_resolve(domain, info):
if domain != "py":
return None
module_name = info["module"]
if "qiskit" not in module_name:
return None
try:
module = importlib.import_module(module_name)
except ModuleNotFoundError:
return None
obj = module
for part in info["fullname"].split("."):
try:
obj = getattr(obj, part)
except AttributeError:
return None
try:
full_file_name = inspect.getsourcefile(obj)
except TypeError:
return None
if full_file_name is None:
return None
try:
relative_file_name = Path(full_file_name).resolve().relative_to(REPO_ROOT)
file_name = re.sub(r"\.tox\/.+\/site-packages\/", "", str(relative_file_name))
except ValueError:
return None
try:
source, lineno = inspect.getsourcelines(obj)
except (OSError, TypeError):
linespec = ""
else:
ending_lineno = lineno + len(source) - 1
linespec = f"#L{lineno}-L{ending_lineno}"
github_branch = os.environ.get("QISKIT_DOCS_GITHUB_BRANCH_NAME", "main")
return f"https://github.com/Qiskit/qiskit/tree/{github_branch}/{file_name}{linespec}"