Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Josverl opened this issue Jul 24, 2024 · 0 comments

Comments

@Josverl
Copy link

Josverl commented Jul 24, 2024

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 :)
   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants