-
Notifications
You must be signed in to change notification settings - Fork 26
/
tasks.py
209 lines (171 loc) · 4.63 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
import os
import re
import invoke
from invoke import task
def oneline_command(string):
return re.sub("\\s+", " ", string).strip()
def run_invoke_cmd(context, cmd):
return context.run(
cmd, env=None, hide=False, warn=False, pty=False, echo=True
)
@task
def clean(context):
find_command = oneline_command(
"""
find
.
-type f \\(
-name '*.script'
\\)
-or -type d \\(
-name '*.dSYM' -or
-name 'Sandbox' -or
-name 'Output' -or
-name 'output'
\\)
-not -path "**Expected**"
-not -path "**Input**"
"""
)
find_result = run_invoke_cmd(context, find_command)
find_result_stdout = find_result.stdout.strip()
echo_command = oneline_command(
"""echo {find_result} | xargs rm -rfv""".format(
find_result=find_result_stdout
)
)
run_invoke_cmd(context, echo_command)
@task
def sphinx(context):
run_invoke_cmd(
context,
oneline_command(
"""
python3 strictdoc/cli/main.py export docs --formats=html,rst --output-dir output/sphinx
"""
),
)
run_invoke_cmd(
context,
oneline_command(
"""
cp -v output/sphinx/rst/StrictDoc.rst docs/sphinx/source/ &&
cp -rv output/sphinx/html/* docs/strictdoc-html/strictdoc-html
"""
),
)
run_invoke_cmd(
context,
oneline_command(
"""
cd docs/sphinx &&
make html latexpdf &&
open build/latex/strictdoc.pdf
"""
),
)
@task
def test_unit(context):
command = oneline_command(
"""
pytest --capture=no
"""
)
run_invoke_cmd(context, command)
@task(clean)
def test_integration(context, focus=None, debug=False):
cwd = os.getcwd()
strictdoc_exec = 'python \\"{cwd}/strictdoc/cli/main.py\\"'.format(cwd=cwd)
focus_or_none = "--filter {}".format(focus) if focus else ""
debug_opts = "-vv --show-all" if debug else ""
command = oneline_command(
"""
lit
--param STRICTDOC_EXEC="{strictdoc_exec}"
-v
{debug_opts}
{focus_or_none}
{cwd}/tests/integration
"""
).format(
strictdoc_exec=strictdoc_exec,
cwd=cwd,
debug_opts=debug_opts,
focus_or_none=focus_or_none,
)
run_invoke_cmd(context, command)
@task
def export_pip_requirements(context):
run_invoke_cmd(
context,
"poetry export --dev --without-hashes --format requirements.txt > requirements.txt",
)
# Support generation of Poetry managed setup.py file #761
# https://github.com/python-poetry/poetry/issues/761#issuecomment-689491920
@task
def install_local(context):
command_1 = oneline_command(
"""
poetry build
"""
)
command_2 = oneline_command(
"""
tar -xvf dist/*.tar.gz --wildcards --no-anchored '*/setup.py' --strip=1
"""
)
command_3 = oneline_command(
"""
pip install -e .
"""
)
run_invoke_cmd(context, command_1)
run_invoke_cmd(context, command_2)
run_invoke_cmd(context, command_3)
@task
def lint_black_diff(context):
command = oneline_command(
"""
black . --color 2>&1
"""
)
result = run_invoke_cmd(context, command)
# black always exits with 0, so we handle the output.
if "reformatted" in result.stdout:
print("invoke: black found issues")
result.exited = 1
raise invoke.exceptions.UnexpectedExit(result)
@task
def lint_pylint(context):
command = oneline_command(
"""
pylint --rcfile=.pylint.ini strictdoc/ tasks.py
"""
)
try:
run_invoke_cmd(context, command)
except invoke.exceptions.UnexpectedExit as exc:
# pylink doesn't show an error message when exit code != 0, so we do.
print(
"invoke: pylint exited with error code {}".format(exc.result.exited)
)
raise exc
@task(lint_pylint, lint_black_diff)
def lint(_):
pass
@task(lint, test_unit, test_integration)
def test(_):
pass
# https://github.com/github-changelog-generator/github-changelog-generator
# gem install github_changelog_generator
@task
def changelog(context, github_token):
command = oneline_command(
f"""
github_changelog_generator
--token {github_token}
--user strictdoc-project
--project strictdoc
"""
)
run_invoke_cmd(context, command)