Debian Codegraph @

doc/en/conf.py

raw ◀ ▶
3 Debian patches touch this file
1 from __future__ import annotations
2
3 import os
4 from pathlib import Path
5 import shutil
6 from textwrap import dedent
7 from typing import TYPE_CHECKING
8
9 from pytest import __version__ as full_version
10
11
12 if TYPE_CHECKING:
13 import sphinx.application
14
15 PROJECT_ROOT_DIR = Path(__file__).parents[2].resolve()
16
17 # -- Project information ---------------------------------------------------------------
18 # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
19
20 project = "pytest"
21 copyright = "2015, holger krekel and pytest-dev team"
22 version = full_version.split("+")[0]
23 release = ".".join(version.split(".")[:2])
24
25 # -- General configuration -------------------------------------------------------------
26 # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
27
28 root_doc = "index"
29 extensions = [
30 "sphinx.ext.autodoc",
31 "sphinx.ext.autosummary",
32 "sphinx.ext.intersphinx",
33 "sphinx.ext.todo",
34 "sphinx.ext.viewcode",
35 "sphinx_inline_tabs",
36 "sphinxcontrib.towncrier.ext", # provides `towncrier-draft-entries` directive
37 "sphinx_issues", # implements `:issue:`, `:pr:` and other GH-related roles
38 ]
39
40 # Building PDF docs on readthedocs requires inkscape for svg to pdf
41 # conversion. The relevant plugin is not useful for normal HTML builds, but
42 # it still raises warnings and fails CI if inkscape is not available. So
43 # only use the plugin if inkscape is actually available.
44 if shutil.which("inkscape"):
45 extensions.append("sphinxcontrib.inkscapeconverter")
46
47 exclude_patterns = [
48 "_build",
49 "naming20.rst",
50 "test/*",
51 "old_*",
52 "*attic*",
53 "*/attic*",
54 "funcargs.rst",
55 "setup.rst",
56 "example/remoteinterp.rst",
57 ]
58 templates_path = ["_templates"]
59 default_role = "literal"
60
61 nitpicky = True
62 nitpick_ignore = [
63 # TODO (fix in pluggy?)
64 ("py:class", "HookCaller"),
65 ("py:class", "HookspecMarker"),
66 ("py:exc", "PluginValidationError"),
67 # Might want to expose/TODO (https://github.com/pytest-dev/pytest/issues/7469)
68 ("py:class", "ExceptionRepr"),
69 ("py:class", "Exit"),
70 ("py:class", "SubRequest"),
71 ("py:class", "SubRequest"),
72 ("py:class", "TerminalReporter"),
73 ("py:class", "_pytest._code.code.TerminalRepr"),
74 ("py:class", "TerminalRepr"),
75 ("py:class", "_pytest.fixtures.FixtureFunctionMarker"),
76 ("py:class", "_pytest.fixtures.FixtureFunctionDefinition"),
77 ("py:class", "_pytest.logging.LogCaptureHandler"),
78 ("py:class", "_pytest.mark.structures.ParameterSet"),
79 # Intentionally undocumented/private
80 ("py:class", "_pytest._code.code.Traceback"),
81 ("py:class", "_pytest._py.path.LocalPath"),
82 ("py:class", "_pytest.capture.CaptureResult"),
83 ("py:class", "_pytest.compat.NotSetType"),
84 ("py:class", "_pytest.python.PyCollector"),
85 ("py:class", "_pytest.python.PyobjMixin"),
86 ("py:class", "_pytest.python_api.RaisesContext"),
87 ("py:class", "_pytest.recwarn.WarningsChecker"),
88 ("py:class", "_pytest.reports.BaseReport"),
89 # Sphinx bugs(?)
90 ("py:class", "RewriteHook"),
91 # Undocumented third parties
92 ("py:class", "_tracing.TagTracerSub"),
93 ("py:class", "warnings.WarningMessage"),
94 # Python 3.14+ exposes the C accelerator module name.
95 ("py:class", "_py_warnings.WarningMessage"),
96 # Undocumented type aliases
97 ("py:class", "LEGACY_PATH"),
98 ("py:class", "_PluggyPlugin"),
99 # TypeVars
100 ("py:class", "_pytest._code.code.E"),
101 ("py:class", "E"), # due to delayed annotation
102 ("py:class", "T"),
103 ("py:class", "P"),
104 ("py:class", "P.args"),
105 ("py:class", "P.kwargs"),
106 ("py:class", "_pytest.fixtures.FixtureFunction"),
107 ("py:class", "_pytest.nodes._NodeType"),
108 ("py:class", "_NodeType"), # due to delayed annotation
109 ("py:class", "_pytest.python_api.E"),
110 ("py:class", "_pytest.recwarn.T"),
111 ("py:class", "_pytest.runner.TResult"),
112 ("py:obj", "_pytest.fixtures.FixtureValue"),
113 ("py:obj", "_pytest.stash.T"),
114 ("py:class", "ScopeName"),
115 ("py:class", "BaseExcT_1"),
116 ("py:class", "ExcT_1"),
117 # Deprecated, intentionally not added to reference docs.
118 ("py:func", "pytest.console_main"),
119 ]
120
121 add_module_names = False
122
123 # -- Options for Autodoc --------------------------------------------------------------
124 # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration
125
126 autodoc_member_order = "bysource"
127 autodoc_typehints = "description"
128 autodoc_typehints_description_target = "documented"
129
130 # -- Options for intersphinx ----------------------------------------------------------
131 # https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration
132
•133 def use_if_available(path):
134 return path if os.path.isfile(path) else None
135
136 intersphinx_mapping = {
•137 "pluggy": ("https://pluggy.readthedocs.io/en/stable", use_if_available("/usr/share/doc/python-pluggy/html/objects.inv")),
138 "python": ("https://docs.python.org/3", use_if_available("/usr/share/doc/python3/html/objects.inv")),
139 "numpy": ("https://numpy.org/doc/stable", use_if_available("/usr/share/doc/python-numpy/html/objects.inv")),
140 "pip": ("https://pip.pypa.io/en/stable", None),
141 "tox": ("https://tox.wiki/en/stable", None),
142 "virtualenv": ("https://virtualenv.pypa.io/en/stable", None),
•143 "setuptools": ("https://setuptools.pypa.io/en/stable", use_if_available("/usr/share/doc/python-setuptools-doc/html/objects.inv")),
144 "packaging": ("https://packaging.python.org/en/latest", None),
145 }
146
147 # -- Options for todo -----------------------------------------------------------------
148 # https://www.sphinx-doc.org/en/master/usage/extensions/todo.html#configuration
149
150 todo_include_todos = True
151
152 # -- Options for linkcheck builder ----------------------------------------------------
153 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-the-linkcheck-builder
154
155 linkcheck_ignore = [
156 "https://blogs.msdn.microsoft.com/bharry/2017/06/28/testing-in-a-cloud-delivery-cadence/",
157 "http://pythontesting.net/framework/pytest-introduction/",
158 r"https://github.com/pytest-dev/pytest/issues/\d+",
159 r"https://github.com/pytest-dev/pytest/pull/\d+",
160 ]
161 linkcheck_workers = 5
162
163 # -- Options for HTML output ----------------------------------------------------------
164 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
165
166 html_theme = "furo"
167 html_theme_options = {"sidebar_hide_name": True}
168
169 html_static_path = ["_static"]
170 html_css_files = [
171 "pytest-custom.css",
172 ]
173
174 html_title = "pytest documentation"
175 html_short_title = f"pytest-{release}"
176
177 html_logo = "_static/pytest1.png"
178 html_favicon = "img/favicon.png"
179
180 html_use_index = False
181 html_show_sourcelink = False
182
183 html_baseurl = "https://docs.pytest.org/en/stable/"
184
185 # -- Options for HTML Help output -----------------------------------------------------
186 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-help-output
187
188 htmlhelp_basename = "pytestdoc"
189
190
191 # -- Options for manual page output ---------------------------------------------------
192 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-manual-page-output
193
194 man_pages = [
195 ("how-to/usage", "pytest", "pytest usage", ["holger krekel at merlinux eu"], 1)
196 ]
197
198 # -- Options for epub output ----------------------------------------------------------
199 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-epub-output
200
201 epub_title = "pytest"
202 epub_author = "holger krekel at merlinux eu"
203 epub_publisher = "holger krekel at merlinux eu"
204 epub_copyright = "2013, holger krekel et alii"
205
206 # -- Options for LaTeX output --------------------------------------------------------
207 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-latex-output
208
209 latex_documents = [
210 (
211 "contents",
212 "pytest.tex",
213 "pytest Documentation",
214 "holger krekel, trainer and consultant, https://merlinux.eu/",
215 "manual",
216 )
217 ]
218 latex_domain_indices = False
219 latex_engine = "lualatex"
220 latex_elements = {
221 "preamble": dedent(
222 r"""
223 \directlua{
224 luaotfload.add_fallback("fallbacks", {
225 "Noto Serif CJK SC:style=Regular;",
226 "Symbola:Style=Regular;"
227 })
228 }
229
230 \setmainfont{FreeSerif}[RawFeature={fallback=fallbacks}]
231 """
232 )
233 }
234
235 # -- Options for texinfo output -------------------------------------------------------
236 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-texinfo-output
237
238 texinfo_documents = [
239 (
240 root_doc,
241 "pytest",
242 "pytest Documentation",
243 (
244 "Holger Krekel@*Benjamin Peterson@*Ronny Pfannschmidt@*"
245 "Floris Bruynooghe@*others"
246 ),
247 "pytest",
248 "simple powerful testing with Python",
249 "Programming",
250 1,
251 )
252 ]
253
254 # -- Options for towncrier_draft extension --------------------------------------------
255 # https://sphinxcontrib-towncrier.readthedocs.io/en/latest/#how-to-use-this
256
257 towncrier_draft_autoversion_mode = "draft" # or: 'sphinx-version', 'sphinx-release'
258 towncrier_draft_include_empty = True
259 towncrier_draft_working_directory = PROJECT_ROOT_DIR
260 towncrier_draft_config_path = "pyproject.toml" # relative to cwd
261
262 # -- Options for sphinx_issues extension -----------------------------------
263 # https://github.com/sloria/sphinx-issues#installation-and-configuration
264
265 issues_github_path = "pytest-dev/pytest"
266
267 # -- Custom Read the Docs build configuration -----------------------------------------
268 # https://docs.readthedocs.io/en/stable/reference/environment-variables.html#environment-variable-reference
269 # https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#including-content-based-on-tags
270
•271 IS_RELEASE_ON_RTD = True or (
272 os.getenv("READTHEDOCS", "False") == "True"
273 and os.environ["READTHEDOCS_VERSION_TYPE"] == "tag"
274 )
275 if IS_RELEASE_ON_RTD:
276 tags: set[str]
277 # pylint: disable-next=used-before-assignment
278 tags.add("is_release") # noqa: F821
279
280 # -- Custom documentation plugin ------------------------------------------------------
281 # https://www.sphinx-doc.org/en/master/development/tutorials/extending_syntax.html#the-setup-function
282
283
284 def setup(app: sphinx.application.Sphinx) -> None:
285 app.add_crossref_type(
286 "fixture",
287 "fixture",
288 objname="built-in fixture",
289 indextemplate="pair: %s; fixture",
290 )
291
292 app.add_object_type(
293 "globalvar",
294 "globalvar",
295 objname="global variable interpreted by pytest",
296 indextemplate="pair: %s; global variable interpreted by pytest",
297 )
298
299 app.add_crossref_type(
300 directivename="hook",
301 rolename="hook",
302 objname="pytest hook",
303 indextemplate="pair: %s; hook",
304 )
305
306 # legacypath.py monkey-patches pytest.Testdir in. Import the file so
307 # that autodoc can discover references to it.
308 # Workaround for Sphinx bug with Python 3.14:
309 # inspect.getsource() returns '\n' instead of raising OSError for classes
310 # whose __module__ doesn't match the file they're defined in, causing
311 # get_type_comment() to crash with IndexError on empty ast.parse result.
312 # See: https://github.com/sphinx-doc/sphinx/issues/14345
313 import sys
314
315 import _pytest.legacypath # noqa: F401
316
317 if sys.version_info >= (3, 14):
318 from sphinx.ext.autodoc._dynamic import _type_comments
319
320 _orig_get_type_comment = _type_comments.get_type_comment
321
322 def _get_type_comment_safe(obj: object, bound_method: bool = False) -> object:
323 try:
324 return _orig_get_type_comment(obj, bound_method)
325 except IndexError:
326 return None
327
328 _type_comments.get_type_comment = _get_type_comment_safe # type: ignore[assignment]