-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
103 lines (78 loc) · 3.15 KB
/
tasks.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from pathlib import Path
import invoke
@invoke.task
def build(ctx):
"""
An umbrella task, currently only calls the cog
"""
cog(ctx)
def schema_file_path() -> Path:
return Path(__file__).parent / "src/alfasim_sdk/_internal/alfacase/schema.py"
def case_description_source_file_path() -> Path:
return (
Path(__file__).parent / "src/alfasim_sdk/_internal/alfacase/case_description.py"
)
def alfacase_definitions_path() -> Path:
return Path(__file__).parent / "docs/source/alfacase_definitions"
@invoke.task(
help={
"check": "Run cog in check mode ensuring that schema has not being changed.",
}
)
def cog(ctx, check=False):
"""
Executes cog
- on `_internal/alfacase/case_description.py`;
- on `_internal/alfacase/schema.py` to generate the schema for strictyaml;
- generate some documentation files;
"""
ctx.run(command=f"cog -rc {case_description_source_file_path()}", warn=True)
ctx.run(command=f"cog -rc {schema_file_path()}", warn=True)
from alfasim_sdk._internal.alfacase.generate_schema import (
get_all_classes_that_needs_schema,
)
from alfasim_sdk._internal.alfacase.case_description import CaseDescription
from alfasim_sdk._internal.alfacase.generate_case_description_docstring import (
generate_definition,
)
alfacase_definitions_path().mkdir(parents=True, exist_ok=True)
alfacase_definitions_cogged_files = set()
def write_alfacase_definitions_cogged_file(filename, content):
alfacase_definitions_cogged_files.add(filename)
Path(alfacase_definitions_path() / filename).write_text(content)
for class_ in get_all_classes_that_needs_schema(CaseDescription):
output = generate_definition(class_)
write_alfacase_definitions_cogged_file(f"{class_.__name__}.txt", output)
from alfasim_sdk._internal.alfacase.generate_case_description_docstring import (
generate_list_of_units,
CATEGORIES_USED_ON_DESCRIPTION,
)
for category in CATEGORIES_USED_ON_DESCRIPTION:
output = generate_list_of_units(category)
category_for_path = category.replace(" ", "_")
write_alfacase_definitions_cogged_file(
f"list_of_unit_for_{category_for_path}.txt", output
)
for filepath in alfacase_definitions_path().glob("*.txt"):
filename = filepath.name
if filename not in alfacase_definitions_cogged_files:
print(f"Removing {filepath}")
filepath.unlink()
if check:
check_cog(ctx)
@invoke.task
def check_cog(ctx):
"""
Check if the cogged files have unstaged modifications
- `_internal/alfacase/case_description.py`;
- `_internal/alfacase/schema.py`;
- generated documentation files;
"""
ctx.run(f"git diff --no-ext-diff --exit-code {case_description_source_file_path()}")
ctx.run(f"git diff --no-ext-diff --exit-code {schema_file_path()}")
ctx.run(f"git diff --no-ext-diff --exit-code {alfacase_definitions_path()}")
@invoke.task
def docs(ctx):
with ctx.cd("docs"):
ctx.run("doxygen alfasim_sdk_api.cfg")
ctx.run("sphinx-build --keep-going -W -b html source _build/html")