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