Skip to content

Commit 330367b

Browse files
author
Jonathan Corbet
committed
Merge branch 'mauro' into docs-mw
Mauro's work to include documentation from our Python modules. His cover letter follows: This is an extended version of: https://lore.kernel.org/linux-doc/cover.1768488832.git.mchehab+huawei@kernel.org/ It basically adds everything we currently have inside libs/tool/python to "tools" book inside documentation. This version should be independent of the other series yet to be merged, (including the jobserver one). The vast amount of changes here are docstring cleanups and additions. They mainly consists on: - ensuring that every phrase will end with a period, making it uniform along all files; - cleaning ups to better uniform docstrings; - variable descriptions now use "#:" markup, as it allows autodoc to add them inside the documentation; - added some missing docstrings; - some new blank lines at comments to make ReST syntax parser happy; - add a couple of sphinx markups (mainly, code blocks). Most of those are minor changes, affecting only comments. It also has one patch per libarary type, adding them to docs. For kernel-doc, I did the cleanups first, as there is one code block inside tools/lib/python/kdoc/latex_fonts.py that would cause a Sphinx crash without such markups. The series actually starts with 3 fixes: - avoid "*" markups on indexes with deep> 3 to override text - a variable rename to stop abusing doctree name - don't rely on cwd to get Documentation/ location patch 4 adds support to document scripts either at: - tools/ - scripts/ patch 5 contains a CSS to better display autodoc html output. For those who want to play with documentation, documenting a python file is very simple. All it takes is to use: .. automodule:: lib.python.<dir+name> Usually, we add a couple of control members to it to adjust the desired documentation scope (add/remove members, showing class inheritance, showing members that currently don't have docstrings, etc). That's why we're using: .. automodule:: lib.python.kdoc.enrich_formatter :members: :show-inheritance: :undoc-members: (and similar) inside tools/kdoc*.rst. autodoc allows filtering in/out members, file docstrings, etc. It also allows documenting just some members or functions with directives like: ..autofunction: ..automember: Sphinx also has a helper script to generate .rst files with documentation: $ sphinx-apidoc -o foobar tools/lib/python/ which can be helpful to discover what should be documented, although changes are needed to use what it produces.
2 parents ffb569d + ef6aa11 commit 330367b

30 files changed

Lines changed: 608 additions & 265 deletions

Documentation/conf.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
import sphinx
1515

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"))
16+
# Location of Documentation/ directory
17+
kern_doc_dir = os.path.dirname(os.path.abspath(__file__))
18+
19+
# Add location of Sphinx extensions
20+
sys.path.insert(0, os.path.join(kern_doc_dir, "sphinx"))
21+
22+
# Allow sphinx.ext.autodoc to document files at tools and scripts
23+
sys.path.append(os.path.join(kern_doc_dir, "..", "tools"))
24+
sys.path.append(os.path.join(kern_doc_dir, "..", "scripts"))
2025

2126
# Minimal supported version
2227
needs_sphinx = "3.4.3"
@@ -32,9 +37,6 @@
3237
# Include patterns that don't contain directory names, in glob format
3338
include_patterns = ["**.rst"]
3439

35-
# Location of Documentation/ directory
36-
doctree = os.path.abspath(".")
37-
3840
# Exclude of patterns that don't contain directory names, in glob format.
3941
exclude_patterns = []
4042

@@ -73,7 +75,7 @@ def config_init(app, config):
7375
# setup include_patterns dynamically
7476
if has_include_patterns:
7577
for p in dyn_include_patterns:
76-
full = os.path.join(doctree, p)
78+
full = os.path.join(kern_doc_dir, p)
7779

7880
rel_path = os.path.relpath(full, start=app.srcdir)
7981
if rel_path.startswith("../"):
@@ -83,7 +85,7 @@ def config_init(app, config):
8385

8486
# setup exclude_patterns dynamically
8587
for p in dyn_exclude_patterns:
86-
full = os.path.join(doctree, p)
88+
full = os.path.join(kern_doc_dir, p)
8789

8890
rel_path = os.path.relpath(full, start=app.srcdir)
8991
if rel_path.startswith("../"):
@@ -95,7 +97,7 @@ def config_init(app, config):
9597
# of the app.srcdir. Add them here
9698

9799
# Handle the case where SPHINXDIRS is used
98-
if not os.path.samefile(doctree, app.srcdir):
100+
if not os.path.samefile(kern_doc_dir, app.srcdir):
99101
# Add a tag to mark that the build is actually a subproject
100102
tags.add("subproject")
101103

@@ -154,6 +156,7 @@ def have_command(cmd):
154156
"maintainers_include",
155157
"parser_yaml",
156158
"rstFlatTable",
159+
"sphinx.ext.autodoc",
157160
"sphinx.ext.autosectionlabel",
158161
"sphinx.ext.ifconfig",
159162
"translations",

Documentation/sphinx-static/custom.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ img.logo {
3030
margin-bottom: 20px;
3131
}
3232

33+
/* The default is to use -1em, wich makes it override text */
34+
li { text-indent: 0em; }
35+
3336
/*
3437
* Parameters for the display of function prototypes and such included
3538
* from C source files.
@@ -40,6 +43,15 @@ dl.function dt { margin-left: 10em; text-indent: -10em; }
4043
dt.sig-object { font-size: larger; }
4144
div.kernelindent { margin-left: 2em; margin-right: 4em; }
4245

46+
/*
47+
* Parameters for the display of function prototypes and such included
48+
* from Python source files.
49+
*/
50+
dl.py { margin-top: 2em; background-color: #ecf0f3; }
51+
dl.py.class { margin-left: 2em; text-indent: -2em; padding-left: 2em; }
52+
dl.py.method, dl.py.attribute { margin-left: 2em; text-indent: -2em; }
53+
dl.py li, pre { text-indent: 0em; padding-left: 0 !important; }
54+
4355
/*
4456
* Tweaks for our local TOC
4557
*/

Documentation/tools/feat.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
====================================
4+
Documentation features parser module
5+
====================================
6+
7+
.. automodule:: lib.python.feat.parse_features
8+
:members:
9+
:show-inheritance:
10+
:undoc-members:

Documentation/tools/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ more additions are needed here:
1212

1313
rtla/index
1414
rv/index
15+
python
1516

1617
.. only:: subproject and html
1718

Documentation/tools/jobserver.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=================
4+
Job server module
5+
=================
6+
7+
.. automodule:: lib.python.jobserver
8+
:members:
9+
:show-inheritance:
10+
:undoc-members:

Documentation/tools/kabi.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=====================================
4+
Kernel ABI documentation tool modules
5+
=====================================
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
10+
kabi_parser
11+
kabi_regex
12+
kabi_symbols
13+
kabi_helpers
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=================
4+
Ancillary classes
5+
=================
6+
7+
.. automodule:: lib.python.abi.helpers
8+
:members:
9+
:member-order: bysource
10+
:show-inheritance:
11+
:undoc-members:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=====================================
4+
Kernel ABI documentation parser class
5+
=====================================
6+
7+
.. automodule:: lib.python.abi.abi_parser
8+
:members:
9+
:show-inheritance:
10+
:undoc-members:

Documentation/tools/kabi_regex.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=============================
4+
ABI regex search symbol class
5+
=============================
6+
7+
.. automodule:: lib.python.abi.abi_regex
8+
:members:
9+
:show-inheritance:
10+
:undoc-members:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=========================================
4+
System ABI documentation validation class
5+
=========================================
6+
7+
.. automodule:: lib.python.abi.system_symbols
8+
:members:
9+
:show-inheritance:
10+
:undoc-members:

0 commit comments

Comments
 (0)