Skip to content
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

Refactor auto-generate aeon_mecha docs #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 19 additions & 28 deletions make_mecha_doctree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from pathlib import Path


# modules to ignore in the api doc
ignore_modules = [
Expand All @@ -12,34 +14,23 @@ def make_mecha_doctree():
Create a doctree of all modules in aeon_mecha/aeon.
"""
doctree = ""
api_path = os.path.join(".", "aeon_mecha", "aeon")
for root, dirs, files in os.walk(api_path):
# remove leading "./"
root = root[2:]
for file in sorted(files):
if file.endswith(".py") and not file.startswith("_"):
# convert file path to module name
full = os.path.join(root, file)
full = full[:-3].replace(os.sep, ".")
full = (".").join(full.split(".")[1:])
ignore = False
for ignore_module in ignore_modules:
if full.startswith(ignore_module):
ignore = True
break
if not ignore:
doctree += f" {full}\n"

# get the api doc header
with open("src/_templates/api_mecha_head.rst", "r") as f:
api_head = f.read()

# write file for api doc with header + doctree
output_dir = "./src/reference/api"
os.makedirs(output_dir, exist_ok=True)

with open(os.path.join(output_dir, "mecha.rst"), "w") as f:
f.write("..\n This file is auto-generated.\n\n")
api_path = Path("aeon_mecha") / "aeon"
for path in sorted(api_path.rglob("*.py")):
if path.name.startswith("_"):
continue
# Convert file path to module name
full = str(path.with_suffix("")).replace(os.sep, ".")
full = ".".join(full.split(".")[1:])
if not any(full.startswith(ignore_module) for ignore_module in ignore_modules):
doctree += f" {full}\n"
# Get the main page header
api_head_path = Path("src") / "_templates" / "api_mecha_head.rst"
api_head = api_head_path.read_text()
# Write main page with header and doc tree
output_dir = Path("src") / "reference" / "api"
output_dir.mkdir(parents=True, exist_ok=True)
output_file = output_dir / "mecha.rst"
with output_file.open("w") as f:
f.write(api_head)
f.write(doctree)

Expand Down
9 changes: 6 additions & 3 deletions src/_templates/api_mecha_head.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
..
This file is auto-generated.

.. _target-mecha-reference:

``aeon_mecha``
==============

.. toctree::
:caption: aeon_mecha API
:maxdepth: 1
:caption: aeon_mecha API
:maxdepth: 1

.. autosummary::
:toctree: mecha
:toctree: mecha