python-sphinxsidebartoctree

Sphinx sidebar: include module's functions and class' methods


In Sphinx docs, I define a reference document like this:

Reference
=========

.. toctree::

   reference_api
   reference_cli
   reference_client
   reference_downloads
   reference_options
   reference_stats
   reference_utils

The reference_api document looks like this:

API module
==========

.. automodule:: aria2p.api
    :no-members:

API
---

.. autoclass:: aria2p.api.API
    :members:

Now I get this list in the sidebar:

Reference
  API module
    API

I would like to also add all the API methods that were documented through :members: in the sidebar, something like:

Reference
  API module
    API
      __init__
      add_magnet
      add_metalink
      ...

Is this possible? Should I change how Sphinx writes modules functions and classes' methods to add anchors to them, so the sidebar can display them?


Solution

  • This is now possible with Sphinx 5.2.0. See https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-toc_object_entries_show_parents

    toc_object_entries_show_parents
    A string that determines how domain objects (e.g. functions, classes, attributes, etc.) are displayed in their table of contents entry. Use domain to allow the domain to determine the appropriate number of parents to show. For example, the Python domain would show Class.method() and function(), leaving out the module. level of parents. This is the default setting. Use hide to only show the name of the element without any parents (i.e. method()). Use all to show the fully-qualified name for the object (i.e. module.Class.method()), displaying all parents.