[docs] 🎨 Sphinx Autosummary for generating Python-API documentation#2286
[docs] 🎨 Sphinx Autosummary for generating Python-API documentation#2286StrikerRUS merged 4 commits intolightgbm-org:masterfrom hayesall:pydocs
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.
@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_contentvalue:
https://github.com/microsoft/LightGBM/blob/5d3a3ea47eb8693c924ffb891387e93534f92896/docs/conf.py#L120

UPD: It can be fixed by setting
autoclass_contentto'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.
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/autofunctionwith sphinx autosummary to create and paginate the Python API.Summary of Changes
docs/.gitignoreto not track autosummary stubssphinx.ext.autosummaryindocs/conf.py:toctree:.. autosummary::tags to replace.. autoclass::and.. autofunction::Pull Request Motivation 📝
Previously the
Python-API.rstdumped all of the Python API onto a single page whensphinx-buildgenerated 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
autoclassandautofunctionon 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.htmllanding pageTraining API:
lightgbm.cv. Thelightgbm.cvfunction has its own page.