Debian Codegraph @

docs/source/conf.py

raw symbols SCIP
1 """Configuration file for the Sphinx documentation builder."""
2
3 from __future__ import annotations
4
5 import datetime
6 import os
7 import re
8 import typing as t
9 from importlib.metadata import metadata
10 from importlib.util import find_spec
11 from pathlib import Path
12
13 import sphinx_rtd_theme # type: ignore[import-untyped]
14
15 if t.TYPE_CHECKING:
16 from sphinx.application import Sphinx
17
18
19 needs_sphinx = "3.1" #: Minimum Sphinx version to build the docs
20
21
22 #: -- GLOB VARS ------------------------------------------------------------------------
23 NOT_LOADED_MSGS = []
24
25
26 #: -- PROJECT INFORMATION --------------------------------------------------------------
27 project = "rstcheck"
28 author = "Steven Myint <[email protected]>"
29 GH_REPO_LINK = "https://github.com/rstcheck/rstcheck"
30 CREATION_YEAR = 2013
31 CURRENT_YEAR = f"{datetime.datetime.now(tz=datetime.UTC).date().year}"
32 copyright = ( # noqa: A001
33 f"{CREATION_YEAR}{('-' + CURRENT_YEAR) if CURRENT_YEAR != CREATION_YEAR else ''}, "
34 f"{author} and AUTHORS"
35 )
36 RSTCHECK_VERSION = metadata(project)["Version"]
37 release = RSTCHECK_VERSION #: The full version, including alpha/beta/rc tags
38 version_parts = re.search(r"^v?(?P<version>\d+\.\d+)\.\d+[-.]?(?P<tag>[a-z]*)[\.]?\d*", release)
39 #: Major + Minor version like (X.Y)
40 version = None if not version_parts else version_parts.group("version")
41 #: only tags like alpha/beta/rc
42 RELEASE_LEVEL = None if not version_parts else version_parts.group("tag")
43
44
45 #: -- GENERAL CONFIG -------------------------------------------------------------------
46 extensions: list[str] = []
47 today_fmt = "%Y-%m-%d"
48 exclude_patterns: list[str] = [] #: Files to exclude for source of doc
49
50 #: Added dirs for static and template files if they exist
51 html_static_path = ["_static"] if Path("_static").exists() else []
52 templates_path = ["_templates"] if Path("_templates").exists() else []
53
54 rst_prolog = """
55 .. ifconfig:: RELEASE_LEVEL in ('alpha', 'beta', 'rc')
56
57 .. warning::
58 The here documented release |release| is a pre-release.
59 Keep in mind that breaking changes can occur till the final release.
60
61 You may want to use the latest stable release instead.
62 """
63
64 rst_epilog = """
65 .. |br| raw:: html
66
67 <br/>
68 """
69
70 tls_cacerts = os.getenv("SSL_CERT_FILE")
71
72
73 #: -- MyST -----------------------------------------------------------------------------
74 extensions.append("myst_parser")
75 source_suffix = {
76 ".rst": "restructuredtext",
77 ".txt": "markdown",
78 ".md": "markdown",
79 }
80
81
82 #: -- LINKCHECK CONFIG -----------------------------------------------------------------
83 #: 1 Worker 5 Retries to fix 429 error
84 linkcheck_workers = 1
85 linkcheck_retries = 5
86 linkcheck_timeout = 30
87
88
89 #: -- DEFAULT EXTENSIONS ---------------------------------------------------------------
90 #: Global
91 extensions.append("sphinx.ext.duration")
92 extensions.append("sphinx.ext.coverage") #: sphinx-build -b coverage ...
93 coverage_write_headline = False
94 coverage_show_missing_items = True
95 extensions.append("sphinx.ext.doctest") #: sphinx-build -b doctest ...
96
97 #: ReStructuredText
98 extensions.append("sphinx.ext.autosectionlabel")
99 autosectionlabel_prefix_document = True
100 autosectionlabel_maxdepth = 2
101 extensions.append("sphinx.ext.ifconfig")
102 extensions.append("sphinx.ext.viewcode")
103
104 #: Links
105 extensions.append("sphinx.ext.intersphinx")
106 # NOTE: to inspect .inv files: https://github.com/bskinn/sphobjinv
107 intersphinx_mapping = {
108 "python": ("https://docs.python.org/3/", None),
109 "pattern": ("https://docs.python.org/3/library/", "objects.pattern.inv"),
110 }
111
112 extensions.append("sphinx.ext.extlinks")
113 extlinks = {
114 "repo": (f"{GH_REPO_LINK}/%s", "Repo's %s"),
115 "issue": (f"{GH_REPO_LINK}/issues/%s", "#%s"),
116 "pull": (f"{GH_REPO_LINK}/pull/%s", "PR#%s"),
117 "user": ("https://github.com/%s", "@%s"),
118 }
119
120
121 #: -- CLICK ----------------------------------------------------------------------------
122 extensions.append("sphinx_click.ext")
123
124
125 #: -- SPELLING -------------------------------------------------------------------------
126 spelling_word_list_filename = "../../spelling_dict.txt"
127 spelling_show_suggestions = True
128
129 if find_spec("sphinxcontrib.spelling") is not None and os.environ.get("SPHINX_SPELLING") == "true":
130 extensions.append("sphinxcontrib.spelling")
131 else:
132 NOT_LOADED_MSGS.append("## 'sphinxcontrib-spelling' extension not loaded - not installed")
133
134
135 #: -- HTML THEME -----------------------------------------------------------------------
136 #: needs install: "sphinx-rtd-theme"
137 extensions.append("sphinx_rtd_theme")
138 html_theme = "sphinx_rtd_theme"
139 html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
140 html_theme_options = {"style_external_links": True, "navigation_depth": 5}
141
142
143 #: -- HTML OUTPUT ----------------------------------------------------------------------
144 html_last_updated_fmt = today_fmt
145 html_show_sourcelink = True #: Add links to *.rst source files on HTML pages
146
147
148 #: -- FINAL SETUP ----------------------------------------------------------------------
149 def setup(app: Sphinx) -> None:
150 """Connect custom func to sphinx events."""
151 app.add_config_value("RELEASE_LEVEL", "", "env")
152
153
154 for msg in NOT_LOADED_MSGS:
155 print(msg) # noqa: T201