How do I exclude modules from autosummary recursive documentation

668 Views Asked by At

I have some Sphinx docs like so:

Browse the code-based documentation here:

.. autosummary::
   :toctree: _autosummary
   :template: custom-module-template.rst
   :recursive:

   foo

Where foo is a module which has foo.bar, foo.bar.a, foo.baz, etc. Is there a way to exclude foo.baz?

1

There are 1 best solutions below

0
On

On the custom-module-template.rst template, at the part were it iterates through the submodules you can add an if statement to check the name of the module, like so:

{# rest of the module template #}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
   :toctree:
   :template: custom-module-template.rst
   :recursive:
   {% for item in modules %}
   {% if not item.endswith('.baz') %}
       {{ item }}
   {%- endif %}
   {%- endfor %}
{% endif %}
{% endblock %}

I'm not sure this is the best solution, but this works for me.

Hint for the custom-module-template.rst