Debian Codegraph @

hypothesis-python/docs/conf.py

raw ◀ ▶
Source reconstructed at patch state 2 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 import datetime
12 import re
13 import sys
14 import types
15 from pathlib import Path
16
17 from docutils import nodes
18 from sphinx.util.docutils import SphinxRole
19
20 root = Path(__file__).parent.parent
21 # insert so the local versions are consulted first, before any installed version
22 sys.path.insert(0, str(root / "src"))
23 sys.path.insert(0, str(Path(__file__).parent / "_ext"))
24
25 needs_sphinx = re.search(
26 r"sphinx==([0-9\.]+)", root.joinpath("../requirements/tools.txt").read_text()
27 ).group(1)
28 default_role = "py:obj"
29 nitpicky = True
30
31 autodoc_member_order = "bysource"
32 autodoc_typehints = "none"
33 maximum_signature_line_length = 60 # either one line, or one param per line
34
35 extensions = [
36 "sphinx.ext.autodoc",
37 "sphinx.ext.extlinks",
38 "sphinx.ext.viewcode",
39 "sphinx.ext.intersphinx",
40 "sphinx.ext.napoleon",
41 # loading this extension overrides the default -b linkcheck behavior with
42 # custom url ignore logic. see hypothesis_linkcheck.py for details.
43 "hypothesis_linkcheck",
44 "hypothesis_redirects",
45 ]
46
47 templates_path = ["_templates"]
48
49 # config for hypothesis_redirects
50 redirects = {
51 "details": "reference/index.html",
52 "data": "reference/strategies.html",
53 "database": "reference/api.html#database",
54 # "stateful": "reference/api.html#stateful-tests",
55 "reproducing": "reference/api.html",
56 "ghostwriter": "reference/integrations.html#ghostwriter",
57 "django": "reference/strategies.html#django",
58 "numpy": "reference/strategies.html#numpy",
59 "observability": "reference/integrations.html#observability",
60 "settings": "reference/api.html#settings",
61 "endorsements": "usage.html#testimonials",
62 # TODO enable when we actually rename them
63 # "extras": "extensions.html",
64 "supported": "compatibility.html",
65 "changes": "changelog.html",
66 "strategies": "extensions.html",
67 # these pages were removed without replacement
68 "support": "index.html",
69 "manifesto": "index.html",
70 "examples": "index.html",
71 }
72 redirect_html_template_file = "redirect.html.template"
73
74 source_suffix = ".rst"
75
76 # The master toctree document.
77 master_doc = "index"
78
79 # General information about the project.
80 project = "Hypothesis"
81 author = "the Hypothesis team"
82 copyright = f"2013-{datetime.date.today().year}, {author}"
83
84 _d = {}
85 _version_file = root.joinpath("src", "hypothesis", "version.py")
86 exec(_version_file.read_text(encoding="utf-8"), _d)
87 version = _d["__version__"]
88 release = _d["__version__"]
89
90
91 # custom role for version syntaxes.
92 # :v:`6.131.0` = [v6.131.0](changelog.html#v6.13.0)
93 # :version:`6.131.0` = [version 6.131.0](changelog.html#v6.13.0)
94 class VersionRole(SphinxRole):
95 def __init__(self, prefix):
96 self.prefix = prefix
97
98 def run(self):
99 node = nodes.reference(
100 "",
101 f"{self.prefix}{self.text}",
102 refuri=f"changelog.html#v{self.text.replace('.', '-')}",
103 )
104 return [node], []
105
106
107 def setup(app):
108 if root.joinpath("RELEASE.rst").is_file():
109 app.tags.add("has_release_file")
110
111 # Workaround for partial-initialization problem when autodoc imports libcst
112 try:
113 import libcst
114
115 import hypothesis.extra.codemods
116
117 assert libcst
118 assert hypothesis.extra.codemods
119 except ModuleNotFoundError:
120 pass
121
122 # patch in mock array_api namespace so we can autodoc it
123 from hypothesis.extra.array_api import (
124 RELEASED_VERSIONS,
125 make_strategies_namespace,
126 mock_xp,
127 )
128
129 mod = types.ModuleType("xps")
130 mod.__dict__.update(
131 make_strategies_namespace(mock_xp, api_version=RELEASED_VERSIONS[-1]).__dict__
132 )
133 assert "xps" not in sys.modules
134 sys.modules["xps"] = mod
135
136 def process_signature(app, what, name, obj, options, signature, return_annotation):
137 # manually override an ugly signature from .. autofunction. Alternative we
138 # could manually document with `.. function:: run_conformance_test(...)`,
139 # but that's less likely to stay up to date.
140 if (
141 name
142 == "hypothesis.internal.conjecture.provider_conformance.run_conformance_test"
143 ):
144 # so we know if this ever becomes obsolete
145 assert "_realize_objects" in signature
146 signature = re.sub(
147 r"_realize_objects=.*",
148 "_realize_objects=st.from_type(object) | st.from_type(type).flatmap(st.from_type))",
149 signature,
150 )
151 return signature, return_annotation
152
153 app.connect("autodoc-process-signature", process_signature)
154 app.add_role("v", VersionRole(prefix="v"))
155 app.add_role("version", VersionRole(prefix="version "))
156
157
158 language = "en"
159 exclude_patterns = ["_build", "prolog.rst"]
160 pygments_style = "sphinx"
161 todo_include_todos = False
162
163 # To run linkcheck (last argument is the output dir)
164 # sphinx-build --builder linkcheck hypothesis-python/docs linkcheck
165 linkcheck_ignore = [
166 # we'll assume that python isn't going to break peps, and github isn't going
167 # to break issues/pulls. (and if they did, we'd hopefully notice quickly).
168 r"https://peps.python.org/pep-.*",
169 r"https://github.com/HypothesisWorks/hypothesis/issues/\d+",
170 r"https://github.com/HypothesisWorks/hypothesis/pull/\d+",
171 ]
172
173 intersphinx_mapping = {
174 "python": ("https://docs.python.org/3/", None),
175 "numpy": ("https://numpy.org/doc/stable/", None),
176 "pandas": ("https://pandas.pydata.org/docs/", None),
177 "pytest": ("https://docs.pytest.org/en/stable/", None),
178 "django": (
179 "http://docs.djangoproject.com/en/stable/",
180 "http://docs.djangoproject.com/en/stable/_objects/",
181 ),
182 "dateutil": ("https://dateutil.readthedocs.io/en/stable/", None),
183 "redis": ("https://redis.readthedocs.io/en/stable/", None),
184 "attrs": ("https://www.attrs.org/en/stable/", None),
185 "sphinx": ("https://www.sphinx-doc.org/en/master/", None),
186 "IPython": ("https://ipython.readthedocs.io/en/stable/", None),
187 "lark": ("https://lark-parser.readthedocs.io/en/stable/", None),
188 "xarray": ("https://docs.xarray.dev/en/stable/", None),
189 }
190
191 autodoc_mock_imports = ["numpy", "pandas", "redis", "django", "pytz"]
192
193 rst_prolog = (Path(__file__).parent / "prolog.rst").read_text()
194
195 codeautolink_autodoc_inject = False
196 codeautolink_global_preface = """
197 from hypothesis import *
198 import hypothesis.strategies as st
199 from hypothesis.strategies import *
200 """
201
202 # This config value must be a dictionary of external sites, mapping unique
203 # short alias names to a base URL and a prefix.
204 # See http://sphinx-doc.org/ext/extlinks.html
205 _repo = "https://github.com/HypothesisWorks/hypothesis/"
206 extlinks = {
207 "commit": (_repo + "commit/%s", "commit %s"),
208 "gh-file": (_repo + "blob/master/%s", "%s"),
209 "gh-link": (_repo + "%s", "%s"),
210 "issue": (_repo + "issues/%s", "issue #%s"),
211 "pull": (_repo + "pull/%s", "pull request #%s"),
212 "pypi": ("https://pypi.org/project/%s/", "%s"),
213 "bpo": ("https://bugs.python.org/issue%s", "bpo-%s"),
214 "xp-ref": ("https://data-apis.org/array-api/latest/API_specification/%s", "%s"),
215 "wikipedia": ("https://en.wikipedia.org/wiki/%s", "%s"),
216 }
217
218 # -- Options for HTML output ----------------------------------------------
219
220 html_theme = "furo"
221 # remove "Hypothesis <version> documentation" from just below logo on the sidebar
222 html_theme_options = {"sidebar_hide_name": True}
223 html_static_path = ["_static"]
224 html_css_files = [
225 "better-signatures.css",
226 "wrap-in-tables.css",
227 "no-scroll.css",
228 "dark-fix.css",
229 ]
230 htmlhelp_basename = "Hypothesisdoc"
231 html_favicon = "../../brand/favicon.ico"
232 html_logo = "../../brand/dragonfly-rainbow-150w.svg"
233
234
235 # -- Options for LaTeX output ---------------------------------------------
236
237 latex_elements = {}
238 latex_documents = [
239 (master_doc, "Hypothesis.tex", "Hypothesis Documentation", author, "manual")
240 ]
241 man_pages = [(master_doc, "hypothesis", "Hypothesis Documentation", [author], 1)]
242 texinfo_documents = [
243 (
244 master_doc,
245 "Hypothesis",
246 "Hypothesis Documentation",
247 author,
248 "Hypothesis",
249 "Advanced property-based testing for Python.",
250 "Miscellaneous",
251 )
252 ]