-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[docs] 🎨 Sphinx Autosummary for generating Python-API documentation #2286
Conversation
Add `docs/.gitignore` to not track autosummary stubs Add `sphinx.ext.autosummary` in `docs/conf.py` Add 'members' and 'inherited-members' as default parameters Add 'autosummary = True' for setting output with `:toctree:` Add `.. autosummary::` tags to replace `.. autoclass::` Previously the `Python-API.rst` dumped all of the Python API onto a single page. This replaces the Python-API documentation with an index listing all modules, and paginates all functions and classes onto separate pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hayesall Thanks a lot for your contribution! It looks nice from a first glance! Please let me describe a few drawbacks I see.
-
It breaks previous links to Python API from third-party sites.
-
It generates duplicated entries for class constructors. I guess a workaround can be found by playing around with
autoclass_content
value:
Line 120 in 5d3a3ea
autoclass_content = 'both'
UPD: It can be fixed by setting
autoclass_content
to'class'
. -
It removes class inheritance (previously controlled by
:show-inheritance:
flag).
UPD: Can be fixed by appending'show-inheritance'
toautodoc_default_flags
.
Drop `docs/.gitignore` to use the general `.gitignore` Add `show-inheritance` to `autodoc_default_flags` in `docs/conf.py` Fix `both` to `class` in `autoclass_content` in `docs/conf.py`
✅ Fixed the autodoc_default_flags = ['members', 'inherited-members', 'show-inheritance'] ✅ Changing ❓ I don't have a solution for third-party links, but here is what I have currently:
|
Indeed! Since index page is rather small now, it should be not so hard for users to seek for the specified API member manually. |
Fix deprecated `autodoc_default_flags` to `autodoc_default_options`
Add `autodoc_default_flags` with parameters from `autodoc_default_options`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@hayesall Thank you for your contribution! Separate pages look much better than previous huge wall of API code.
@hayesall I'm sorry for the late question, but according to the logs it seems that
|
@StrikerRUS Sphinx's The I can look later today. If it's an easy fix I'll try to patch it in with #2293. If it's a bit more involved I'll open an issue. |
@hayesall Thanks a lot for your answer with starting points! It's absolutely not urgent and critical. Please do not include any fix in #2293, because that PR is about different things. Just post updates here if you find anything valuable or make a new PR if you'd like (and have enough free time 😄 ). |
Executive Summary
This replaces
autoclass/autofunction
with sphinx autosummary to create and paginate the Python API.Summary of Changes
docs/.gitignore
to not track autosummary stubssphinx.ext.autosummary
indocs/conf.py
:toctree:
.. autosummary::
tags to replace.. autoclass::
and.. autofunction::
Pull Request Motivation 📝
Previously the
Python-API.rst
dumped all of the Python API onto a single page whensphinx-build
generated html pages.This replaces the Python-API documentation with an index listing all modules, and paginates all functions and classes onto separate pages.
In summary, this pull request:
Alternatives
This could also be accomplished by creating individual pages by hand and putting
autoclass
andautofunction
on each. Autosummary simply makes this process more scalable.Any feedback would be appreciated. Thank you developers!
Screenshots
Before (left) and After (right) of the
Python-API.html
landing pageTraining API:
lightgbm.cv
. Thelightgbm.cv
function has its own page.