-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
By default, make Autosummary templates generate documentation pages for classes, functions, exceptions etc #7912
Comments
Thank you for proposal. Good idea! On the other hand, I prefer to show the methods and attributes of the class in the same file (like Javadoc does). So it would be nice if we'll add Anyway, the modification of the template brings a breaking change. So we have to change them on 4.0 release. |
Note: Adding |
The Sphinx documentation is opaque, to put it mildly, but this seems to work. These were helpful: - https://romanvm.pythonanywhere.com/post/autodocumenting-your-python-code-sphinx-part-ii-6/ - sphinx-doc/sphinx#7912
@JamesALeedham First of all, thanks a lot for the solution on the StackOverflow question. I think it would make the auto_summary extension even more useful. There are, however, several problems I noticed while using the the StackOverflow question or the solution in this issue: Stackoverflow versionThe solution breaks if classes are imported onto a higher namespace using an init.py fileLet's say we have the following project structure: └── package
└── submodule
├── __init__.py
└── subsubmodule
└── subsubsubmodule.py Now try to make the package.submodule.init.py from package.submodule.subsubmodule.subsubmodule import Class This prevents the auto summaries for the classes, functions and methods of the .. rubric:: Classes
.. autosummary::
:toctree:
:template: custom-class-template.rst
Class
.. rubric:: Functions
.. autosummary::
:toctree:
function_1 This is related to this sphinx issue. This can be solved by using the The templates don't work nicely with intersphinx bindingsWhen I use this workaround combined with the intersphinx bindings, it could lead to possible errors if a class inherits from a base class that contains sphinx errors. I, for example, use the https://github.com/mr-ubik/tensorflow-intersphinx/ TensorFlow bindings, which contain several errors. Therefore, maybe care should be taken when hardcoding the The version in this issueWhen I omit the |
Hi @rickstaa , thanks for getting back to me. I admit I only tested my solution on a few live projects, and didn't set out to test it exhaustively on a wide set of possible scenarios, so not surprised you've found cases where it doesn't work! Thanks for trying it out... I'll be guided by what you experts think is best, of course. For my part, when getting started with Sphinx I found it hard to get something that 'quickly' & 'nearly' worked so that I could see I was on the right tracks (and from the responses I've had on StackOverflow and other places I am not alone!). The goal with my solution (or something similar) is to get a majority of people up and running with something tangible out-of-the-box a bit quicker, and then let people explore Sphinx's myriad settings and options to tailor their experience at their own leisure. I hope it is a step in the right direction there, though naturally I realise it won't entirely work for everyone... |
@JamesALeedham, I think your solution is good as it works in most use cases. I use it in most of my projects. My previous comment was mainly to provide the sphinx developers like @guyer and @tk0miya with the uses cases in which it does not work. I'm not familiar enough with the sphinx and |
@rickstaa I'm not a sphinx developer! |
Ha @guyer sorry for making that assumption. |
Hey guys! Any progress on this feature? |
Hey there, waiting for this very useful feature. Can someone share when it would be released in Sphinx? |
I am working with it where I have a following folder structure:-
The script for templates is completely same as given on stackoverflow. Following is my code for
config.py
However, with this code I am unable to access the documentation in separate page for classes and functions in
i.e. specifying each file individually.
|
Hi, I'm trying to use the recursive option with the modified template to create stubs for functions, attributes etc. But, this also includes attributes, functions etc. in the navigation toctree. Is there a way to recursively generate all stubs (with corresponding links in the summary tables), but limit the depth of the navigation (or limit it to entries only for packages and modules)? |
@buhrmann Did you find a solution? I am having the same problem. |
... and also attributes, exaptions or functions and attributes on module level. When a class is added to an ".. autosummary" directive, the docstring for the class itself is automatically generated for the reference docs, but any methods or attributes are not. With a set of private autosummary templates and following the comments in sphinx-doc/sphinx#7912 now all elements will be respected by autosummary and all Python dostrings will convert into RST. Signed-off-by: Stephan Linz <linz@li-pro.net>
... and also attributes, exaptions or functions and attributes on module level. When a class is added to an ".. autosummary" directive, the docstring for the class itself is automatically generated for the reference docs, but any methods or attributes are not. With a set of private autosummary templates and following the comments in sphinx-doc/sphinx#7912 now all elements will be respected by autosummary and all Python dostrings will convert into RST. Signed-off-by: Stephan Linz <linz@li-pro.net>
... and also attributes, exaptions or functions and attributes on module level. When a class is added to an ".. autosummary" directive, the docstring for the class itself is automatically generated for the reference docs, but any methods or attributes are not. With a set of private autosummary templates and following the comments in sphinx-doc/sphinx#7912 now all elements will be respected by autosummary and all Python dostrings will convert into RST. Signed-off-by: Stephan Linz <linz@li-pro.net>
... and also attributes, exaptions or functions and attributes on module level. When a class is added to an ".. autosummary" directive, the docstring for the class itself is automatically generated for the reference docs, but any methods or attributes are not. With a set of private autosummary templates and following the comments in sphinx-doc/sphinx#7912 now all elements will be respected by autosummary and all Python dostrings will convert into RST. Signed-off-by: Stephan Linz <linz@li-pro.net>
Thank you so much @JamesALeedham, being new to autosummary I completely expected what you suggest to be the expected behaviour, this was driving me mad!! 🍔 |
Thanks for sharing, @mhostetter. Your docs look amazing! |
* Automatically generate rst files using the `autosummary` extension. * The generated rst internally use the `autodoc` extension to automatically generate the desired documentation. * Added autosummary templates to force an "extensive" documentation (e.g., modules, classes, members: methods, attributes, etc.) to be generated by autodoc, instead of simply a table with the first line of the docstrings. (See sphinx-doc/sphinx#7912) * Added the `api.rst` and updated the `index.rst` files to include the auto-generated documentation in the Table of Contents. * Removed the `generate-autodoc` make target, as we do not need it anymore. * Adapted the gitignore.
Love the theming in https://galois.readthedocs.io/en/stable/api/! |
Another alternative is to use sphinxcontrib-apidoc. I prefer this to |
Is your feature request related to a problem? Please describe.
The new
:recursive:
option forsphinx.ext.autosummary
is great. I can point Sphinx at the top of my package and have it find every module, however deeply nested. For each module it creates neat summary tables listing all the attributes, classes, exceptions and functions in those modules. This is all fantastic.To generate actual documentation pages for these attributes, classes, exceptions and functions, however, and link to them from the summary tables, I have to copy the default
module.rst
andclass.rst
templates locally and edit them. I would like to think this is what most people would want. So I think it should be the default behavior - and those who don't want this should have to customize the templates.Describe the solution you'd like
I've described the solution I'd like to see here. There's a Github test implementation here and a sample ReadTheDocs user experience here.
(I'm sure you know what the current user experience is like but, just to be clear, you can reproduce it by cloning the Github test project and deleting the
:template: custom-module-template.rst
line indocs/source/index.rst
.)Basically, the solution involves adding a
:toctree:
option to every.. autosummary::
directive in the defaultmodule.rst
template so that documentation pages get generated for attributes, classes, exceptions and functions out-of-the-box, like this:site-packages/sphinx/ext/autosummary/templates/autosummary/module.rst
(additional lines noted on right):The text was updated successfully, but these errors were encountered: