-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtasks.py
239 lines (198 loc) · 5.89 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Invoke is broken on Python 3.11
# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106
import inspect
import os
import re
import sys
from enum import Enum
from typing import Optional
if not hasattr(inspect, "getargspec"):
inspect.getargspec = inspect.getfullargspec
import invoke # pylint: disable=wrong-import-position
from invoke import task # pylint: disable=wrong-import-position
# Specifying encoding because Windows crashes otherwise when running Invoke
# tasks below:
# UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd'
# in position 16: character maps to <undefined>
# People say, it might also be possible to export PYTHONIOENCODING=utf8 but this
# seems to work.
# FIXME: If you are a Windows user and expert, please advise on how to do this
# properly.
sys.stdout = open( # pylint: disable=consider-using-with
1, "w", encoding="utf-8", closefd=False, buffering=1
)
# To prevent all tasks from building to the same virtual environment.
# All values correspond to the configuration in the tox.ini config file.
class ToxEnvironment(str, Enum):
CHECK = "check"
def run_invoke(
context,
cmd,
environment: Optional[dict] = None,
warn: bool = False,
) -> invoke.runners.Result:
def one_line_command(string):
return re.sub("\\s+", " ", string).strip()
return context.run(
one_line_command(cmd),
env=environment,
hide=False,
warn=warn,
pty=False,
echo=True,
)
def run_invoke_with_tox(
context,
environment_type: ToxEnvironment,
command: str,
) -> invoke.runners.Result:
assert isinstance(environment_type, ToxEnvironment)
assert isinstance(command, str)
tox_py_version = f"py{sys.version_info.major}{sys.version_info.minor}"
return run_invoke(
context,
f"""
tox
-e {tox_py_version}-{environment_type.value} --
{command}
""",
)
@task
def clean(context):
# https://unix.stackexchange.com/a/689930/77389
clean_command = """
rm -rfv output/ docs/sphinx/build/
"""
run_invoke(context, clean_command)
@task
def clean_itest_artifacts(context):
# https://unix.stackexchange.com/a/689930/77389
find_command = """
git clean -dfX tests/integration/
"""
# The command sometimes exits with 1 even if the files are deleted.
# warn=True ensures that the execution continues.
run_invoke(context, find_command, warn=True)
@task
def server(context, input_path="."):
assert os.path.isdir(input_path), input_path
run_invoke_with_tox(
context,
ToxEnvironment.CHECK,
f"""
strictdoc server {input_path} --reload
""",
)
@task
def test_integration(
context,
focus=None,
debug=False,
strictdoc=None,
environment=ToxEnvironment.CHECK,
):
clean_itest_artifacts(context)
cwd = os.getcwd()
if strictdoc is None:
strictdoc_exec = f'strictdoc'
else:
strictdoc_exec = strictdoc
focus_or_none = f"--filter {focus}" if focus else ""
debug_opts = "-vv --show-all" if debug else ""
itest_command = f"""
lit
--param STRICTDOC_EXEC="{strictdoc_exec}"
-v
{debug_opts}
{focus_or_none}
{cwd}/tests/integration
"""
# It looks like LIT does not open the RUN: subprocesses in the same
# environment from which it itself is run from. This issue has been known by
# us for a couple of years by now. Not using Tox on Windows for the time
# being.
if os.name == "nt":
run_invoke(context, itest_command)
return
run_invoke_with_tox(
context,
environment,
itest_command,
)
@task
def test(context):
test_integration(context)
@task
def check(context):
test(context)
@task
def check_dead_links(context):
pass
# run_invoke_with_tox(
# context,
# ToxEnvironment.CHECK,
# """
# python3 tools/link_health.py docs/strictdoc_01_user_guide.sdoc
# """,
# )
@task
def watch(context, sdocs_path="."):
strictdoc_command = f"""
strictdoc
export
{sdocs_path}
--output-dir output/
--experimental-enable-file-traceability
"""
run_invoke_with_tox(
context,
ToxEnvironment.CHECK,
f"""
{strictdoc_command}
""",
)
paths_to_watch = "."
run_invoke_with_tox(
context,
ToxEnvironment.CHECK,
f"""
watchmedo shell-command
--patterns="*.py;*.sdoc;*.jinja;*.html;*.css;*.js"
--recursive
--ignore-pattern='output/;tests/integration'
--command='{strictdoc_command}'
--drop
{paths_to_watch}
""",
)
@task
def run(context, command):
run_invoke_with_tox(
context,
ToxEnvironment.CHECK,
f"""
{command}
""",
)
@task
def bitfield(context,input, output, lanes, bits):
command = f"""bit_field --lanes {lanes} --bits {bits} --fontsize 8 --hspace 750 --vspace 40 {input} > {output}"""
run_invoke(context, command)
@task
def cairosvg(context,input,output):
command = f"""cairosvg {input} -o {output}"""
run_invoke(context, command)
@task
def readthedoc(context):
strictdoc2rst(context,'templates/DO-178C/doc','templates/DO-178C')
doxygen(context,"templates/DO-178C/.doxygen")
bitfield(context,'templates/DO-178C/_assets/A429.json','templates/DO-178C/_assets/A429.svg',1,32)
cairosvg(context,'templates/DO-178C/_assets/A429.svg','templates/DO-178C/_assets/A429.pdf')
@task
def strictdoc2rst(context,input,output):
command = f"""strictdoc export --output-dir {output} --project-title DO-178C --format rst {input}"""
run_invoke(context, command)
@task
def doxygen(context,config):
command = f"""doxygen {config}"""
run_invoke(context, command)