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

Open
#468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Start with the autodoc-process-docstring and autodoc-process-signature events in the Sphinx extension, and verify whether AutoAPI emits them and how their what, obj, and options values differ. Update the documentation to list event availability and supported what values for autodoc and AutoAPI. Done when these behaviors and differences are clear to users.

Written by the indexing model from the issue text.

Description

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 :)
   
Dominant language
Python
Stars
494
Forks
147
Avg merge
9m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from readthedocs/sphinx-autoapi

All issues in readthedocs/sphinx-autoapi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.