forked from lightspeed-core/lightspeed-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_doc.py
More file actions
executable file
·67 lines (53 loc) · 1.97 KB
/
gen_doc.py
File metadata and controls
executable file
·67 lines (53 loc) · 1.97 KB
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
#!/usr/bin/env python3
"""Generate documentation for all modules from Lightspeed Core Stack service."""
import os
import ast
from pathlib import Path
DIRECTORIES = ["src", "tests/unit", "tests/integration", "tests/e2e"]
def generate_docfile(directory):
"""Generate README.md in the CWD."""
with open("README.md", "w", encoding="utf-8", newline="\n") as indexfile:
print(
f"# List of source files stored in `{directory}` directory",
file=indexfile,
)
print("", file=indexfile)
files = sorted(os.listdir())
for file in files:
if file.endswith(".py"):
print(f"## [{file}]({file})", file=indexfile)
with open(file, "r", encoding="utf-8") as fin:
source = fin.read()
try:
mod = ast.parse(source)
doc = ast.get_docstring(mod)
except SyntaxError:
doc = None
if doc:
print(doc.splitlines()[0], file=indexfile)
print(file=indexfile)
def generate_documentation_on_path(path):
"""Generate documentation for all the sources found in path."""
directory = path
cwd = os.getcwd()
os.chdir(directory)
print(f"[gendoc] Generating README.md in: {directory}")
try:
generate_docfile(directory)
finally:
os.chdir(cwd)
def main():
"""Entry point to this script, regenerates documentation in all directories."""
for directory in DIRECTORIES:
generate_documentation_on_path(f"{directory}/")
for path in Path(directory).rglob("*"):
if path.is_dir():
if (
path.name == "lightspeed_stack.egg-info"
or path.name == "__pycache__"
or ".ruff_cache" in str(path)
):
continue
generate_documentation_on_path(path)
if __name__ == "__main__":
main()