Skip to content

Commit

Permalink
Configure autosummary in conf.py
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-narozniak committed Nov 28, 2023
1 parent e2f43d9 commit 6773473
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.graphviz",
Expand All @@ -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"]

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6773473

Please sign in to comment.