Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx autosummary modules should return module names without path #9743

Closed
4flixt opened this issue Oct 15, 2021 · 3 comments · Fixed by #12609
Closed

Sphinx autosummary modules should return module names without path #9743

4flixt opened this issue Oct 15, 2021 · 3 comments · Fixed by #12609

Comments

@4flixt
Copy link

4flixt commented Oct 15, 2021

Is your feature request related to a problem? Please describe.
We are using sphinx.ext.autosummary with _templates to create new files for each class, attribute, function.
This works perfectly for the above mentioned, where the template file contains (e.g. just for classes):

{% if classes %}
.. automodule:: {{ fullname }}
.. currentmodule:: {{ fullname }}

.. rubric:: Classes
.. autosummary::
    :toctree:
    :nosignatures:
    {% for class in classes %}
    {{ class }}
    {% endfor %}
{% endif %}

Note that we are setting with .. currentmodule:: {{ fullname }} the correct path to the current file and then document each class with: {% for class in classes %}. This works, because classes returns the class names without prefix (the path contained in fullname).

For modules, on the other hand, the approach doesn't work:

{% if modules %}
.. automodule:: {{ fullname }}
.. currentmodule:: {{ fullname }}
.. autosummary::
   :toctree:
   :recursive:
   :template: module.rst
   {% for module in modules %}
   {{ module }}
   {% endfor %}
{% endif %}

The problem is here that modules returns a list of modules with the full path.

Describe the solution you'd like
Have modules return only the module name without prefix (full path)

Additional context
We use Sphinx to document our toolbox do-mpc

@4flixt 4flixt added the type:enhancement enhance or introduce a new feature label Oct 15, 2021
@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
@JPEWdev
Copy link

JPEWdev commented Jul 15, 2024

I think #6792 should raise the priority of this, because now Sphinx will reject the full path modules with an error. We had to work around this by doing:

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

.. autosummary::
   :toctree:
   :template: module-template.rst
   :recursive:
{% for item in modules %}
   {{ item | replace(fullname + ".", "") }}
{%- endfor %}
{% endif %}

@AA-Turner
Copy link
Member

Please see #12609, which ought resolve this.

A

@AA-Turner
Copy link
Member

I have released Sphinx 7.4.6 with a fix.

A

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants