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