-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate API reference automatically
- Loading branch information
Showing
10 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Generate the code API reference pages | ||
Refer to https://mkdocstrings.github.io/recipes/ for more details. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import mkdocs_gen_files | ||
|
||
SRC_PATH = "pixano_inference" | ||
REF_PATH = "code" | ||
IGNORED_FILES = ["__init__.py", "__version__.py"] | ||
|
||
nav = mkdocs_gen_files.Nav() | ||
|
||
for path in sorted(Path(SRC_PATH).rglob("*.py")): | ||
module_path = path.relative_to(SRC_PATH).with_suffix("") | ||
doc_path = path.relative_to(SRC_PATH).with_suffix(".md") | ||
full_doc_path = Path(REF_PATH, doc_path) | ||
|
||
parts = list(module_path.parts) | ||
|
||
if parts[-1] == "__init__": | ||
parts = parts[:-1] | ||
elif parts[-1] == "__main__": | ||
continue | ||
|
||
# Create root index file | ||
if not parts: | ||
doc_path = doc_path.with_name("index.md") | ||
full_doc_path = full_doc_path.with_name("index.md") | ||
nav["index"] = doc_path.as_posix() | ||
with open(f"docs/{REF_PATH}/index.md", "r") as index_file: | ||
lines = index_file.readlines() | ||
with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
fd.writelines(lines) | ||
mkdocs_gen_files.set_edit_path(full_doc_path, path) | ||
|
||
# Add all python files that are not in the ignore list | ||
elif not any(ignored in path.name for ignored in IGNORED_FILES): | ||
nav[parts] = doc_path.as_posix() | ||
with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
identifier = ".".join(parts) | ||
print("::: " + identifier, file=fd) | ||
mkdocs_gen_files.set_edit_path(full_doc_path, path) | ||
|
||
|
||
with mkdocs_gen_files.open(f"{REF_PATH}/SUMMARY.md", "w") as nav_file: | ||
nav_file.writelines(nav.build_literate_nav()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters