From 67734737b76246ab0f719e2dd1786eda22ab392b Mon Sep 17 00:00:00 2001 From: Adam Narozniak Date: Tue, 28 Nov 2023 11:07:01 +0100 Subject: [PATCH] Configure autosummary in conf.py --- doc/source/conf.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 87860e2c6e7b..c6d6ed1444a3 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -95,6 +95,7 @@ extensions = [ "sphinx.ext.napoleon", "sphinx.ext.autodoc", + "sphinx.ext.autosummary", "sphinx.ext.mathjax", "sphinx.ext.viewcode", "sphinx.ext.graphviz", @@ -108,6 +109,42 @@ "nbsphinx", ] +# Generate .rst files +autosummary_generate = True + +# Document ONLY the objects from __all__ (present in __init__ files). +# It will be done recursively starting from flwr.__init__ +# Starting point is controlled in the index.rst file. +autosummary_ignore_module_all = False + +# Each class and function docs start with the path to it +# Make the flwr_datasets.federated_dataset.FederatedDataset appear as FederatedDataset +# The full name is still at the top of the page +add_module_names = False + +def find_test_modules(package_path): + """Go through the python files and exclude every *_test.py file.""" + full_path_modules = [] + for root, dirs, files in os.walk(package_path): + for file in files: + if file.endswith('_test.py'): + # Construct the module path relative to the package directory + full_path = os.path.join(root, file) + relative_path = os.path.relpath(full_path, package_path) + # Convert file path to dotted module path + module_path = os.path.splitext(relative_path)[0].replace(os.sep, '.') + full_path_modules.append(module_path) + modules = [] + for full_path_module in full_path_modules: + parts = full_path_module.split('.') + for i in range(len(parts)): + modules.append('.'.join(parts[i:])) + return modules + +# Stop from documenting the *_test.py files. +# That's the only way to do that in autosummary (make the modules as mock_imports). +autodoc_mock_imports = find_test_modules(os.path.abspath("../../src/py/flwr")) + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -173,7 +210,8 @@ "evaluation": "explanation-federated-evaluation.html", "differential-privacy-wrappers": "explanation-differential-privacy.html", # Restructuring: references - "apiref-flwr": "ref-api-flwr.html", + "apiref-flwr": "ref-api/flwr.html", + "ref-api-flwr": "ref-api/flwr.html", "apiref-cli": "ref-api-cli.html", "examples": "ref-example-projects.html", "telemetry": "ref-telemetry.html",