Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Doc/conf.py
12 views
1
#
2
# Python documentation build configuration file
3
#
4
# This file is execfile()d with the current directory set to its containing dir.
5
#
6
# The contents of this file are pickled, so don't put values in the namespace
7
# that aren't pickleable (module imports are okay, they're removed automatically).
8
9
import sys, os, time
10
sys.path.append(os.path.abspath('tools/extensions'))
11
sys.path.append(os.path.abspath('includes'))
12
13
# General configuration
14
# ---------------------
15
16
extensions = [
17
'asdl_highlight',
18
'c_annotations',
19
'escape4chm',
20
'glossary_search',
21
'peg_highlight',
22
'pyspecific',
23
'sphinx.ext.coverage',
24
'sphinx.ext.doctest',
25
]
26
27
# Skip if downstream redistributors haven't installed it
28
try:
29
import sphinxext.opengraph
30
except ImportError:
31
pass
32
else:
33
extensions.append('sphinxext.opengraph')
34
35
36
doctest_global_setup = '''
37
try:
38
import _tkinter
39
except ImportError:
40
_tkinter = None
41
# Treat warnings as errors, done here to prevent warnings in Sphinx code from
42
# causing spurious test failures.
43
import warnings
44
warnings.simplefilter('error')
45
del warnings
46
'''
47
48
manpages_url = 'https://manpages.debian.org/{path}'
49
50
# General substitutions.
51
project = 'Python'
52
copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
53
54
# We look for the Include/patchlevel.h file in the current Python source tree
55
# and replace the values accordingly.
56
import patchlevel
57
version, release = patchlevel.get_version_info()
58
59
# There are two options for replacing |today|: either, you set today to some
60
# non-false value, then it is used:
61
today = ''
62
# Else, today_fmt is used as the format for a strftime call.
63
today_fmt = '%B %d, %Y'
64
65
# By default, highlight as Python 3.
66
highlight_language = 'python3'
67
68
# Minimum version of sphinx required
69
needs_sphinx = '3.2'
70
71
# Ignore any .rst files in the includes/ directory;
72
# they're embedded in pages but not rendered individually.
73
# Ignore any .rst files in the venv/ directory.
74
exclude_patterns = ['includes/*.rst', 'venv/*', 'README.rst']
75
venvdir = os.getenv('VENVDIR')
76
if venvdir is not None:
77
exclude_patterns.append(venvdir + '/*')
78
79
nitpick_ignore = [
80
# Do not error nit-picky mode builds when _SubParsersAction.add_parser cannot
81
# be resolved, as the method is currently undocumented. For context, see
82
# https://github.com/python/cpython/pull/103289.
83
('py:meth', '_SubParsersAction.add_parser'),
84
]
85
86
# Disable Docutils smartquotes for several translations
87
smartquotes_excludes = {
88
'languages': ['ja', 'fr', 'zh_TW', 'zh_CN'], 'builders': ['man', 'text'],
89
}
90
91
# Avoid a warning with Sphinx >= 2.0
92
master_doc = 'contents'
93
94
# Allow translation of index directives
95
gettext_additional_targets = [
96
'index',
97
]
98
99
# Options for HTML output
100
# -----------------------
101
102
# Use our custom theme.
103
html_theme = 'python_docs_theme'
104
html_theme_path = ['tools']
105
html_theme_options = {
106
'collapsiblesidebar': True,
107
'issues_url': '/bugs.html',
108
'license_url': '/license.html',
109
'root_include_title': False # We use the version switcher instead.
110
}
111
112
# Override stylesheet fingerprinting for Windows CHM htmlhelp to fix GH-91207
113
# https://github.com/python/cpython/issues/91207
114
if any('htmlhelp' in arg for arg in sys.argv):
115
html_style = 'pydoctheme.css'
116
print("\nWARNING: Windows CHM Help is no longer supported.")
117
print("It may be removed in the future\n")
118
119
# Short title used e.g. for <title> HTML tags.
120
html_short_title = '%s Documentation' % release
121
122
# Deployment preview information
123
# (See .readthedocs.yml and https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
124
repository_url = os.getenv("READTHEDOCS_GIT_CLONE_URL")
125
html_context = {
126
"is_deployment_preview": os.getenv("READTHEDOCS_VERSION_TYPE") == "external",
127
"repository_url": repository_url.removesuffix(".git") if repository_url else None,
128
"pr_id": os.getenv("READTHEDOCS_VERSION")
129
}
130
131
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
132
# using the given strftime format.
133
html_last_updated_fmt = '%b %d, %Y'
134
135
# Path to find HTML templates.
136
templates_path = ['tools/templates']
137
138
# Custom sidebar templates, filenames relative to this file.
139
html_sidebars = {
140
# Defaults taken from https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars
141
# Removes the quick search block
142
'**': ['localtoc.html', 'relations.html', 'customsourcelink.html'],
143
'index': ['indexsidebar.html'],
144
}
145
146
# Additional templates that should be rendered to pages.
147
html_additional_pages = {
148
'download': 'download.html',
149
'index': 'indexcontent.html',
150
}
151
152
# Output an OpenSearch description file.
153
html_use_opensearch = 'https://docs.python.org/' + version
154
155
# Additional static files.
156
html_static_path = ['_static', 'tools/static']
157
158
# Output file base name for HTML help builder.
159
htmlhelp_basename = 'python' + release.replace('.', '')
160
161
# Split the index
162
html_split_index = True
163
164
165
# Options for LaTeX output
166
# ------------------------
167
168
latex_engine = 'xelatex'
169
170
# Get LaTeX to handle Unicode correctly
171
latex_elements = {
172
}
173
174
# Additional stuff for the LaTeX preamble.
175
latex_elements['preamble'] = r'''
176
\authoraddress{
177
\sphinxstrong{Python Software Foundation}\\
178
Email: \sphinxemail{[email protected]}
179
}
180
\let\Verbatim=\OriginalVerbatim
181
\let\endVerbatim=\endOriginalVerbatim
182
\setcounter{tocdepth}{2}
183
'''
184
185
# The paper size ('letter' or 'a4').
186
latex_elements['papersize'] = 'a4'
187
188
# The font size ('10pt', '11pt' or '12pt').
189
latex_elements['pointsize'] = '10pt'
190
191
# Grouping the document tree into LaTeX files. List of tuples
192
# (source start file, target name, title, author, document class [howto/manual]).
193
_stdauthor = 'Guido van Rossum and the Python development team'
194
latex_documents = [
195
('c-api/index', 'c-api.tex',
196
'The Python/C API', _stdauthor, 'manual'),
197
('distributing/index', 'distributing.tex',
198
'Distributing Python Modules', _stdauthor, 'manual'),
199
('extending/index', 'extending.tex',
200
'Extending and Embedding Python', _stdauthor, 'manual'),
201
('installing/index', 'installing.tex',
202
'Installing Python Modules', _stdauthor, 'manual'),
203
('library/index', 'library.tex',
204
'The Python Library Reference', _stdauthor, 'manual'),
205
('reference/index', 'reference.tex',
206
'The Python Language Reference', _stdauthor, 'manual'),
207
('tutorial/index', 'tutorial.tex',
208
'Python Tutorial', _stdauthor, 'manual'),
209
('using/index', 'using.tex',
210
'Python Setup and Usage', _stdauthor, 'manual'),
211
('faq/index', 'faq.tex',
212
'Python Frequently Asked Questions', _stdauthor, 'manual'),
213
('whatsnew/' + version, 'whatsnew.tex',
214
'What\'s New in Python', 'A. M. Kuchling', 'howto'),
215
]
216
# Collect all HOWTOs individually
217
latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex',
218
'', _stdauthor, 'howto')
219
for fn in os.listdir('howto')
220
if fn.endswith('.rst') and fn != 'index.rst')
221
222
# Documents to append as an appendix to all manuals.
223
latex_appendices = ['glossary', 'about', 'license', 'copyright']
224
225
# Options for Epub output
226
# -----------------------
227
228
epub_author = 'Python Documentation Authors'
229
epub_publisher = 'Python Software Foundation'
230
231
# Options for the coverage checker
232
# --------------------------------
233
234
# The coverage checker will ignore all modules/functions/classes whose names
235
# match any of the following regexes (using re.match).
236
coverage_ignore_modules = [
237
r'[T|t][k|K]',
238
]
239
240
coverage_ignore_functions = [
241
'test($|_)',
242
]
243
244
coverage_ignore_classes = [
245
]
246
247
# Glob patterns for C source files for C API coverage, relative to this directory.
248
coverage_c_path = [
249
'../Include/*.h',
250
]
251
252
# Regexes to find C items in the source files.
253
coverage_c_regexes = {
254
'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
255
'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
256
'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
257
}
258
259
# The coverage checker will ignore all C items whose names match these regexes
260
# (using re.match) -- the keys must be the same as in coverage_c_regexes.
261
coverage_ignore_c_items = {
262
# 'cfunction': [...]
263
}
264
265
266
# Options for the link checker
267
# ----------------------------
268
269
linkcheck_allowed_redirects = {
270
# bpo-NNNN -> BPO -> GH Issues
271
r'https://bugs.python.org/issue\?@action=redirect&bpo=\d+': r'https://github.com/python/cpython/issues/\d+',
272
# GH-NNNN used to refer to pull requests
273
r'https://github.com/python/cpython/issues/\d+': r'https://github.com/python/cpython/pull/\d+',
274
# :source:`something` linking files in the repository
275
r'https://github.com/python/cpython/tree/.*': 'https://github.com/python/cpython/blob/.*',
276
# Intentional HTTP use at Misc/NEWS.d/3.5.0a1.rst
277
r'http://www.python.org/$': 'https://www.python.org/$',
278
# Used in license page, keep as is
279
r'https://www.zope.org/': r'https://www.zope.dev/',
280
# Microsoft's redirects to learn.microsoft.com
281
r'https://msdn.microsoft.com/.*': 'https://learn.microsoft.com/.*',
282
r'https://docs.microsoft.com/.*': 'https://learn.microsoft.com/.*',
283
r'https://go.microsoft.com/fwlink/\?LinkID=\d+': 'https://learn.microsoft.com/.*',
284
# Language redirects
285
r'https://toml.io': 'https://toml.io/en/',
286
r'https://www.redhat.com': 'https://www.redhat.com/en',
287
# Other redirects
288
r'https://www.boost.org/libs/.+': r'https://www.boost.org/doc/libs/\d_\d+_\d/.+',
289
r'https://support.microsoft.com/en-us/help/\d+': 'https://support.microsoft.com/en-us/topic/.+',
290
r'https://perf.wiki.kernel.org$': 'https://perf.wiki.kernel.org/index.php/Main_Page',
291
r'https://www.sqlite.org': 'https://www.sqlite.org/index.html',
292
r'https://mitpress.mit.edu/sicp$': 'https://mitpress.mit.edu/9780262510875/structure-and-interpretation-of-computer-programs/',
293
r'https://www.python.org/psf/': 'https://www.python.org/psf-landing/',
294
}
295
296
linkcheck_anchors_ignore = [
297
# ignore anchors that start with a '/', e.g. Wikipedia media files:
298
# https://en.wikipedia.org/wiki/Walrus#/media/File:Pacific_Walrus_-_Bull_(8247646168).jpg
299
r'\/.*',
300
]
301
302
linkcheck_ignore = [
303
# The crawler gets "Anchor not found"
304
r'https://developer.apple.com/documentation/.+?#.*',
305
r'https://devguide.python.org.+?/#.*',
306
r'https://github.com.+?#.*',
307
# Robot crawlers not allowed: "403 Client Error: Forbidden"
308
r'https://support.enthought.com/hc/.*',
309
# SSLError CertificateError, even though it is valid
310
r'https://unix.org/version2/whatsnew/lp64_wp.html',
311
]
312
313
314
# Options for extensions
315
# ----------------------
316
317
# Relative filename of the data files
318
refcount_file = 'data/refcounts.dat'
319
stable_abi_file = 'data/stable_abi.dat'
320
321
# sphinxext-opengraph config
322
ogp_site_url = 'https://docs.python.org/3/'
323
ogp_site_name = 'Python documentation'
324
ogp_image = '_static/og-image.png'
325
ogp_custom_meta_tags = [
326
'<meta property="og:image:width" content="200" />',
327
'<meta property="og:image:height" content="200" />',
328
'<meta name="theme-color" content="#3776ab" />',
329
]
330
331