Commit 207bb3ef authored by Alexander L. Hayes's avatar Alexander L. Hayes Committed by Nikita Titov
Browse files

[docs] 🎨 Sphinx Autosummary for generating Python-API documentation (#2286)

* 🎨 `sphinx.ext.autosummary` for generating Python-API summaries

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.

* ️ Corrections following feedback

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`

* ️ Replacing deprecated Sphinx parameter

Fix deprecated `autodoc_default_flags` to `autodoc_default_options`

* ️ Adding `autodoc_default_flags` in to support early Sphinx versions

Add `autodoc_default_flags` with parameters from
  `autodoc_default_options`
parent 5dc1507e
...@@ -339,6 +339,7 @@ instance/ ...@@ -339,6 +339,7 @@ instance/
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
docs/pythonapi/
# Doxygen documentation # Doxygen documentation
docs/doxyoutput/ docs/doxyoutput/
......
Python API Python API
========== ==========
.. currentmodule:: lightgbm
Data Structure API Data Structure API
------------------ ------------------
.. autoclass:: lightgbm.Dataset .. autosummary::
:members: :toctree: pythonapi/
:show-inheritance:
.. autoclass:: lightgbm.Booster
:members:
:show-inheritance:
Dataset
Booster
Training API Training API
------------ ------------
.. autofunction:: lightgbm.train .. autosummary::
:toctree: pythonapi/
.. autofunction:: lightgbm.cv
train
cv
Scikit-learn API Scikit-learn API
---------------- ----------------
.. autoclass:: lightgbm.LGBMModel .. autosummary::
:members: :toctree: pythonapi/
:inherited-members:
:show-inheritance:
.. autoclass:: lightgbm.LGBMClassifier
:members:
:inherited-members:
:show-inheritance:
.. autoclass:: lightgbm.LGBMRegressor
:members:
:inherited-members:
:show-inheritance:
.. autoclass:: lightgbm.LGBMRanker
:members:
:inherited-members:
:show-inheritance:
LGBMModel
LGBMClassifier
LGBMRegressor
LGBMRanker
Callbacks Callbacks
--------- ---------
.. autofunction:: lightgbm.early_stopping .. autosummary::
:toctree: pythonapi/
.. autofunction:: lightgbm.print_evaluation
.. autofunction:: lightgbm.record_evaluation
.. autofunction:: lightgbm.reset_parameter
early_stopping
print_evaluation
record_evaluation
reset_parameter
Plotting Plotting
-------- --------
.. autofunction:: lightgbm.plot_importance .. autosummary::
:toctree: pythonapi/
.. autofunction:: lightgbm.plot_split_value_histogram
.. autofunction:: lightgbm.plot_metric
.. autofunction:: lightgbm.plot_tree
.. autofunction:: lightgbm.create_tree_digraph plot_importance
plot_split_value_histogram
plot_metric
plot_tree
create_tree_digraph
...@@ -68,14 +68,25 @@ if needs_sphinx > sphinx.__version__: ...@@ -68,14 +68,25 @@ if needs_sphinx > sphinx.__version__:
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.todo', 'sphinx.ext.todo',
'sphinx.ext.viewcode', 'sphinx.ext.viewcode',
'sphinx.ext.napoleon', 'sphinx.ext.napoleon',
] ]
autodoc_default_flags = ['members', 'inherited-members', 'show-inheritance']
autodoc_default_options = {
"members": True,
"inherited-members": True,
"show-inheritance": True,
}
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
# Generate autosummary pages. Output should be set with: `:toctree: pythonapi/`
autosummary_generate = True
# The suffix(es) of source filenames. # The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string: # You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md'] # source_suffix = ['.rst', '.md']
...@@ -117,7 +128,7 @@ pygments_style = 'default' ...@@ -117,7 +128,7 @@ pygments_style = 'default'
todo_include_todos = False todo_include_todos = False
# Both the class' and the __init__ method's docstring are concatenated and inserted. # Both the class' and the __init__ method's docstring are concatenated and inserted.
autoclass_content = 'both' autoclass_content = 'class'
# -- Configuration for C API docs generation ------------------------------ # -- Configuration for C API docs generation ------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment