Sphinx documentation tree without full path to module

112 Views Asked by At

I'm trying to create an automated documentation using sphinx with autodoc and autosummary extension. I'm also using the pydata_sphinx_theme.

My goal is to automatically create a tree of of objects (let's stick with python functions for now) that will be shown in the primary sidebar of the documentation.

The template (see lower) does the job, nevertheless it always shows the full path to each function - e.g. my_package.my_python_module1.function_A. The goal is to get rid of the whole path and see just the ending object.

Code structure:
├───my_package
│   └───my_python_module1 (contains function_A)
│   └───my_directory
│       └───my_python_module2 (contains function_B)


Generated documentation tree:
├───my_package
│   └───my_package.my_python_module1
│          └───my_package.my_python_module1.function_A
│   └───my_package.my_directory
│       └───my_package.my_directory.my_python_module2
│              └───my_package.my_directory.my_python_module2.function_B

Desired documentation tree
├───my_package
│   └───my_python_module1
│          └───function_A
│   └───my_directory
│       └───my_python_module2
│              └───function_B

One of the recommended options is to use add_module_names = False in conf.py - this does not work for the pydata_sphinx_theme.

Also playing around with the "fullname" (like replacing with "name") in code lower also solves the job only partially.

Full template code of custom-module-template.rst:

{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

   {% block attributes %}
   {% if attributes %}
   .. rubric:: Module attributes

   .. autosummary::
      :toctree:
   {% for item in attributes %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block functions %}
   {% if functions %}
   .. rubric:: {{ _('Functions') }}

   .. autosummary::
      :toctree:
      :nosignatures:
   {% for item in functions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block classes %}
   {% if classes %}
   .. rubric:: {{ _('Classes') }}

   .. autosummary::
      :toctree:
      :template: custom-class-template.rst
      :nosignatures:
   {% for item in classes %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block exceptions %}
   {% if exceptions %}
   .. rubric:: {{ _('Exceptions') }}

   .. autosummary::
      :toctree:
   {% for item in exceptions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

{% block modules %}
{% if modules %}
.. autosummary::
   :toctree:
   :template: custom-module-template.rst
   :recursive:
{% for item in modules %}
   {{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

So the question is: how to adjust the template in order to get rid of the full path?

0

There are 0 best solutions below