Debian Codegraph @

hypothesis-python/docs/conf.py

raw ◀ ▶
Source reconstructed at patch state 0 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 "sphinx_codeautolink",
42 "sphinx_selective_exclude.eager_only",
43 "sphinx-jsonschema",
44 # loading this extension overrides the default -b linkcheck behavior with
45 # custom url ignore logic. see hypothesis_linkcheck.py for details.
46 "hypothesis_linkcheck",
47 "hypothesis_redirects",
48 ]
49
50 templates_path = ["_templates"]
51
52 # config for hypothesis_redirects
53 redirects = {
54 "details": "reference/index.html",
55 "data": "reference/strategies.html",
56 "database": "reference/api.html#database",
57 # "stateful": "reference/api.html#stateful-tests",
58 "reproducing": "reference/api.html",
59 "ghostwriter": "reference/integrations.html#ghostwriter",
60 "django": "reference/strategies.html#django",
61 "numpy": "reference/strategies.html#numpy",
62 "observability": "reference/integrations.html#observability",
63 "settings": "reference/api.html#settings",
64 "endorsements": "usage.html#testimonials",
65 # TODO enable when we actually rename them
66 # "extras": "extensions.html",
67 "supported": "compatibility.html",
68 "changes": "changelog.html",
69 "strategies": "extensions.html",
70 # these pages were removed without replacement
71 "support": "index.html",
72 "manifesto": "index.html",
73 "examples": "index.html",
74 }
75 redirect_html_template_file = "redirect.html.template"
76
77 source_suffix = ".rst"
78
79 # The master toctree document.
80 master_doc = "index"
81
82 # General information about the project.
83 project = "Hypothesis"
84 author = "the Hypothesis team"
85 copyright = f"2013-{datetime.date.today().year}, {author}"
86
87 _d = {}
88 _version_file = root.joinpath("src", "hypothesis", "version.py")
89 exec(_version_file.read_text(encoding="utf-8"), _d)
90 version = _d["__version__"]
91 release = _d["__version__"]
92
93
94 # custom role for version syntaxes.
95 # :v:`6.131.0` = [v6.131.0](changelog.html#v6.13.0)
96 # :version:`6.131.0` = [version 6.131.0](changelog.html#v6.13.0)
97 class VersionRole(SphinxRole):
98 def __init__(self, prefix):
99 self.prefix = prefix
100
101 def run(self):
102 node = nodes.reference(
103 "",
104 f"{self.prefix}{self.text}",
105 refuri=f"changelog.html#v{self.text.replace('.', '-')}",
106 )
107 return [node], []
108
109
110 def setup(app):
111 if root.joinpath("RELEASE.rst").is_file():
112 app.tags.add("has_release_file")
113
114 # Workaround for partial-initialization problem when autodoc imports libcst
115 import libcst
116
117 import hypothesis.extra.codemods
118
119 assert libcst
120 assert hypothesis.extra.codemods
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 ]