-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_reference_docs.py
85 lines (58 loc) · 2.75 KB
/
generate_reference_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright 2023 Unai Lería Fortea & Pablo Vizcaíno García
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generate the code reference pages and navigation. Ty mkdocstrings"""
from pathlib import Path
import mkdocs_gen_files
nav = mkdocs_gen_files.Nav()
LICENSE = """<!-- Copyright 2023 PhasePortriat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
"""
# import shutil
# shutil.copy("README.md", "docs/index.md")
# shutil.copy("LICENSE", "docs/LICENSE.md")
for path in sorted(Path("phaseportrait").rglob("*.py")):
module_path = path.with_suffix("")
doc_path = path.with_suffix(".md")
full_doc_path = Path("reference", doc_path)
parts = tuple(module_path.parts)
if parts[-1] == "__init__":
continue
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue
nav[("reference", *parts)] = full_doc_path.as_posix()
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(LICENSE)
fd.write(f":::{ident}")
mkdocs_gen_files.set_edit_path(full_doc_path, Path("../") / path)
for path in sorted(list(Path("examples").rglob("*.md"))):
example_name = path.with_suffix("")
doc_path = path.with_suffix(".md")
full_doc_path = Path(doc_path)
parts = tuple(example_name.parts)
nav[("examples", *parts)] = full_doc_path.as_posix()
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(''.join([line for line in open(path, 'r').readlines()]))
mkdocs_gen_files.set_edit_path(full_doc_path, Path("../") / path)
with mkdocs_gen_files.open("SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())