Skip to content

add documentation for availability and differences for autodoc-process-docstring (and some friends)  #468

Open
@Josverl

Description

@Josverl

Hi,

I am in need for some module docstring post-processing, and it took me rather long to figure out that:

  1. autoapi also allows (some?) autodoc-* events to be captured
  2. There are some differences in the values for what

Especially it took me quite a while to figure out there are some subtle differences:

  • autodoc: what can be : "module", "class", "exception", "function", "method", "attribute"
  • autoapi: what can be : "package", "class", "exception", "function", "method", "attribute", "data"

Im not quite sure if t

I think that would be good to add to the documentation if this is indeed the intent, rather than a side effect of something else in my setup
It appears that the autodoc-process-signature event is also available, but I have not done any further validation on that, but as it appears to be used internally by autoapi, it is likely to work as well.

extensions = [
    "autoapi.extension",
    "sphinx.ext.napoleon",
]

# ...
mpy_lib_modules = {"foo":"bar"}

def process_docstring(
    app: Sphinx,
    what: str,  # "module", "class", "exception", "function", "method", "attribute" ( "package", 'data' with autoapi)
    name: str,
    obj,  # Always None with autoapi
    options,  # Always None with autoapi
    lines: List[str],
):
    if what in {"package", "module"} and name in mpy_lib_modules:
            lines.extend(
                (
                    "",
                    f".. seealso:: This is a `{mpy_lib_modules[name]}` module from the `micropython-lib` repository.",
                )
            )

def process_signature(app, what, name, obj, options, signature, return_annotation):
    pass

def setup(sphinx: Sphinx):
    sphinx.connect("autodoc-process-docstring", process_docstring) # also fires with autoapi :)
    sphinx.connect("autodoc-process-signature", process_signature)  # also fires with autoapi :)
   

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions