Lopez
Lopez

Reputation: 472

Skip Empty Modules - Sphinx Autodoc

I am using Sphinx to build documentation for a package. I can't find a way to skip (remove) empty submodules when building doc. Example in Section 2 there is a subsection named Submodule which is blank I want to skip such subsections. I tried using the following code.

def skip_util_classes(app, what, name, obj, skip, options):
    if what == "Submodules":
        skip = True
    return skip


def setup(sphinx):
    sphinx.connect("autodoc-skip-member", skip_util_classes)

The above code is not eliminating section Submodules.

I want to know how can I define a section or subsection that needs to be skipped? And how can I define empty section or subsection that I want to skip in skip_util_classes?

Upvotes: 0

Views: 1123

Answers (1)

mzjn
mzjn

Reputation: 50947

Something like the skip_util_classes function (a handler for the autodoc-skip-member event) is used when you want Sphinx to ignore certain members of Python modules or classes. See Connect Sphinx autodoc-skip-member to my function.

This technique cannot be used to skip or remove sections in generated .rst files. Here are two suggestions that might help with that problem:

  1. Create a custom sphinx-apidoc template. See Remove the word "module" from Sphinx documentation.

  2. Don't run sphinx-apidoc over and over again. Run the tool once, tweak the output and add it to source control. See Keeping the API updated in Sphinx.

Upvotes: 1

Related Questions