Skip to content

DOC refactored API page for consistency and smoother switch to pydata-sphinx-theme #28279

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sklearn/**/*.html

dist/
MANIFEST
doc/api/
doc/sg_execution_times.rst
doc/_build/
doc/auto_examples/
Expand Down
2 changes: 1 addition & 1 deletion build_tools/circle/build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ then
(
echo '<html><body><ul>'
echo "$affected" | sed 's|.*|<li><a href="&">&</a> [<a href="https://scikit-learn.org/dev/&">dev</a>, <a href="https://scikit-learn.org/stable/&">stable</a>]</li>|'
echo '</ul><p>General: <a href="index.html">Home</a> | <a href="modules/classes.html">API Reference</a> | <a href="auto_examples/index.html">Examples</a></p>'
echo '</ul><p>General: <a href="index.html">Home</a> | <a href="api/index.html">API Reference</a> | <a href="auto_examples/index.html">Examples</a></p>'
echo '<strong>Sphinx Warnings in affected files</strong><ul>'
echo "$warnings" | sed 's/\/home\/circleci\/project\//<li>/g'
echo '</ul></body></html>'
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ clean:
-rm -rf auto_examples/
-rm -rf generated/*
-rm -rf modules/generated/
-rm -rf api/

# Default to SPHINX_NUMJOBS=1 for full documentation build. Using
# SPHINX_NUMJOBS!=1 may actually slow down the build, or cause weird issues in
Expand Down
67 changes: 63 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
# redirects dictionary maps from old links to new links
redirects = {
"documentation": "index",
"modules/classes": "api/index",
"auto_examples/feature_selection/plot_permutation_test_for_classification": (
"auto_examples/model_selection/plot_permutation_tests_for_classification"
),
Expand Down Expand Up @@ -602,7 +603,7 @@ def filter_search_index(app, exception):
f.write(searchindex_text)


def generate_min_dependency_table(app):
def generate_min_dependency_table():
"""Generate min dependency table for docs."""
from sklearn._min_dependencies import dependent_packages

Expand Down Expand Up @@ -652,7 +653,7 @@ def generate_min_dependency_table(app):
f.write(output)


def generate_min_dependency_substitutions(app):
def generate_min_dependency_substitutions():
"""Generate min dependency substitutions for docs."""
from sklearn._min_dependencies import dependent_packages

Expand All @@ -669,6 +670,60 @@ def generate_min_dependency_substitutions(app):
f.write(output)


def generate_api_reference():
from sklearn._api_reference import (
API_REFERENCE,
DEPRECATED_API_REFERENCE,
get_api_reference_rst,
get_deprecated_api_reference_rst,
)

# Create the directory if it does not already exist
api_dir = Path(".") / "api"
api_dir.mkdir(exist_ok=True)

# Write API reference for each module
for module in API_REFERENCE:
with (api_dir / f"{module}.rst").open("w") as f:
f.write(get_api_reference_rst(module))

# Write the API reference index page
with (api_dir / "index.rst").open("w") as f:
f.write(".. _api_ref:\n\n")
f.write("=============\n")
f.write("API Reference\n")
f.write("=============\n\n")
f.write(
"This is the class and function reference of scikit-learn. Please refer to "
"the :ref:`full user guide <user_guide>` for further details, as the raw "
"specifications of classes and functions may not be enough to give full "
"guidelines on their uses. For reference on concepts repeated across the"
"API, see :ref:`glossary`.\n\n"
)

# Define the toctree
f.write(".. toctree::\n")
f.write(" :maxdepth: 2\n")
f.write(" :hidden:\n\n")
sorted_module_names = sorted(API_REFERENCE)
for module_name in sorted_module_names:
f.write(f" {module_name}\n")
f.write("\n")

# Write the module table
f.write(".. list-table::\n\n")
for module_name in sorted_module_names:
f.write(f" * - :mod:`{module_name}`\n")
f.write(f" - {API_REFERENCE[module_name]['short_summary']}\n\n")

# Write deprecated API
if DEPRECATED_API_REFERENCE:
f.write("Recently deprecated\n")
f.write("===================\n\n")
for ver in sorted(DEPRECATED_API_REFERENCE, key=parse, reverse=True):
f.write(get_deprecated_api_reference_rst(ver))


# Config for sphinx_issues

# we use the issues path for PRs since the issues URL will forward
Expand All @@ -684,8 +739,6 @@ def setup(app):
# do not run the examples when using linkcheck by using a small priority
# (default priority is 500 and sphinx-gallery using builder-inited event too)
app.connect("builder-inited", disable_plot_gallery_for_linkcheck, priority=50)
app.connect("builder-inited", generate_min_dependency_table)
app.connect("builder-inited", generate_min_dependency_substitutions)

# to hide/show the prompt in code examples:
app.connect("build-finished", make_carousel_thumbs)
Expand Down Expand Up @@ -822,3 +875,9 @@ def setup(app):
linkcheck_request_headers = {
"https://github.com/": {"Authorization": f"token {github_token}"},
}


# Write the files in advance to avoid any potential conflict with other extensions
generate_min_dependency_table()
generate_min_dependency_substitutions()
generate_api_reference()
2 changes: 1 addition & 1 deletion doc/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Table Of Contents
user_guide
glossary
auto_examples/index
modules/classes
api/index
developers/index
3 changes: 3 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if "%1" == "help" (
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
if exist api\ (
rmdir /q /s api
)
goto end
)

Expand Down
Loading