Commit 330367bd authored by Jonathan Corbet's avatar Jonathan Corbet
Browse files

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.
parents ffb569d5 ef6aa110
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -13,10 +13,15 @@ from textwrap import dedent

import sphinx

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("sphinx"))
# Location of Documentation/ directory
kern_doc_dir = os.path.dirname(os.path.abspath(__file__))

# Add location of Sphinx extensions
sys.path.insert(0, os.path.join(kern_doc_dir, "sphinx"))

# Allow sphinx.ext.autodoc to document files at tools and scripts
sys.path.append(os.path.join(kern_doc_dir, "..", "tools"))
sys.path.append(os.path.join(kern_doc_dir, "..", "scripts"))

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

# Location of Documentation/ directory
doctree = os.path.abspath(".")

# Exclude of patterns that don't contain directory names, in glob format.
exclude_patterns = []

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

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

    # setup exclude_patterns dynamically
    for p in dyn_exclude_patterns:
        full = os.path.join(doctree, p)
        full = os.path.join(kern_doc_dir, p)

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

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

@@ -154,6 +156,7 @@ extensions = [
    "maintainers_include",
    "parser_yaml",
    "rstFlatTable",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosectionlabel",
    "sphinx.ext.ifconfig",
    "translations",
+12 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ img.logo {
    margin-bottom: 20px;
}

/* The default is to use -1em, wich makes it override text */
li { text-indent: 0em; }

/*
 * Parameters for the display of function prototypes and such included
 * from C source files.
@@ -40,6 +43,15 @@ dl.function dt { margin-left: 10em; text-indent: -10em; }
dt.sig-object { font-size: larger; }
div.kernelindent { margin-left: 2em; margin-right: 4em; }

/*
 * Parameters for the display of function prototypes and such included
 * from Python source files.
 */
dl.py { margin-top: 2em; background-color: #ecf0f3; }
dl.py.class { margin-left: 2em; text-indent: -2em; padding-left: 2em; }
dl.py.method, dl.py.attribute { margin-left: 2em; text-indent: -2em; }
dl.py li, pre { text-indent: 0em; padding-left: 0 !important; }

/*
 * Tweaks for our local TOC
 */
+10 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0

====================================
Documentation features parser module
====================================

.. automodule:: lib.python.feat.parse_features
   :members:
   :show-inheritance:
   :undoc-members:
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ more additions are needed here:

   rtla/index
   rv/index
   python

.. only::  subproject and html

+10 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0

=================
Job server module
=================

.. automodule:: lib.python.jobserver
   :members:
   :show-inheritance:
   :undoc-members:
Loading