Debian Codegraph @

hypothesis-python/docs/conf.py

raw ◀ ▶
Source reconstructed at patch state 1 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 import libcst
113
114 import hypothesis.extra.codemods
115
116 assert libcst
117 assert hypothesis.extra.codemods
118
119 # patch in mock array_api namespace so we can autodoc it
120 from hypothesis.extra.array_api import (
121 RELEASED_VERSIONS,
122 make_strategies_namespace,
123 mock_xp,
124 )
125
126 mod = types.ModuleType("xps")
127 mod.__dict__.update(
128 make_strategies_namespace(mock_xp, api_version=RELEASED_VERSIONS[-1]).__dict__
129 )
130 assert "xps" not in sys.modules
131 sys.modules["xps"] = mod
132
133 def process_signature(app, what, name, obj, options, signature, return_annotation):
134 # manually override an ugly signature from .. autofunction. Alternative we
135 # could manually document with `.. function:: run_conformance_test(...)`,
136 # but that's less likely to stay up to date.
137 if (
138 name
139 == "hypothesis.internal.conjecture.provider_conformance.run_conformance_test"
140 ):
141 # so we know if this ever becomes obsolete
142 assert "_realize_objects" in signature
143 signature = re.sub(
144 r"_realize_objects=.*",
145 "_realize_objects=st.from_type(object) | st.from_type(type).flatmap(st.from_type))",
146 signature,
147 )
148 return signature, return_annotation
149
150 app.connect("autodoc-process-signature", process_signature)
151 app.add_role("v", VersionRole(prefix="v"))
152 app.add_role("version", VersionRole(prefix="version "))
153
154
155 language = "en"
156 exclude_patterns = ["_build", "prolog.rst"]
157 pygments_style = "sphinx"
158 todo_include_todos = False
159
160 # To run linkcheck (last argument is the output dir)
161 # sphinx-build --builder linkcheck hypothesis-python/docs linkcheck
162 linkcheck_ignore = [
163 # we'll assume that python isn't going to break peps, and github isn't going
164 # to break issues/pulls. (and if they did, we'd hopefully notice quickly).
165 r"https://peps.python.org/pep-.*",
166 r"https://github.com/HypothesisWorks/hypothesis/issues/\d+",
167 r"https://github.com/HypothesisWorks/hypothesis/pull/\d+",
168 ]
169
170 intersphinx_mapping = {
171 "python": ("https://docs.python.org/3/", None),
172 "numpy": ("https://numpy.org/doc/stable/", None),
173 "pandas": ("https://pandas.pydata.org/docs/", None),
174 "pytest": ("https://docs.pytest.org/en/stable/", None),
175 "django": (
176 "http://docs.djangoproject.com/en/stable/",
177 "http://docs.djangoproject.com/en/stable/_objects/",
178 ),
179 "dateutil": ("https://dateutil.readthedocs.io/en/stable/", None),
180 "redis": ("https://redis.readthedocs.io/en/stable/", None),
181 "attrs": ("https://www.attrs.org/en/stable/", None),
182 "sphinx": ("https://www.sphinx-doc.org/en/master/", None),
183 "IPython": ("https://ipython.readthedocs.io/en/stable/", None),
184 "lark": ("https://lark-parser.readthedocs.io/en/stable/", None),
185 "xarray": ("https://docs.xarray.dev/en/stable/", None),
186 }
187
188 autodoc_mock_imports = ["numpy", "pandas", "redis", "django", "pytz"]
189
190 rst_prolog = (Path(__file__).parent / "prolog.rst").read_text()
191
192 codeautolink_autodoc_inject = False
193 codeautolink_global_preface = """
194 from hypothesis import *
195 import hypothesis.strategies as st
196 from hypothesis.strategies import *
197 """
198
199 # This config value must be a dictionary of external sites, mapping unique
200 # short alias names to a base URL and a prefix.
201 # See http://sphinx-doc.org/ext/extlinks.html
202 _repo = "https://github.com/HypothesisWorks/hypothesis/"
203 extlinks = {
204 "commit": (_repo + "commit/%s", "commit %s"),
205 "gh-file": (_repo + "blob/master/%s", "%s"),
206 "gh-link": (_repo + "%s", "%s"),
207 "issue": (_repo + "issues/%s", "issue #%s"),
208 "pull": (_repo + "pull/%s", "pull request #%s"),
209 "pypi": ("https://pypi.org/project/%s/", "%s"),
210 "bpo": ("https://bugs.python.org/issue%s", "bpo-%s"),
211 "xp-ref": ("https://data-apis.org/array-api/latest/API_specification/%s", "%s"),
212 "wikipedia": ("https://en.wikipedia.org/wiki/%s", "%s"),
213 }
214
215 # -- Options for HTML output ----------------------------------------------
216
217 html_theme = "furo"
218 # remove "Hypothesis <version> documentation" from just below logo on the sidebar
219 html_theme_options = {"sidebar_hide_name": True}
220 html_static_path = ["_static"]
221 html_css_files = [
222 "better-signatures.css",
223 "wrap-in-tables.css",
224 "no-scroll.css",
225 "dark-fix.css",
226 ]
227 htmlhelp_basename = "Hypothesisdoc"
228 html_favicon = "../../brand/favicon.ico"
229 html_logo = "../../brand/dragonfly-rainbow-150w.svg"
230
231
232 # -- Options for LaTeX output ---------------------------------------------
233
234 latex_elements = {}
235 latex_documents = [
236 (master_doc, "Hypothesis.tex", "Hypothesis Documentation", author, "manual")
237 ]
238 man_pages = [(master_doc, "hypothesis", "Hypothesis Documentation", [author], 1)]
239 texinfo_documents = [
240 (
241 master_doc,
242 "Hypothesis",
243 "Hypothesis Documentation",
244 author,
245 "Hypothesis",
246 "Advanced property-based testing for Python.",
247 "Miscellaneous",
248 )
249 ]