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

Autosummary: autosummary_ignore_module_all does not work as documented #10809

Closed
ClementPinard opened this issue Sep 8, 2022 · 2 comments · Fixed by #10811
Closed

Autosummary: autosummary_ignore_module_all does not work as documented #10809

ClementPinard opened this issue Sep 8, 2022 · 2 comments · Fixed by #10811

Comments

@ClementPinard
Copy link
Contributor

ClementPinard commented Sep 8, 2022

Describe the bug

As per documentation :

Note that if an imported member is listed in __all__, it will be documented regardless of the value of autosummary_imported_members.

So the way I understand it is that if I have a small package like this :

my_package/
    __init__.py
    my_class.py
    my_module/
        my_submodule.py

with the following files :

my_class.py

class myClass:
    """" my Class docstring """"
    def my_class_method(self, a):
        """ method docstring """
        return

my_submodule.py

def f():
    """ f docstring """
    return

__init__.py

from .my_class import myClass
from . import my_module

__all__ = ["myClass", "my_module"]

and a rst file like this:

An example of recursive module documentation
====================================

.. autosummary::
    :toctree: generated
    :recursive:

    my_package

assume the option autosummary_ignore_module_all is set to False in conf.py, the autosummary should only consider myClass and my_module to be part of the package my_package. The generated folder should normally look like this:

generated
    my_package.myClass
    my_packge.my_module

But actually, it looks like this :

generated
    my_package.my_class

Meaning it ignored the imported elements, even though they were in the __all__ and it did take the my_module package even though it was not in the __all__

How to Reproduce

$ git clone git@github.com:ClementPinard/sphinx_autosummary_bug_example.git
$ cd sphinx_autosummary_bug_example.gt
$ pip install sphinx
$ sphinx-build -b html docs docs/_build
$ # see docs/generated/ folder

Expected behavior

generated folder should have the files

my_package.rst
my_package.my_module.rst
my_patckage.my_module.my_submodule.rst
my_package.myClass.rst

Your project

https://github.com/ClementPinard/sphinx_autosummary_bug_example

Screenshots

No response

OS

Ubuntu 20.04

Python version

3.9

Sphinx version

5.1

Sphinx extensions

sphinx.ext.autodoc, sphinx.ext.autosummary

Additional context

@ClementPinard
Copy link
Contributor Author

ClementPinard commented Sep 8, 2022

After some investigation in the code, I do believe that there is a problem in the generate.py file, when populating the ns dictionnary

https://github.com/sphinx-doc/sphinx/blob/5.x/sphinx/ext/autosummary/generate.py#L313

Problem with myClass

ns["members"] has the right dict, i.e. myClass and my_module, but when trying to populate ns["classes"] , myClass gets dismissed, because imported_member is not True, and the function get_members does not check if the imported memeber is in __all__ or not as seen here :

if imported or getattr(value, '__module__', None) == obj.__name__:

See how if skips the block if either the imported is not evaluated to True or the __module__ of considered object is not the root, i.e. the element is imported.

As a consequence, ns["classes"] is empty

Problem with my_module

The code only seem to care about modules found by the function get_modules and otherwise are simply ignored.

ns['modules'], ns['all_modules'] = get_modules(obj)

It explains why we find my_package.my_class even though it's not in my_package.__all__. Not sure how to explain the lack of my_package.my_module though, it seems that the fact that it has a submodule and no __init__.py is the problem.

ClementPinard added a commit to ClementPinard/sphinx that referenced this issue Sep 8, 2022
Fixes sphinx-doc#10809

* the option autosummary_ignore_module_all when set to False adds members to module's members entry that will be used for autodoc, but otherwise it ignores it. As such, if a class is available in the __all__, it won't be generated.
* This commit aims at extending the __all__ handling not only to members, but also to corresponding attribute types (function, classes, exceptions, modules)
* In short, the imported_members option is set to True if the object has __all__ member and autosummary is set to have autosummary_ignore_module_all set to False
@ClementPinard
Copy link
Contributor Author

See a proposition for how to fix it here : #10811

@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
ClementPinard added a commit to ClementPinard/sphinx that referenced this issue Apr 4, 2023
Fixes sphinx-doc#10809

* the option autosummary_ignore_module_all when set to False adds members to module's members entry that will be used for autodoc, but otherwise it ignores it. As such, if a class is available in the __all__, it won't be generated.
* This commit aims at extending the __all__ handling not only to members, but also to corresponding attribute types (function, classes, exceptions, modules)
* In short, the imported_members option is set to True if the object has __all__ member and autosummary is set to have autosummary_ignore_module_all set to False
@AA-Turner AA-Turner changed the title Autosummary : autosummary_ignore_module_all does not work as documented Autosummary : autosummary_ignore_module_all does not work as documented Apr 4, 2023
@AA-Turner AA-Turner changed the title Autosummary : autosummary_ignore_module_all does not work as documented Autosummary: autosummary_ignore_module_all does not work as documented Apr 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2023
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.

2 participants