| 1 |
# Sphinx documentation build configuration file |
| 2 |
from __future__ import annotations |
| 3 |
|
| 4 |
import os |
| 5 |
import re |
| 6 |
from typing import TYPE_CHECKING |
| 7 |
|
| 8 |
from sphinx import __display_version__ |
| 9 |
|
| 10 |
os.environ['SPHINX_AUTODOC_RELOAD_MODULES'] = '1' |
| 11 |
|
| 12 |
extensions = [ |
| 13 |
'sphinx.ext.autodoc', |
| 14 |
'sphinx.ext.doctest', |
| 15 |
'sphinx.ext.todo', |
| 16 |
'sphinx.ext.autosummary', |
| 17 |
'sphinx.ext.extlinks', |
| 18 |
'sphinx.ext.intersphinx', |
| 19 |
'sphinx.ext.viewcode', |
| 20 |
'sphinx.ext.inheritance_diagram', |
| 21 |
'sphinx.ext.coverage', |
| 22 |
'sphinx.ext.graphviz', |
| 23 |
] |
| 24 |
coverage_statistics_to_report = coverage_statistics_to_stdout = True |
| 25 |
templates_path = ['_templates'] |
| 26 |
exclude_patterns = ['_build'] |
| 27 |
|
| 28 |
project = 'Sphinx' |
| 29 |
copyright = '2007-%Y, the Sphinx developers' |
| 30 |
release = version = __display_version__ |
| 31 |
show_authors = True |
| 32 |
nitpicky = True |
| 33 |
show_warning_types = True |
| 34 |
|
| 35 |
html_theme = 'sphinx13' |
| 36 |
html_theme_path = ['_themes'] |
| 37 |
html_css_files = [ |
| 38 |
# 'basic.css', # included through inheritance from the basic theme |
| 39 |
'sphinx13.css', |
| 40 |
] |
| 41 |
modindex_common_prefix = ['sphinx.'] |
| 42 |
html_static_path = ['_static'] |
| 43 |
html_title = 'Sphinx documentation' |
| 44 |
html_additional_pages = {'contents': 'contents.html'} |
| 45 |
html_use_opensearch = 'https://www.sphinx-doc.org/en/master' |
| 46 |
html_baseurl = 'https://www.sphinx-doc.org/en/master/' |
| 47 |
html_favicon = '_static/favicon.svg' |
| 48 |
|
| 49 |
htmlhelp_basename = 'Sphinxdoc' |
| 50 |
|
| 51 |
epub_theme = 'epub' |
| 52 |
epub_basename = 'sphinx' |
| 53 |
epub_author = 'the Sphinx developers' |
| 54 |
epub_publisher = 'https://www.sphinx-doc.org/' |
| 55 |
epub_uid = 'web-site' |
| 56 |
epub_scheme = 'url' |
| 57 |
epub_identifier = epub_publisher |
| 58 |
epub_pre_files = [('index.xhtml', 'Welcome')] |
| 59 |
epub_post_files = [ |
| 60 |
('usage/installation.xhtml', 'Installing Sphinx'), |
| 61 |
('develop.xhtml', 'Sphinx development'), |
| 62 |
] |
| 63 |
epub_exclude_files = [ |
| 64 |
'_static/opensearch.xml', |
| 65 |
'_static/doctools.js', |
| 66 |
'_static/searchtools.js', |
| 67 |
'_static/sphinx_highlight.js', |
| 68 |
'_static/basic.css', |
| 69 |
'_static/language_data.js', |
| 70 |
'search.html', |
| 71 |
'_static/websupport.js', |
| 72 |
] |
| 73 |
epub_fix_images = False |
| 74 |
epub_max_image_width = 0 |
| 75 |
epub_show_urls = 'inline' |
| 76 |
epub_use_index = False |
| 77 |
epub_description = 'Sphinx documentation generator system manual' |
| 78 |
|
| 79 |
latex_documents = [ |
| 80 |
( |
| 81 |
'index', |
| 82 |
'sphinx.tex', |
| 83 |
'Sphinx Documentation', |
| 84 |
'the Sphinx developers', |
| 85 |
'manual', |
| 86 |
1, |
| 87 |
) |
| 88 |
] |
| 89 |
latex_logo = '_static/sphinx.png' |
| 90 |
latex_elements = { |
| 91 |
'fontenc': r'\usepackage[LGR,X2,T1]{fontenc}', |
| 92 |
'passoptionstopackages': r""" |
| 93 |
\PassOptionsToPackage{svgnames}{xcolor} |
| 94 |
""", |
| 95 |
'preamble': r""" |
| 96 |
\DeclareUnicodeCharacter{229E}{\ensuremath{\boxplus}} |
| 97 |
\setcounter{tocdepth}{3}% depth of what main TOC shows (3=subsubsection) |
| 98 |
\setcounter{secnumdepth}{1}% depth of section numbering |
| 99 |
\setlength{\tymin}{2cm}% avoid too cramped table columns |
| 100 |
""", |
| 101 |
# fix missing index entry due to RTD doing only once pdflatex after makeindex |
| 102 |
'printindex': r""" |
| 103 |
\IfFileExists{\jobname.ind} |
| 104 |
{\footnotesize\raggedright\printindex} |
| 105 |
{\begin{sphinxtheindex}\end{sphinxtheindex}} |
| 106 |
""", |
| 107 |
} |
| 108 |
latex_show_urls = 'footnote' |
| 109 |
latex_use_xindy = True |
| 110 |
|
| 111 |
linkcheck_timeout = 5 |
| 112 |
linkcheck_ignore = [ |
| 113 |
r'^contents\.html$', # extra generated page |
| 114 |
r'^\.\./contents\.html$', |
| 115 |
re.escape('https://gitlab.com/projects/new'), # requires sign-in |
| 116 |
re.escape('https://web.libera.chat/?channel=#sphinx-doc'), |
| 117 |
] |
| 118 |
linkcheck_anchors_ignore_for_url = [ |
| 119 |
# anchors in Markdown files cannot be accessed directly |
| 120 |
'https://github.com/Khan/style-guides/blob/master/style/python.md', |
| 121 |
] |
| 122 |
|
| 123 |
autodoc_member_order = 'groupwise' |
| 124 |
autosummary_generate = False |
| 125 |
todo_include_todos = 'READTHEDOCS' not in os.environ |
| 126 |
extlinks = { |
| 127 |
'dupage': ('https://docutils.sourceforge.io/docs/ref/rst/%s.html', '%s'), |
| 128 |
'duref': ( |
| 129 |
'https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#%s', |
| 130 |
'%s', |
| 131 |
), |
| 132 |
'durole': ('https://docutils.sourceforge.io/docs/ref/rst/roles.html#%s', '%s'), |
| 133 |
'dudir': ('https://docutils.sourceforge.io/docs/ref/rst/directives.html#%s', '%s'), |
| 134 |
} |
| 135 |
|
| 136 |
man_pages = [ |
| 137 |
( |
| 138 |
'index', |
| 139 |
'sphinx-all', |
| 140 |
'Sphinx documentation generator system manual', |
| 141 |
'the Sphinx developers', |
| 142 |
1, |
| 143 |
), |
| 144 |
('man/sphinx-build', 'sphinx-build', 'Sphinx documentation generator tool', '', 1), |
| 145 |
( |
| 146 |
'man/sphinx-quickstart', |
| 147 |
'sphinx-quickstart', |
| 148 |
'Sphinx documentation template generator', |
| 149 |
'', |
| 150 |
1, |
| 151 |
), |
| 152 |
('man/sphinx-apidoc', 'sphinx-apidoc', 'Sphinx API doc generator tool', '', 1), |
| 153 |
('man/sphinx-autogen', 'sphinx-autogen', 'Generate autodoc stub pages', '', 1), |
| 154 |
] |
| 155 |
|
| 156 |
texinfo_documents = [ |
| 157 |
( |
| 158 |
'index', |
| 159 |
'sphinx', |
| 160 |
'Sphinx Documentation', |
| 161 |
'the Sphinx developers', |
| 162 |
'Sphinx', |
| 163 |
'The Sphinx documentation builder.', |
| 164 |
'Documentation tools', |
| 165 |
True, |
| 166 |
), |
| 167 |
] |
| 168 |
|
| 169 |
intersphinx_mapping = { |
| •170 |
'python': ('/usr/share/doc/python3-doc/html', None), |
| 171 |
'requests': ('/usr/share/doc/python-requests-doc/html', None), |
| 172 |
} |
| 173 |
|
| 174 |
# Sphinx document translation with sphinx gettext feature uses these settings: |
| 175 |
gettext_compact = False |
| 176 |
|
| 177 |
nitpick_ignore = { |
| 178 |
( |
| 179 |
'cpp:class', |
| 180 |
'template<typename TOuter> template<typename TInner> Wrapper::Outer<TOuter>::Inner', |
| 181 |
), |
| 182 |
('cpp:identifier', 'MyContainer'), |
| 183 |
('js:class', 'SomeError'), |
| 184 |
('js:class', 'number'), |
| 185 |
('js:class', 'string'), |
| 186 |
('py:attr', 'srcline'), |
| 187 |
# sphinx.application.Sphinx.connect |
| 188 |
('py:class', '_AutodocProcessDocstringListener'), |
| 189 |
# sphinx.application.Sphinx.connect |
| 190 |
('py:class', '_AutodocBeforeProcessSignatureListener'), |
| 191 |
# sphinx.application.Sphinx.connect |
| 192 |
('py:class', '_AutodocProcessSignatureListener'), |
| 193 |
('py:class', '_AutodocProcessBasesListener'), # sphinx.application.Sphinx.connect |
| 194 |
('py:class', '_AutodocSkipMemberListener'), # sphinx.application.Sphinx.connect |
| 195 |
('py:class', '_ConfigRebuild'), # sphinx.application.Sphinx.add_config_value |
| 196 |
# sphinx.application.Sphinx.add_html_math_renderer |
| 197 |
('py:class', '_MathsBlockRenderers'), |
| 198 |
# sphinx.application.Sphinx.add_html_math_renderer |
| 199 |
('py:class', '_MathsInlineRenderers'), |
| 200 |
('py:class', '_NodeHandler'), # sphinx.application.Sphinx.add_enumerable_node |
| 201 |
('py:class', '_NodeHandlerPair'), # sphinx.application.Sphinx.add_node |
| 202 |
('py:class', '_StrPath'), # sphinx.environment.BuildEnvironment.doc2path |
| 203 |
('py:class', 'Element'), # sphinx.domains.Domain |
| 204 |
('py:class', 'Documenter'), # sphinx.application.Sphinx.add_autodocumenter |
| 205 |
('py:class', 'Field'), # sphinx.application.Sphinx.add_object_type |
| 206 |
('py:class', 'IndexEntry'), # sphinx.domains.IndexEntry |
| 207 |
('py:class', 'Inliner'), # sphinx.util.docutils.SphinxRole.inliner |
| 208 |
('py:class', 'Lexer'), # sphinx.application.Sphinx.add_lexer |
| 209 |
('py:class', 'Node'), # sphinx.domains.Domain |
| 210 |
('py:class', 'NullTranslations'), # gettext.NullTranslations |
| 211 |
('py:class', 'ObjDescT'), # sphinx.directives.ObjectDescription |
| 212 |
('py:class', 'OptionSpec'), # sphinx.directives.ObjectDescription.option_spec |
| 213 |
('py:class', 'Path'), # sphinx.application.Sphinx.connect |
| 214 |
('py:class', 'RoleFunction'), # sphinx.domains.Domain |
| 215 |
('py:class', 'RSTState'), # sphinx.utils.parsing.nested_parse_to_nodes |
| 216 |
('py:class', 'SearchLanguage'), # sphinx.application.Sphinx.add_search_language |
| 217 |
('py:class', 'StringList'), # sphinx.utils.parsing.nested_parse_to_nodes |
| 218 |
('py:class', 'system_message'), # sphinx.utils.docutils.SphinxDirective |
| 219 |
('py:class', 'Theme'), # sphinx.application.TemplateBridge |
| 220 |
('py:class', 'TitleGetter'), # sphinx.domains.Domain |
| 221 |
('py:class', 'todo_node'), # sphinx.application.Sphinx.connect |
| 222 |
('py:class', 'Transform'), # sphinx.application.Sphinx.add_transform |
| 223 |
('py:class', 'XRefRole'), # sphinx.domains.Domain |
| 224 |
('py:class', 'docutils.nodes.Element'), |
| 225 |
('py:class', 'docutils.nodes.Node'), |
| 226 |
('py:class', 'docutils.nodes.NodeVisitor'), |
| 227 |
('py:class', 'docutils.nodes.TextElement'), |
| 228 |
('py:class', 'docutils.nodes.document'), |
| 229 |
('py:class', 'docutils.nodes.system_message'), |
| 230 |
('py:class', 'docutils.parsers.Parser'), |
| 231 |
('py:class', 'docutils.parsers.rst.states.Inliner'), |
| 232 |
('py:class', 'docutils.transforms.Transform'), |
| 233 |
('py:class', 'nodes.NodeVisitor'), |
| 234 |
('py:class', 'nodes.TextElement'), # sphinx.application.Sphinx.connect |
| 235 |
('py:class', 'nodes.document'), |
| 236 |
('py:class', 'nodes.reference'), |
| 237 |
('py:class', 'pygments.lexer.Lexer'), |
| 238 |
('py:class', 'sphinx.directives.ObjDescT'), |
| 239 |
('py:class', 'sphinx.domains.IndexEntry'), |
| 240 |
# sphinx.application.Sphinx.add_autodocumenter |
| 241 |
('py:class', 'sphinx.ext.autodoc.Documenter'), |
| 242 |
('py:class', 'sphinx.errors.NoUri'), |
| 243 |
('py:class', 'sphinx.roles.XRefRole'), |
| 244 |
('py:class', 'sphinx.search.SearchLanguage'), |
| 245 |
('py:class', 'sphinx.theming.Theme'), |
| 246 |
('py:class', 'sphinx.util._pathlib._StrPath'), # sphinx.project.Project.doc2path |
| 247 |
('py:class', 'sphinxcontrib.websupport.errors.DocumentNotFoundError'), |
| 248 |
('py:class', 'sphinxcontrib.websupport.errors.UserNotAuthorizedError'), |
| 249 |
('py:exc', 'docutils.nodes.SkipNode'), |
| 250 |
('py:exc', 'sphinx.environment.NoUri'), |
| 251 |
('py:func', 'setup'), |
| 252 |
('py:func', 'sphinx.util.nodes.nested_parse_with_titles'), |
| 253 |
# Error in sphinxcontrib.websupport.core::WebSupport.add_comment |
| 254 |
('py:meth', 'get_comments'), |
| 255 |
('py:mod', 'autodoc'), |
| 256 |
('py:mod', 'docutils.nodes'), |
| 257 |
('py:mod', 'docutils.parsers.rst.directives'), |
| 258 |
('py:mod', 'sphinx.ext'), |
| 259 |
('py:obj', 'sphinx.util.relative_uri'), |
| 260 |
('rst:role', 'c:any'), |
| 261 |
('std:confval', 'autodoc_inherit_docstring'), |
| 262 |
('std:confval', 'automodule_skip_lines'), |
| 263 |
('std:confval', 'autossummary_imported_members'), |
| 264 |
('std:confval', 'gettext_language_team'), |
| 265 |
('std:confval', 'gettext_last_translator'), |
| 266 |
('std:confval', 'globaltoc_collapse'), |
| 267 |
('std:confval', 'globaltoc_includehidden'), |
| 268 |
('std:confval', 'globaltoc_maxdepth'), |
| 269 |
} |
| 270 |
|
| •271 |
mathjax_path = 'file:///usr/share/nodejs/mathjax-full/es5/tex-mml-chtml.js' |
| 272 |
|
| 273 |
# -- Extension interface ------------------------------------------------------- |
| 274 |
|
| 275 |
from sphinx import addnodes # NoQA: E402 |
| 276 |
|
| 277 |
if TYPE_CHECKING: |
| 278 |
from pathlib import Path |
| 279 |
|
| 280 |
from docutils.nodes import Element |
| 281 |
|
| 282 |
from sphinx.application import Sphinx |
| 283 |
from sphinx.environment import BuildEnvironment |
| 284 |
|
| 285 |
_event_sig_re = re.compile(r'([a-zA-Z-]+)\s*\((.*)\)') |
| 286 |
|
| 287 |
|
| 288 |
def parse_event(_env: BuildEnvironment, sig: str, signode: Element) -> str: |
| 289 |
m = _event_sig_re.match(sig) |
| 290 |
if m is None: |
| 291 |
signode += addnodes.desc_name(sig, sig) |
| 292 |
return sig |
| 293 |
name, args = m.groups() |
| 294 |
signode += addnodes.desc_name(name, name) |
| 295 |
plist = addnodes.desc_parameterlist() |
| 296 |
for arg in args.split(','): |
| 297 |
arg = arg.strip() |
| 298 |
plist += addnodes.desc_parameter(arg, arg) |
| 299 |
signode += plist |
| 300 |
return name |
| 301 |
|
| 302 |
|
| 303 |
def linkify_issues_in_changelog( |
| 304 |
_app: Sphinx, _path: Path, docname: str, source: list[str] |
| 305 |
) -> None: |
| 306 |
"""Linkify issue references like #123 in changelog to GitHub.""" |
| 307 |
if docname == 'changes': |
| 308 |
linkified_changelog = re.sub(r'(?:PR)?#([0-9]+)\b', _linkify, source[0]) |
| 309 |
source[0] = linkified_changelog |
| 310 |
|
| 311 |
|
| 312 |
def _linkify(match: re.Match[str], /) -> str: |
| 313 |
return f'`{match[0]} <https://github.com/sphinx-doc/sphinx/issues/{match[1]}>`__' |
| 314 |
|
| 315 |
|
| 316 |
REDIRECT_TEMPLATE = """ |
| 317 |
<html> |
| 318 |
<head> |
| 319 |
<noscript> |
| 320 |
<meta http-equiv="refresh" content="0; url={{rel_url}}"/> |
| 321 |
</noscript> |
| 322 |
</head> |
| 323 |
<body> |
| 324 |
<script> |
| 325 |
window.location.href = '{{rel_url}}' + (window.location.search || '') + (window.location.hash || ''); |
| 326 |
</script> |
| 327 |
<p>You should have been redirected.</p> |
| 328 |
<a href="{{rel_url}}">If not, click here to continue.</a> |
| 329 |
</body> |
| 330 |
</html> |
| 331 |
""" # NoQA: E501 |
| 332 |
|
| 333 |
|
| 334 |
def build_redirects(app: Sphinx, exception: Exception | None) -> None: |
| 335 |
# this is a very simple implementation of |
| 336 |
# https://github.com/wpilibsuite/sphinxext-rediraffe/blob/main/sphinxext/rediraffe.py |
| 337 |
# to re-direct some old pages to new ones |
| 338 |
if exception is not None or app.builder.name != 'html': |
| 339 |
return |
| 340 |
for page, rel_redirect in ( |
| 341 |
(('changes.html',), 'changes/index.html'), |
| 342 |
(('development', 'overview.html'), 'index.html'), |
| 343 |
(('development', 'builders.html'), 'howtos/builders.html'), |
| 344 |
(('development', 'theming.html'), 'html_themes/index.html'), |
| 345 |
(('development', 'templating.html'), 'html_themes/templating.html'), |
| 346 |
(('development', 'tutorials', 'helloworld.html'), 'extending_syntax.html'), |
| 347 |
(('development', 'tutorials', 'todo.html'), 'extending_build.html'), |
| 348 |
(('development', 'tutorials', 'recipe.html'), 'adding_domain.html'), |
| 349 |
): |
| 350 |
path = app.outdir.joinpath(*page) |
| 351 |
if path.exists(): |
| 352 |
continue |
| 353 |
path.parent.mkdir(parents=True, exist_ok=True) |
| 354 |
with path.open('w', encoding='utf-8') as f: |
| 355 |
f.write(REDIRECT_TEMPLATE.replace('{{rel_url}}', rel_redirect)) |
| 356 |
|
| 357 |
|
| 358 |
def setup(app: Sphinx) -> None: |
| 359 |
from sphinx.util.docfields import GroupedField |
| 360 |
|
| 361 |
app.connect('include-read', linkify_issues_in_changelog) |
| 362 |
app.connect('build-finished', build_redirects) |
| 363 |
fdesc = GroupedField( |
| 364 |
'parameter', label='Parameters', names=('param',), can_collapse=True |
| 365 |
) |
| 366 |
app.add_object_type( |
| 367 |
'event', |
| 368 |
'event', |
| 369 |
'pair: %s; event', |
| 370 |
parse_event, |
| 371 |
doc_field_types=[fdesc], |
| 372 |
) |