Debian Codegraph @

doc/en/conf.py

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