Debian Codegraph @

docs/conf.py

raw ◀ ▶
3 Debian patches touch this file
1 """Configuration file for the Sphinx documentation builder.
2
3 This file only contains a selection of the most common options. For a full
4 list see the documentation:
5 https://www.sphinx-doc.org/en/master/usage/configuration.html
6 """
7
8 # -- Path setup --------------------------------------------------------------
9 import os
10 import sys
11
12 from pathlib import Path
13 from typing import Any, Dict
14
15 from sphinx.application import Sphinx
16 from sphinx.locale import _
17
18 import pydata_sphinx_theme
19
20
21 sys.path.append(str(Path(".").resolve()))
22
23 # -- Project information -----------------------------------------------------
24
25 project = "PyData Theme"
26 copyright = "2019, PyData Community"
27 author = "PyData Community"
28
29 # -- General configuration ---------------------------------------------------
30
31 extensions = [
32 # AutoAPI must run early to generate API files before other extensions
33 "autoapi.extension",
34 "sphinx.ext.napoleon",
35 "sphinx.ext.autodoc",
36 "sphinx.ext.autosummary",
37 "sphinx.ext.todo",
38 "sphinx.ext.viewcode",
39 "sphinx.ext.intersphinx",
40 "sphinx.ext.graphviz",
41 "sphinxext.rediraffe",
42 "sphinx_design",
43 "sphinx_copybutton",
44 # custom extentions
45 "_extension.gallery_directive",
46 "_extension.component_directive",
47 # For extension examples and demos
48 "myst_parser",
49 "numpydoc",
50 "sphinx_favicon",
51 ]
52
53 # Add any paths that contain templates here, relative to this directory.
54 templates_path = ["_templates"]
55
56 # List of patterns, relative to source directory, that match files and
57 # directories to ignore when looking for source files.
58 # This pattern also affects html_static_path and html_extra_path.
59 exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]
60
61 intersphinx_mapping = {"sphinx": ("https://www.sphinx-doc.org/en/master", None)}
62
63 # -- Sitemap -----------------------------------------------------------------
64
65 # ReadTheDocs has its own way of generating sitemaps, etc.
66 if not os.environ.get("READTHEDOCS"):
67 extensions += ["sphinx_sitemap"]
68
69 html_baseurl = os.environ.get("SITEMAP_URL_BASE", "http://127.0.0.1:8000/")
70 sitemap_locales = [None]
71 sitemap_url_scheme = "{link}"
72
73 # -- MyST options ------------------------------------------------------------
74
75 # This allows us to use ::: to denote directives, useful for admonitions
76 myst_enable_extensions = ["colon_fence", "linkify", "substitution"]
77 myst_heading_anchors = 2
78 myst_substitutions = {"rtd": "[Read the Docs](https://readthedocs.org/)"}
79
80 # -- Internationalization ----------------------------------------------------
81
82 # specifying the natural language populates some key tags
83 language = "en"
84
85 # -- Ablog options -----------------------------------------------------------
86
87 blog_path = "examples/blog/index"
88 blog_authors = {
89 "pydata": ("PyData", "https://pydata.org"),
90 "jupyter": ("Jupyter", "https://jupyter.org"),
91 }
92
93
94 # -- sphinx_ext_graphviz options ---------------------------------------------
95
96 graphviz_output_format = "svg"
97 inheritance_graph_attrs = dict(
98 rankdir="LR",
99 fontsize=14,
100 ratio="compress",
101 )
102
103 # -- sphinx_togglebutton options ---------------------------------------------
104 togglebutton_hint = str(_("Click to expand"))
105 togglebutton_hint_hide = str(_("Click to collapse"))
106
107 # -- Sphinx-copybutton options ---------------------------------------------
108 # Exclude copy button from appearing over notebook cell numbers by using :not()
109 # The default copybutton selector is `div.highlight pre`
110 # https://github.com/executablebooks/sphinx-copybutton/blob/master/sphinx_copybutton/__init__.py#L82
111 copybutton_exclude = ".linenos, .gp"
112 copybutton_selector = ":not(.prompt) > div.highlight pre"
113
114 # -- Options for HTML output -------------------------------------------------
115
116 html_theme = "pydata_sphinx_theme"
117 html_logo = "_static/logo.svg"
118 html_favicon = "_static/logo.svg"
119 html_sourcelink_suffix = ""
120 html_last_updated_fmt = "" # to reveal the build date in the pages meta
121
122 # Define the json_url for our version switcher.
123 json_url = "https://pydata-sphinx-theme.readthedocs.io/en/latest/_static/switcher.json"
124
125 # Define the version we use for matching in the version switcher.
126 version_match = os.environ.get("READTHEDOCS_VERSION")
127 release = pydata_sphinx_theme.__version__
128 # If READTHEDOCS_VERSION doesn't exist, we're not on RTD
129 # If it is an integer, we're in a PR build and the version isn't correct.
130 # If it's "latest" → change to "dev" (that's what we want the switcher to call it)
131 if not version_match or version_match.isdigit() or version_match == "latest":
132 # For local development, infer the version to match from the package.
133 if "dev" in release or "rc" in release:
134 version_match = "dev"
135 # We want to keep the relative reference if we are in dev mode
136 # but we want the whole url if we are effectively in a released version
137 json_url = "_static/switcher.json"
138 else:
139 version_match = f"v{release}"
140 elif version_match == "stable":
141 version_match = f"v{release}"
142
143 html_theme_options = {
144 "external_links": [
145 {
146 "url": "https://pydata.org",
147 "name": "PyData Website",
148 },
149 {
150 "url": "https://numfocus.org/",
151 "name": "NumFocus",
152 },
153 {
154 "url": "https://numfocus.org/donate",
155 "name": "Donate to NumFocus",
156 },
157 ],
158 "header_links_before_dropdown": 4,
159 "icon_links": [
160 {
161 "name": "X",
162 "url": "https://x.com/PyData",
163 "icon": "fa-brands fa-x-twitter",
164 },
165 {
166 "name": "GitHub",
167 "url": "https://github.com/pydata/pydata-sphinx-theme",
168 "icon": "fa-brands fa-github",
169 },
170 {
171 "name": "PyPI",
172 "url": "https://pypi.org/project/pydata-sphinx-theme",
173 "icon": "fa-brands fa-python",
174 },
175 {
176 "name": "PyData",
177 "url": "https://pydata.org",
178 "icon": "fa-custom fa-pydata",
179 },
180 ],
181 # alternative way to set twitter and github header icons
•182 # "github_url": "https://github.com/pydata/pydata-sphinx-theme",
183 # "twitter_url": "https://twitter.com/PyData",
184 "logo": {
185 "text": "PyData Theme",
186 "image_dark": "_static/logo-dark.svg",
187 },
188 "use_edit_page_button": True,
189 "show_toc_level": 1,
190 # [left, content, right] For testing that the navbar items align properly
191 "navbar_align": "left",
192 # "show_nav_level": 2,
193 "announcement": "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/_templates/custom-template.html",
194 "show_version_warning_banner": True,
•195 "navbar_center": ["navbar-nav"],
196 # "navbar_start": ["navbar-logo"],
197 # "navbar_end": ["theme-switcher", "navbar-icon-links"],
198 # "navbar_persistent": ["search-button"],
199 # "primary_sidebar_end": ["custom-template", "sidebar-ethical-ads"],
200 # "article_footer_items": ["test", "test"],
201 # "content_footer_items": ["test", "test"],
202 "footer_start": ["copyright"],
203 "footer_center": ["sphinx-version"],
204 "secondary_sidebar_items": {
205 "**/*": ["page-toc", "edit-this-page", "sourcelink"],
206 "examples/no-sidebar": [],
207 },
208 # "back_to_top_button": False,
209 "search_as_you_type": True,
210 }
211
212 html_sidebars = {
213 "community/index": [
214 "sidebar-nav-bs",
215 "custom-template",
216 ], # This ensures we test for custom sidebars
217 "examples/no-sidebar": [], # Test what page looks like with no sidebar items
218 "examples/persistent-search-field": ["search-field"],
219 }
220
221 html_context = {
222 "github_user": "pydata",
223 "github_repo": "pydata-sphinx-theme",
224 "github_version": "main",
225 "doc_path": "docs",
226 }
227
228 rediraffe_redirects = {
229 "contributing.rst": "community/index.rst",
230 }
231
232 # Add any paths that contain custom static files (such as style sheets) here,
233 # relative to this directory. They are copied after the builtin static files,
234 # so a file named "default.css" will overwrite the builtin "default.css".
235 html_static_path = ["_static"]
236 html_css_files = ["custom.css"]
237 html_js_files = [
238 ("custom-icons.js", {"defer": "defer"}),
239 ]
240 todo_include_todos = True
241
242 mathjax_path = "file:///usr/share/nodejs/mathjax-full/es5/tex-mml-chtml.js"
243
244 # -- favicon options ---------------------------------------------------------
245
246 # see https://sphinx-favicon.readthedocs.io for more information about the
247 # sphinx-favicon extension
248 favicons = [
249 # generic icons compatible with most browsers
250 "favicon-32x32.png",
•251 "favicon-16x16.png",
252 {"rel": "shortcut icon", "sizes": "any", "href": "favicon.ico"},
253 # chrome specific
254 "android-chrome-192x192.png",
255 # apple icons
256 {"rel": "mask-icon", "color": "#459db9", "href": "safari-pinned-tab.svg"},
257 {"rel": "apple-touch-icon", "href": "apple-touch-icon.png"},
258 # msapplications
259 {"name": "msapplication-TileColor", "content": "#459db9"},
260 {"name": "theme-color", "content": "#ffffff"},
261 {"name": "msapplication-TileImage", "content": "mstile-150x150.png"},
262 ]
263
264 # -- Options for autosummary/autodoc output ------------------------------------
265 autosummary_generate = True
266 autodoc_typehints = "description"
267 autodoc_member_order = "groupwise"
268
269 # -- Options for autoapi -------------------------------------------------------
270 autoapi_type = "python"
271 # Use absolute path to ensure AutoAPI can find the source code in all environments
272 _autoapi_source = os.path.abspath(
273 os.path.join(os.path.dirname(__file__), "..", "src", "pydata_sphinx_theme")
274 )
275 autoapi_dirs = [_autoapi_source]
276 autoapi_keep_files = True
277 autoapi_root = "api"
278 autoapi_member_order = "groupwise"
279
280 # -- Warnings / Nitpicky -------------------------------------------------------
281
282 nitpicky = True
283 bad_classes = (
284 r".*abc def.*", # urllib.parse.unquote_to_bytes
285 r"api_sample\.RandomNumberGenerator",
286 r"bs4\.BeautifulSoup",
287 r"docutils\.nodes\.Node",
288 r"matplotlib\.artist\.Artist", # matplotlib xrefs are in the class diagram demo
289 r"matplotlib\.figure\.Figure",
290 r"matplotlib\.figure\.FigureBase",
291 r"pygments\.formatters\.HtmlFormatter",
292 )
293 nitpick_ignore_regex = [
294 *[("py:class", target) for target in bad_classes],
295 # we demo some `urllib` docs on our site; don't care that its xrefs fail to resolve
296 ("py:obj", r"urllib\.parse\.(Defrag|Parse|Split)Result(Bytes)?\.(count|index)"),
297 # the kitchen sink pages include some intentional errors
298 ("token", r"(suite|expression|target)"),
299 ]
300
301 # -- application setup -------------------------------------------------------
302
303
304 def setup_to_main(
305 app: Sphinx, pagename: str, templatename: str, context, doctree
306 ) -> None:
307 """
308 Add a function that jinja can access for returning an "edit this page" link
309 pointing to `main`.
310 """
311
312 def to_main(link: str) -> str:
313 """
314 Transform "edit on github" links and make sure they always point to the
315 main branch.
316
317 Args:
318 link: the link to the github edit interface
319
320 Returns:
321 the link to the tip of the main branch for the same file
322 """
323 links = link.split("/")
324 idx = links.index("edit")
325 return "/".join(links[: idx + 1]) + "/main/" + "/".join(links[idx + 2 :])
326
327 context["to_main"] = to_main
328
329
330 def setup(app: Sphinx) -> Dict[str, Any]:
331 """Add custom configuration to sphinx app.
332
333 Args:
334 app: the Sphinx application
335 Returns:
336 the 2 parallel parameters set to ``True``.
337 """
338 app.connect("html-page-context", setup_to_main)
339
340 return {
341 "parallel_read_safe": True,
342 "parallel_write_safe": True,
343 }
344
345
346 # -- linkcheck options ---------------------------------------------------------
347
348 linkcheck_anchors_ignore = [
349 # match any anchor that starts with a '/' since this is an invalid HTML anchor
350 r"\/.*",
351 ]
352
353 linkcheck_ignore = [
354 # The crawler gets "Anchor not found" for various anchors
355 r"https://github.com.+?#.*",
356 r"https://www.sphinx-doc.org/en/master/*/.+?#.+?",
357 # sample urls
358 "https://someurl/release-0.1.0.tar-gz",
359 # for whatever reason the Ablog index is treated as broken
360 "../examples/blog/index.html",
361 # get a 403 on CI
362 "https://canvas.workday.com/styles/tokens/type",
363 r"https?://www.gnu.org/software/gettext/.*",
364 r"https://www.npmjs.com/.*",
365 r"https://sass-lang.com/.*",
366 r"https://docutils.sourceforge.io/.*",
367 ]
368
369 linkcheck_allowed_redirects = {
370 r"http://www.python.org": "https://www.python.org/",
371 # :source:`something` linking files in the repository
372 r"https://github.com/pydata/pydata-sphinx-theme/tree/.*": r"https://github.com/pydata/pydata-sphinx-theme/blob/.*",
373 r"https://github.com/sphinx-themes/sphinx-themes.org/raw/.*": r"https://github.com/sphinx-themes/sphinx-themes.org/tree/.*",
374 # project redirects
375 r"https://pypi.org/project/[A-Za-z\d_\-\.]+/": r"https://pypi.org/project/[a-z\d\-\.]+/",
376 r"https://virtualenv.pypa.io/": "https://virtualenv.pypa.io/en/latest/",
377 # catching redirects in rtd
378 r"https://[A-Za-z\d_\-\.]+.readthedocs.io/": r"https://[A-Za-z\d_\-\.]+\.readthedocs\.io(/en)?/(stable|latest)/",
379 r"https://readthedocs.org/": r"https://about.readthedocs.com/\?ref=app.readthedocs.org",
380 r"https://app.readthedocs.org/dashboard/": r"https://app.readthedocs.org/accounts/login/\?next=/dashboard/",
381 # miscellanenous urls
382 r"https://python.arviz.org/": "https://python.arviz.org/en/stable/",
383 r"https://www.sphinx-doc.org/": "https://www.sphinx-doc.org/en/master/",
384 r"https://idtracker.ai/": "https://idtracker.ai/latest/",
385 r"https://gitlab.com": "https://about.gitlab.com/",
386 r"https://feature-engine.readthedocs.io/": "https://feature-engine.trainindata.com/en/latest/",
387 r"https://picsum.photos/": r"https://fastly.picsum.photos/",
388 }
389
390 # we have had issues with linkcheck timing and retries on www.gnu.org
391 linkcheck_retries = 1
392 linkcheck_timeout = 30
393 linkcheck_report_timeouts_as_broken = True