Debian Codegraph @

docs/gen_ref_nav.py

raw
1 """Generate the code reference pages and navigation."""
2
3 from pathlib import Path
4
5 import mkdocs_gen_files
6
7 SRC = Path("src")
8 PKG = SRC / "app_model"
9
10 nav = mkdocs_gen_files.Nav()
11 mod_symbol = '<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code>'
12
13 for path in sorted(SRC.rglob("*.py")):
14 module_path = path.relative_to("src").with_suffix("")
15 doc_path = path.relative_to(PKG).with_suffix(".md")
16 full_doc_path = Path("reference", doc_path)
17
18 parts = tuple(module_path.parts)
19
20 if parts[-1] == "__init__":
21 parts = parts[:-1]
22 doc_path = doc_path.with_name("index.md")
23 full_doc_path = full_doc_path.with_name("index.md")
24 if parts[-1].startswith("_"):
25 continue
26
27 nav_parts = [f"{mod_symbol} {part}" for part in parts]
28 nav[tuple(nav_parts)] = doc_path.as_posix()
29
30 with mkdocs_gen_files.open(full_doc_path, "w") as fd:
31 ident = ".".join(parts)
32 fd.write(f"::: {ident}")
33
34 mkdocs_gen_files.set_edit_path(full_doc_path, ".." / path)
35
36 with mkdocs_gen_files.open("reference/SUMMARY.txt", "w") as nav_file:
37 nav_file.writelines(nav.build_literate_nav())