-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version for auto generation api
- Loading branch information
1 parent
e0ccc0c
commit a228dd2
Showing
6 changed files
with
85 additions
and
45 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 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
3 changes: 0 additions & 3 deletions
3
src/scicookie/{{cookiecutter.project_slug}}/docs/api/references.md
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/scicookie/{{cookiecutter.project_slug}}/scripts/gen_ref_nav.py
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,51 @@ | ||
""" | ||
Generate the code reference pages and navigation. | ||
REF: | ||
https://github.com/mkdocstrings/mkdocstrings/blob/main/scripts/gen_ref_nav.py | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import mkdocs_gen_files | ||
|
||
nav = mkdocs_gen_files.Nav() | ||
mod_symbol = '<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code>' | ||
|
||
root = Path(__file__).parent.parent | ||
src = {{ cookiecutter.project_layout == "src" }} | ||
{% if cookiecutter.project_layout == "src" -%} | ||
{% set src = root / "src" -%} | ||
{% else -%} | ||
{% set src = cookiecutter.package_slug -%} | ||
{% endif -%} | ||
|
||
for path in sorted(src.rglob("*.py")): | ||
module_path = path.relative_to(src).with_suffix("") | ||
doc_path = path.relative_to(src / "cookiecutter.package_slug").with_suffix(".md") | ||
full_doc_path = Path("api", doc_path) | ||
|
||
parts = tuple(module_path.parts) | ||
|
||
if parts[-1] == "__init__": | ||
parts = parts[:-1] | ||
doc_path = doc_path.with_name("index.md") | ||
full_doc_path = full_doc_path.with_name("index.md") | ||
elif parts[-1].startswith("_"): | ||
continue | ||
|
||
nav_parts = [f"{mod_symbol} {part}" for part in parts] | ||
nav[tuple(nav_parts)] = doc_path.as_posix() | ||
|
||
with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
ident = ".".join(parts) | ||
fd.write(f"::: {ident}") | ||
|
||
mkdocs_gen_files.set_edit_path( | ||
full_doc_path, ".." / path.relative_to(root) | ||
) | ||
|
||
with mkdocs_gen_files.open("api/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