-
Notifications
You must be signed in to change notification settings - Fork 7
/
document_python.py
58 lines (45 loc) · 1.33 KB
/
document_python.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
import json
import os
import click
from devtale.aggregators.python import PythonAggregator
DEFAULT_OUTPUT_PATH = "devtale_demo/"
def document_python_file(
source_file: str, documentation_file: str, output_path: str = DEFAULT_OUTPUT_PATH
):
aggregator = PythonAggregator()
with open(documentation_file, "r") as file:
documentation = json.load(file)
with open(source_file, "r") as file:
code = file.read()
documented_code = aggregator.document(code=code, documentation=documentation)
file_name = os.path.basename(source_file)
save_path = os.path.join(output_path, file_name)
with open(save_path, "w") as file:
file.write(documented_code)
@click.command()
@click.option(
"-s",
"--source",
"source",
required=True,
help="The path to the code file",
)
@click.option(
"-d",
"--documentation",
"documentation",
required=True,
help="The path to the documentation JSON file",
)
@click.option(
"-o",
"--output-path",
"output_path",
required=False,
default=DEFAULT_OUTPUT_PATH,
help="The destination folder where you want to save the documentated source",
)
def main(source: str, documentation: str, output_path: str = DEFAULT_OUTPUT_PATH):
document_python_file(source, documentation, output_path)
if __name__ == "__main__":
main()