gen_ref_pages   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 0
1
"""Generate the code reference pages and navigation."""
2
3
from pathlib import Path
4
5
import mkdocs_gen_files
6
7
nav = mkdocs_gen_files.Nav()
8
9
ignore = ('cli.py', 'color.py', 'converters.py', 'constants.py', 'server', 'tools')
10
11
for path in sorted(Path("src").rglob("*.py")):
12
    if any(v in path.as_posix() for v in ignore):
13
        print(path)
14
        continue
15
    module_path = path.relative_to("src").with_suffix("")
16
    doc_path = path.relative_to("src").with_suffix(".md")
17
    full_doc_path = Path("reference", doc_path)
18
19
    parts = tuple(module_path.parts)
20
21
    if parts[-1] == "__init__":
22
        parts = parts[:-1]
23
        doc_path = doc_path.with_name("index.md")
24
        full_doc_path = full_doc_path.with_name("index.md")
25
    elif parts[-1] == "__main__":
26
        continue
27
28
    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("../") / path)  #
35
36
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:  #
37
    nav_file.writelines(nav.build_literate_nav())  #
38