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
Comments
After some investigation in the code, I do believe that there is a problem in the generate.py file, when populating the https://github.com/sphinx-doc/sphinx/blob/5.x/sphinx/ext/autosummary/generate.py#L313 Problem with
|
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.
sphinx/sphinx/ext/autosummary/generate.py
Line 320 in 7473b05
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.
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
See a proposition for how to fix it here : #10811 |
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
autosummary_ignore_module_all
does not work as documented
autosummary_ignore_module_all
does not work as documentedautosummary_ignore_module_all
does not work as documented
Describe the bug
As per documentation :
So the way I understand it is that if I have a small package like this :
with the following files :
my_class.py
my_submodule.py
__init__.py
and a rst file like this:
assume the option
autosummary_ignore_module_all
is set toFalse
inconf.py
, the autosummary should only considermyClass
andmy_module
to be part of the packagemy_package
. Thegenerated
folder should normally look like this:But actually, it looks like this :
Meaning it ignored the imported elements, even though they were in the
__all__
and it did take themy_module
package even though it was not in the__all__
How to Reproduce
Expected behavior
generated folder should have the files
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
The text was updated successfully, but these errors were encountered: