Debian Codegraph @

docs/conf.py

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #
2 # Configuration file for the Sphinx documentation builder.
3 #
4 # This file does only contain a selection of the most common options. For a
5 # full list see the documentation:
6 # http://www.sphinx-doc.org/en/stable/config
7
8 # -- Path setup --------------------------------------------------------------
9
10 # If extensions (or modules to document with autodoc) are in another directory,
11 # add these directories to sys.path here. If the directory is relative to the
12 # documentation root, use os.path.abspath to make it absolute, like shown here.
13 #
14
15 import os
16 import re
17 import string
18 from importlib.metadata import version
19 from pathlib import Path
20
21 from sphinx.application import Sphinx
22
23 CURRENT_DIR = Path(__file__).parent
24
25
26 def make_pypi_svg(version: str) -> None:
27 template: Path = CURRENT_DIR / "_static" / "pypi_template.svg"
28 target: Path = CURRENT_DIR / "_static" / "pypi.svg"
29 with open(str(template), encoding="utf8") as f:
30 svg: str = string.Template(f.read()).substitute(version=version)
31 with open(str(target), "w", encoding="utf8") as f:
32 f.write(svg)
33
34
35 def replace_pr_numbers_with_links(content: str) -> str:
36 """Replaces all PR numbers with the corresponding GitHub link."""
37 return re.sub(r"#(\d+)", r"[#\1](https://github.com/psf/black/pull/\1)", content)
38
39
40 def handle_include_read(
41 app: Sphinx,
42 relative_path: Path,
43 parent_docname: str,
44 content: list[str],
45 ) -> None:
46 """Handler for the include-read sphinx event."""
47 if parent_docname == "change_log":
48 content[0] = replace_pr_numbers_with_links(content[0])
49
50
51 def setup(app: Sphinx) -> None:
52 """Sets up a minimal sphinx extension."""
53 app.connect("include-read", handle_include_read)
54
55
56 # Necessary so Click doesn't hit an encode error when called by
57 # sphinxcontrib-programoutput on Windows.
58 os.putenv("pythonioencoding", "utf-8")
59
60 # -- Project information -----------------------------------------------------
61
62 project = "Black"
63 copyright = "2018-Present, Łukasz Langa and contributors to Black"
64 author = "Łukasz Langa and contributors to Black"
65
66 # Autopopulate version
67 # The version, including alpha/beta/rc tags, but not commit hash and datestamps
68 release = version("black").split("+")[0]
69 # The short X.Y version.
70 version = release
71 for sp in "abcfr":
72 version = version.split(sp)[0]
73
74 make_pypi_svg(release)
75
76
77 # -- General configuration ---------------------------------------------------
78
79 # Add any Sphinx extension module names here, as strings. They can be
80 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
81 # ones.
82 extensions = [
83 "sphinx.ext.autodoc",
84 "sphinx.ext.intersphinx",
85 "sphinx.ext.napoleon",
86 "myst_parser",
87 "sphinxcontrib.programoutput",
88 "sphinx_copybutton",
89 ]
90
91 # Add any paths that contain templates here, relative to this directory.
92 templates_path = ["_templates"]
93
94 # The suffix(es) of source filenames.
95 # You can specify multiple suffix as a list of string:
96 source_suffix = [".rst", ".md"]
97
98 # The master toctree document.
99 master_doc = "index"
100
101 # The language for content autogenerated by Sphinx. Refer to documentation
102 # for a list of supported languages.
103 #
104 # This is also used if you do content translation via gettext catalogs.
105 # Usually you set "language" from the command line for these cases.
106 language = "en"
107
108 # List of patterns, relative to source directory, that match files and
109 # directories to ignore when looking for source files.
110 # This pattern also affects html_static_path and html_extra_path .
111
112 exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
113
114 # The name of the Pygments (syntax highlighting) style to use.
115 pygments_style = "sphinx"
116
117 # We need headers to be linkable to so ask MyST-Parser to autogenerate anchor IDs for
118 # headers up to and including level 3.
119 myst_heading_anchors = 3
120
121 # Prettier support formatting some MyST syntax but not all, so let's disable the
122 # unsupported yet still enabled by default ones.
123 myst_disable_syntax = [
124 "colon_fence",
125 "myst_block_break",
126 "myst_line_comment",
127 "math_block",
128 ]
129
130 # Optional MyST Syntaxes
131 myst_enable_extensions = []
132
133 # -- Options for HTML output -------------------------------------------------
134
135 # The theme to use for HTML and HTML Help pages. See the documentation for
136 # a list of builtin themes.
137 #
138 html_theme = "furo"
139 html_logo = "_static/logo2-readme.png"
140
141 # Add any paths that contain custom static files (such as style sheets) here,
142 # relative to this directory. They are copied after the builtin static files,
143 # so a file named "default.css" will overwrite the builtin "default.css".
144 html_static_path = ["_static"]
145
146 # Custom sidebar templates, must be a dictionary that maps document names
147 # to template names.
148 #
149 # The default sidebars (for documents that don't match any pattern) are
150 # defined by theme itself. Builtin themes are using these templates by
151 # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
152 # 'searchbox.html']``.
153 #
154 # html_sidebars = {}
155
156
157 # -- Options for HTMLHelp output ---------------------------------------------
158
159 # Output file base name for HTML help builder.
160 htmlhelp_basename = "blackdoc"
161
162
163 # -- Options for LaTeX output ------------------------------------------------
164
165 # Grouping the document tree into LaTeX files. List of tuples
166 # (source start file, target name, title,
167 # author, documentclass [howto, manual, or own class]).
168 latex_documents = [(
169 master_doc,
170 "black.tex",
171 "Documentation for Black",
172 "Łukasz Langa and contributors to Black",
173 "manual",
174 )]
175
176
177 # -- Options for manual page output ------------------------------------------
178
179 # One entry per manual page. List of tuples
180 # (source start file, name, description, authors, manual section).
181 man_pages = [(master_doc, "black", "Documentation for Black", [author], 1)]
182
183
184 # -- Options for Texinfo output ----------------------------------------------
185
186 # Grouping the document tree into Texinfo files. List of tuples
187 # (source start file, target name, title, author,
188 # dir menu entry, description, category)
189 texinfo_documents = [(
190 master_doc,
191 "Black",
192 "Documentation for Black",
193 author,
194 "Black",
195 "The uncompromising Python code formatter",
196 "Miscellaneous",
197 )]
198
199
200 # -- Options for Epub output -------------------------------------------------
201
202 # Bibliographic Dublin Core info.
203 epub_title = project
204 epub_author = author
205 epub_publisher = author
206 epub_copyright = copyright
207
208 # The unique identifier of the text. This can be a ISBN number
209 # or the project homepage.
210 #
211 # epub_identifier = ''
212
213 # A unique identification for the text.
214 #
215 # epub_uid = ''
216
217 # A list of files that should not be packed into the epub file.
218 epub_exclude_files = ["search.html"]
219
220
221 # -- Extension configuration -------------------------------------------------
222
223 autodoc_member_order = "bysource"
224
225 # -- sphinx-copybutton configuration ----------------------------------------
226 copybutton_prompt_text = (
227 r">>> |\.\.\. |> |\$ |\# | In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
228 )
229 copybutton_prompt_is_regexp = True
230 copybutton_remove_prompts = True
231
232 # -- Options for intersphinx extension ---------------------------------------
233
234 # Example configuration for intersphinx: refer to the Python standard library.
235 intersphinx_mapping = {"python": ("/usr/share/doc/python3/html/", None)}