Debian Codegraph @

docs/conf.py

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