Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I just list undocumented members with sphinx/autodoc?

I am using sphinx with the autodoc extension, and would like to generate a list only containing the undocumented member functions in several modules, and not the documented members.

I can successfully create a list that includes both documented members and undocumented members as follows:

.. automodule:: module
    :members:
    :undoc-members:

Using the :members: directive alone creates the list of documented members only, as expected.

.. automodule:: module
    :members:

But using just the :undoc-members: directive alone (i.e. omitting the :members: flag) does not result in any list at all:

.. automodule:: module
    :undoc-members:

Is there a way to automatically generate this?

(The primary documentation includes a page that shows all the documented members, but I'd find it far more useful to ensure I have written docs for each function etc by having a single page that lists any undocumented member, without showing the text for those that are documented).

like image 861
Bonlenfum Avatar asked Jan 03 '13 14:01

Bonlenfum


People also ask

What is Sphinx ext Autodoc?

ext. autodoc – Include documentation from docstrings. This extension can import the modules you are documenting, and pull in documentation from docstrings in a semi-automatic way.

What is Sphinx AutoAPI?

Sphinx AutoAPI provides "autodoc" style documentation for multiple programming languages without needing to load, run, or import the project being documented. In contrast to the traditional Sphinx autodoc, which is Python-only and uses code imports, AutoAPI finds and generates documentation by parsing source code.

What is Sphinx-Apidoc?

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.


1 Answers

Overriding the autodoc-process-docstring event (as noted by @delnan) can help, by adding the following to conf.py:

# set up the types of member to check that are documented
members_to_watch = ['function',];

def warn_undocumented_members(app, what, name, obj, options, lines):
    if(what in members_to_watch and len(lines)==0):
        # warn to terminal during build
        print "Warning: ", what, "is undocumented: ", name, "(%d)"% len(lines);
        # or modify the docstring so the rendered output is highlights the omission
        lines.append(".. Warning:: %s '%s' undocumented" % (what, name));

And then connect this function to the event (from an answer in this SO thread):

def setup(app):
    app.connect('autodoc-process-docstring', warn_undocumented_members);

To turn on (off) the warnings include (exclude) the undoc-members -- globally with autodoc_default_flags in conf.py, or with both the directives as in the question.

autodoc_default_flags = ['members', 'undoc-members' ]
#autodoc_default_flags = ['members' ]

EDIT:

I attempted to extend this approach to generate just the undoc members, by the following method:

  • conditionally set a property, say, warn_undoc=True, on the object during during the function warn_undocumented_members (above)
  • attach a second override function to the preprocessor event autodoc-skip-member that skipped all members if they did not have warn_undoc set.

However, further investigation rules this approach out, because autodoc-skip-member occurs for each group of members before autodoc-process-docstring occurs. Thus, the properties are set too late to conditionally skip based on presence/absence of docstrings.

like image 168
Bonlenfum Avatar answered Oct 05 '22 22:10

Bonlenfum