Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/Documentation/conf.py
49240 views
1
# SPDX-License-Identifier: GPL-2.0-only
2
# pylint: disable=C0103,C0209
3
4
"""
5
The Linux Kernel documentation build configuration file.
6
"""
7
8
import os
9
import shutil
10
import sys
11
12
from textwrap import dedent
13
14
import sphinx
15
16
# If extensions (or modules to document with autodoc) are in another directory,
17
# add these directories to sys.path here. If the directory is relative to the
18
# documentation root, use os.path.abspath to make it absolute, like shown here.
19
sys.path.insert(0, os.path.abspath("sphinx"))
20
21
# Minimal supported version
22
needs_sphinx = "3.4.3"
23
24
# Get Sphinx version
25
major, minor, patch = sphinx.version_info[:3] # pylint: disable=I1101
26
27
# Include_patterns were added on Sphinx 5.1
28
if (major < 5) or (major == 5 and minor < 1):
29
has_include_patterns = False
30
else:
31
has_include_patterns = True
32
# Include patterns that don't contain directory names, in glob format
33
include_patterns = ["**.rst"]
34
35
# Location of Documentation/ directory
36
doctree = os.path.abspath(".")
37
38
# Exclude of patterns that don't contain directory names, in glob format.
39
exclude_patterns = []
40
41
# List of patterns that contain directory names in glob format.
42
dyn_include_patterns = []
43
dyn_exclude_patterns = ["output"]
44
45
# Currently, only netlink/specs has a parser for yaml.
46
# Prefer using include patterns if available, as it is faster
47
if has_include_patterns:
48
dyn_include_patterns.append("netlink/specs/*.yaml")
49
else:
50
dyn_exclude_patterns.append("netlink/*.yaml")
51
dyn_exclude_patterns.append("devicetree/bindings/**.yaml")
52
dyn_exclude_patterns.append("core-api/kho/bindings/**.yaml")
53
54
# Properly handle directory patterns and LaTeX docs
55
# -------------------------------------------------
56
57
def config_init(app, config):
58
"""
59
Initialize path-dependent variabled
60
61
On Sphinx, all directories are relative to what it is passed as
62
SOURCEDIR parameter for sphinx-build. Due to that, all patterns
63
that have directory names on it need to be dynamically set, after
64
converting them to a relative patch.
65
66
As Sphinx doesn't include any patterns outside SOURCEDIR, we should
67
exclude relative patterns that start with "../".
68
"""
69
70
# setup include_patterns dynamically
71
if has_include_patterns:
72
for p in dyn_include_patterns:
73
full = os.path.join(doctree, p)
74
75
rel_path = os.path.relpath(full, start=app.srcdir)
76
if rel_path.startswith("../"):
77
continue
78
79
config.include_patterns.append(rel_path)
80
81
# setup exclude_patterns dynamically
82
for p in dyn_exclude_patterns:
83
full = os.path.join(doctree, p)
84
85
rel_path = os.path.relpath(full, start=app.srcdir)
86
if rel_path.startswith("../"):
87
continue
88
89
config.exclude_patterns.append(rel_path)
90
91
# LaTeX and PDF output require a list of documents with are dependent
92
# of the app.srcdir. Add them here
93
94
# Handle the case where SPHINXDIRS is used
95
if not os.path.samefile(doctree, app.srcdir):
96
# Add a tag to mark that the build is actually a subproject
97
tags.add("subproject")
98
99
# get index.rst, if it exists
100
doc = os.path.basename(app.srcdir)
101
fname = "index"
102
if os.path.exists(os.path.join(app.srcdir, fname + ".rst")):
103
latex_documents.append((fname, doc + ".tex",
104
"Linux %s Documentation" % doc.capitalize(),
105
"The kernel development community",
106
"manual"))
107
return
108
109
# When building all docs, or when a main index.rst doesn't exist, seek
110
# for it on subdirectories
111
for doc in os.listdir(app.srcdir):
112
fname = os.path.join(doc, "index")
113
if not os.path.exists(os.path.join(app.srcdir, fname + ".rst")):
114
continue
115
116
has = False
117
for l in latex_documents:
118
if l[0] == fname:
119
has = True
120
break
121
122
if not has:
123
latex_documents.append((fname, doc + ".tex",
124
"Linux %s Documentation" % doc.capitalize(),
125
"The kernel development community",
126
"manual"))
127
128
# helper
129
# ------
130
131
132
def have_command(cmd):
133
"""Search ``cmd`` in the ``PATH`` environment.
134
135
If found, return True.
136
If not found, return False.
137
"""
138
return shutil.which(cmd) is not None
139
140
141
# -- General configuration ------------------------------------------------
142
143
# Add any Sphinx extensions in alphabetic order
144
extensions = [
145
"automarkup",
146
"kernel_abi",
147
"kerneldoc",
148
"kernel_feat",
149
"kernel_include",
150
"kfigure",
151
"maintainers_include",
152
"parser_yaml",
153
"rstFlatTable",
154
"sphinx.ext.autosectionlabel",
155
"sphinx.ext.ifconfig",
156
"translations",
157
]
158
# Since Sphinx version 3, the C function parser is more pedantic with regards
159
# to type checking. Due to that, having macros at c:function cause problems.
160
# Those needed to be escaped by using c_id_attributes[] array
161
c_id_attributes = [
162
# GCC Compiler types not parsed by Sphinx:
163
"__restrict__",
164
165
# include/linux/compiler_types.h:
166
"__iomem",
167
"__kernel",
168
"noinstr",
169
"notrace",
170
"__percpu",
171
"__rcu",
172
"__user",
173
"__force",
174
"__counted_by_le",
175
"__counted_by_be",
176
177
# include/linux/compiler_attributes.h:
178
"__alias",
179
"__aligned",
180
"__aligned_largest",
181
"__always_inline",
182
"__assume_aligned",
183
"__cold",
184
"__attribute_const__",
185
"__copy",
186
"__pure",
187
"__designated_init",
188
"__visible",
189
"__printf",
190
"__scanf",
191
"__gnu_inline",
192
"__malloc",
193
"__mode",
194
"__no_caller_saved_registers",
195
"__noclone",
196
"__nonstring",
197
"__noreturn",
198
"__packed",
199
"__pure",
200
"__section",
201
"__always_unused",
202
"__maybe_unused",
203
"__used",
204
"__weak",
205
"noinline",
206
"__fix_address",
207
"__counted_by",
208
209
# include/linux/memblock.h:
210
"__init_memblock",
211
"__meminit",
212
213
# include/linux/init.h:
214
"__init",
215
"__ref",
216
217
# include/linux/linkage.h:
218
"asmlinkage",
219
220
# include/linux/btf.h
221
"__bpf_kfunc",
222
]
223
224
# Ensure that autosectionlabel will produce unique names
225
autosectionlabel_prefix_document = True
226
autosectionlabel_maxdepth = 2
227
228
# Load math renderer:
229
# For html builder, load imgmath only when its dependencies are met.
230
# mathjax is the default math renderer since Sphinx 1.8.
231
have_latex = have_command("latex")
232
have_dvipng = have_command("dvipng")
233
load_imgmath = have_latex and have_dvipng
234
235
# Respect SPHINX_IMGMATH (for html docs only)
236
if "SPHINX_IMGMATH" in os.environ:
237
env_sphinx_imgmath = os.environ["SPHINX_IMGMATH"]
238
if "yes" in env_sphinx_imgmath:
239
load_imgmath = True
240
elif "no" in env_sphinx_imgmath:
241
load_imgmath = False
242
else:
243
sys.stderr.write("Unknown env SPHINX_IMGMATH=%s ignored.\n" % env_sphinx_imgmath)
244
245
if load_imgmath:
246
extensions.append("sphinx.ext.imgmath")
247
math_renderer = "imgmath"
248
else:
249
math_renderer = "mathjax"
250
251
# Add any paths that contain templates here, relative to this directory.
252
templates_path = ["sphinx/templates"]
253
254
# The suffixes of source filenames that will be automatically parsed
255
source_suffix = {
256
".rst": "restructuredtext",
257
".yaml": "yaml",
258
}
259
260
# The encoding of source files.
261
# source_encoding = 'utf-8-sig'
262
263
# The master toctree document.
264
master_doc = "index"
265
266
# General information about the project.
267
project = "The Linux Kernel"
268
copyright = "The kernel development community" # pylint: disable=W0622
269
author = "The kernel development community"
270
271
# The version info for the project you're documenting, acts as replacement for
272
# |version| and |release|, also used in various other places throughout the
273
# built documents.
274
#
275
# In a normal build, version and release are set to KERNELVERSION and
276
# KERNELRELEASE, respectively, from the Makefile via Sphinx command line
277
# arguments.
278
#
279
# The following code tries to extract the information by reading the Makefile,
280
# when Sphinx is run directly (e.g. by Read the Docs).
281
try:
282
makefile_version = None
283
makefile_patchlevel = None
284
with open("../Makefile", encoding="utf=8") as fp:
285
for line in fp:
286
key, val = [x.strip() for x in line.split("=", 2)]
287
if key == "VERSION":
288
makefile_version = val
289
elif key == "PATCHLEVEL":
290
makefile_patchlevel = val
291
if makefile_version and makefile_patchlevel:
292
break
293
except Exception:
294
pass
295
finally:
296
if makefile_version and makefile_patchlevel:
297
version = release = makefile_version + "." + makefile_patchlevel
298
else:
299
version = release = "unknown version"
300
301
302
def get_cline_version():
303
"""
304
HACK: There seems to be no easy way for us to get at the version and
305
release information passed in from the makefile...so go pawing through the
306
command-line options and find it for ourselves.
307
"""
308
309
c_version = c_release = ""
310
for arg in sys.argv:
311
if arg.startswith("version="):
312
c_version = arg[8:]
313
elif arg.startswith("release="):
314
c_release = arg[8:]
315
if c_version:
316
if c_release:
317
return c_version + "-" + c_release
318
return c_version
319
return version # Whatever we came up with before
320
321
322
# The language for content autogenerated by Sphinx. Refer to documentation
323
# for a list of supported languages.
324
#
325
# This is also used if you do content translation via gettext catalogs.
326
# Usually you set "language" from the command line for these cases.
327
language = "en"
328
329
# There are two options for replacing |today|: either, you set today to some
330
# non-false value, then it is used:
331
# today = ''
332
# Else, today_fmt is used as the format for a strftime call.
333
# today_fmt = '%B %d, %Y'
334
335
# The reST default role (used for this markup: `text`) to use for all
336
# documents.
337
# default_role = None
338
339
# If true, '()' will be appended to :func: etc. cross-reference text.
340
# add_function_parentheses = True
341
342
# If true, the current module name will be prepended to all description
343
# unit titles (such as .. function::).
344
# add_module_names = True
345
346
# If true, sectionauthor and moduleauthor directives will be shown in the
347
# output. They are ignored by default.
348
# show_authors = False
349
350
# The name of the Pygments (syntax highlighting) style to use.
351
pygments_style = "sphinx"
352
353
# A list of ignored prefixes for module index sorting.
354
# modindex_common_prefix = []
355
356
# If true, keep warnings as "system message" paragraphs in the built documents.
357
# keep_warnings = False
358
359
# If true, `todo` and `todoList` produce output, else they produce nothing.
360
todo_include_todos = False
361
362
primary_domain = "c"
363
highlight_language = "none"
364
365
# -- Options for HTML output ----------------------------------------------
366
367
# The theme to use for HTML and HTML Help pages. See the documentation for
368
# a list of builtin themes.
369
370
# Default theme
371
html_theme = "alabaster"
372
html_css_files = []
373
374
if "DOCS_THEME" in os.environ:
375
html_theme = os.environ["DOCS_THEME"]
376
377
if html_theme in ["sphinx_rtd_theme", "sphinx_rtd_dark_mode"]:
378
# Read the Docs theme
379
try:
380
import sphinx_rtd_theme
381
382
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
383
384
# Add any paths that contain custom static files (such as style sheets) here,
385
# relative to this directory. They are copied after the builtin static files,
386
# so a file named "default.css" will overwrite the builtin "default.css".
387
html_css_files = [
388
"theme_overrides.css",
389
]
390
391
# Read the Docs dark mode override theme
392
if html_theme == "sphinx_rtd_dark_mode":
393
try:
394
import sphinx_rtd_dark_mode # pylint: disable=W0611
395
396
extensions.append("sphinx_rtd_dark_mode")
397
except ImportError:
398
html_theme = "sphinx_rtd_theme"
399
400
if html_theme == "sphinx_rtd_theme":
401
# Add color-specific RTD normal mode
402
html_css_files.append("theme_rtd_colors.css")
403
404
html_theme_options = {
405
"navigation_depth": -1,
406
}
407
408
except ImportError:
409
html_theme = "alabaster"
410
411
if "DOCS_CSS" in os.environ:
412
css = os.environ["DOCS_CSS"].split(" ")
413
414
for l in css:
415
html_css_files.append(l)
416
417
if html_theme == "alabaster":
418
html_theme_options = {
419
"description": get_cline_version(),
420
"page_width": "65em",
421
"sidebar_width": "15em",
422
"fixed_sidebar": "true",
423
"font_size": "inherit",
424
"font_family": "serif",
425
}
426
427
sys.stderr.write("Using %s theme\n" % html_theme)
428
429
# Add any paths that contain custom static files (such as style sheets) here,
430
# relative to this directory. They are copied after the builtin static files,
431
# so a file named "default.css" will overwrite the builtin "default.css".
432
html_static_path = ["sphinx-static"]
433
434
# If true, Docutils "smart quotes" will be used to convert quotes and dashes
435
# to typographically correct entities. However, conversion of "--" to "—"
436
# is not always what we want, so enable only quotes.
437
smartquotes_action = "q"
438
439
# Custom sidebar templates, maps document names to template names.
440
# Note that the RTD theme ignores this
441
html_sidebars = {"**": ["searchbox.html",
442
"kernel-toc.html",
443
"sourcelink.html"]}
444
445
# about.html is available for alabaster theme. Add it at the front.
446
if html_theme == "alabaster":
447
html_sidebars["**"].insert(0, "about.html")
448
449
# The name of an image file (relative to this directory) to place at the top
450
# of the sidebar.
451
html_logo = "images/logo.svg"
452
453
# Output file base name for HTML help builder.
454
htmlhelp_basename = "TheLinuxKerneldoc"
455
456
# -- Options for LaTeX output ---------------------------------------------
457
458
latex_elements = {
459
# The paper size ('letterpaper' or 'a4paper').
460
"papersize": "a4paper",
461
"passoptionstopackages": dedent(r"""
462
\PassOptionsToPackage{svgnames}{xcolor}
463
"""),
464
# The font size ('10pt', '11pt' or '12pt').
465
"pointsize": "11pt",
466
# Needed to generate a .ind file
467
"printindex": r"\footnotesize\raggedright\printindex",
468
# Latex figure (float) alignment
469
# 'figure_align': 'htbp',
470
# Don't mangle with UTF-8 chars
471
"fontenc": "",
472
"inputenc": "",
473
"utf8extra": "",
474
# Set document margins
475
"sphinxsetup": dedent(r"""
476
hmargin=0.5in, vmargin=1in,
477
parsedliteralwraps=true,
478
verbatimhintsturnover=false,
479
"""),
480
#
481
# Some of our authors are fond of deep nesting; tell latex to
482
# cope.
483
#
484
"maxlistdepth": "10",
485
# For CJK One-half spacing, need to be in front of hyperref
486
"extrapackages": r"\usepackage{setspace}",
487
"fontpkg": dedent(r"""
488
\usepackage{fontspec}
489
\setmainfont{DejaVu Serif}
490
\setsansfont{DejaVu Sans}
491
\setmonofont{DejaVu Sans Mono}
492
\newfontfamily\headingfont{DejaVu Serif}
493
"""),
494
"preamble": dedent(r"""
495
% Load kerneldoc specific LaTeX settings
496
\input{kerneldoc-preamble.sty}
497
""")
498
}
499
500
# This will be filled up by config-inited event
501
latex_documents = []
502
503
# The name of an image file (relative to this directory) to place at the top of
504
# the title page.
505
# latex_logo = None
506
507
# For "manual" documents, if this is true, then toplevel headings are parts,
508
# not chapters.
509
# latex_use_parts = False
510
511
# If true, show page references after internal links.
512
# latex_show_pagerefs = False
513
514
# If true, show URL addresses after external links.
515
# latex_show_urls = False
516
517
# Documents to append as an appendix to all manuals.
518
# latex_appendices = []
519
520
# If false, no module index is generated.
521
# latex_domain_indices = True
522
523
# Additional LaTeX stuff to be copied to build directory
524
latex_additional_files = [
525
"sphinx/kerneldoc-preamble.sty",
526
]
527
528
529
# -- Options for manual page output ---------------------------------------
530
531
# One entry per manual page. List of tuples
532
# (source start file, name, description, authors, manual section).
533
man_pages = [
534
(master_doc, "thelinuxkernel", "The Linux Kernel Documentation", [author], 1)
535
]
536
537
# If true, show URL addresses after external links.
538
# man_show_urls = False
539
540
541
# -- Options for Texinfo output -------------------------------------------
542
543
# Grouping the document tree into Texinfo files. List of tuples
544
# (source start file, target name, title, author,
545
# dir menu entry, description, category)
546
texinfo_documents = [(
547
master_doc,
548
"TheLinuxKernel",
549
"The Linux Kernel Documentation",
550
author,
551
"TheLinuxKernel",
552
"One line description of project.",
553
"Miscellaneous",
554
),]
555
556
# -- Options for Epub output ----------------------------------------------
557
558
# Bibliographic Dublin Core info.
559
epub_title = project
560
epub_author = author
561
epub_publisher = author
562
epub_copyright = copyright
563
564
# A list of files that should not be packed into the epub file.
565
epub_exclude_files = ["search.html"]
566
567
# =======
568
# rst2pdf
569
#
570
# Grouping the document tree into PDF files. List of tuples
571
# (source start file, target name, title, author, options).
572
#
573
# See the Sphinx chapter of https://ralsina.me/static/manual.pdf
574
#
575
# FIXME: Do not add the index file here; the result will be too big. Adding
576
# multiple PDF files here actually tries to get the cross-referencing right
577
# *between* PDF files.
578
pdf_documents = [
579
("kernel-documentation", "Kernel", "Kernel", "J. Random Bozo"),
580
]
581
582
# kernel-doc extension configuration for running Sphinx directly (e.g. by Read
583
# the Docs). In a normal build, these are supplied from the Makefile via command
584
# line arguments.
585
kerneldoc_bin = "../scripts/kernel-doc.py"
586
kerneldoc_srctree = ".."
587
588
def setup(app):
589
"""Patterns need to be updated at init time on older Sphinx versions"""
590
591
app.connect('config-inited', config_init)
592
593