-
Notifications
You must be signed in to change notification settings - Fork 18
/
tasks.py
219 lines (178 loc) · 4.88 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
import inspect
import os
import re
import invoke
from invoke import task
# FIXME
if not hasattr(inspect, "getargspec"):
inspect.getargspec = inspect.getfullargspec
def one_line_command(string):
return re.sub("\\s+", " ", string).strip()
def run_invoke_cmd(context, cmd) -> invoke.runners.Result:
return context.run(
one_line_command(cmd),
env=None,
hide=False,
warn=False,
pty=False,
echo=True,
)
@task
def clean(context):
find_command = """
find
tests
-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 = f"""echo {find_result_stdout} | xargs rm -rfv"""
run_invoke_cmd(context, echo_command)
@task(aliases=["tu"])
def test_unit(context):
run_invoke_cmd(
context,
"""
coverage run
--rcfile=.coveragerc
--branch
-m pytest
tests/unit/
""",
)
run_invoke_cmd(
context,
"""
coverage report --sort=cover
""",
)
@task(test_unit)
def test_coverage_report(context):
run_invoke_cmd(
context,
"""
coverage html
""",
)
@task(clean, aliases=["ti"])
def test_integration(context, focus=None, debug=False):
cwd = os.getcwd()
reqif_exec = "python -m reqif.cli.main"
focus_or_none = f"--filter {focus}" if focus else ""
debug_opts = "-vv --show-all" if debug else ""
command = f"""
lit
--param REQIF_EXEC="{reqif_exec}"
-v
{debug_opts}
{focus_or_none}
{cwd}/tests/integration
"""
run_invoke_cmd(context, command)
@task
def lint_ruff_format(context):
result: invoke.runners.Result = run_invoke_cmd(
context,
"""
ruff
format
*.py
reqif/
tests/unit
""",
)
# Ruff always exits with 0, so we handle the output.
if "reformatted" in result.stdout:
print("invoke: ruff format found issues") # noqa: T201
result.exited = 1
raise invoke.exceptions.UnexpectedExit(result)
@task
def lint_flake8(context):
command = """
flake8
reqif/ tasks.py tests/unit/
--ignore=E501,W503
--statistics --max-line-length 80 --show-source
"""
run_invoke_cmd(context, command)
@task
def lint_ruff_check(context, fix=True):
argument_fix = "--fix" if fix else ""
command = f"""
ruff check . {argument_fix}
"""
run_invoke_cmd(context, command)
@task(aliases=["lm"])
def lint_mypy(context):
run_invoke_cmd(
context,
"""
mypy reqif/
--show-error-codes
--disable-error-code=import
--disable-error-code=no-untyped-call
--disable-error-code=no-untyped-def
--disable-error-code=type-arg
--disable-error-code=union-attr
--strict
""",
)
@task(lint_ruff_format, lint_ruff_check, lint_flake8, lint_mypy, aliases=["l"])
def lint(_):
pass
@task(test_unit, test_integration, aliases=["t"])
def test(_):
pass
@task(lint, test, aliases=["c"])
def check(_):
pass
@task
def release(context, username=None, password=None):
"""
A release can be made to PyPI or test package index (TestPyPI):
https://pypi.org/project/strictdoc/
https://test.pypi.org/project/strictdoc/
"""
# When a username is provided, we also need password, and then we don't use
# tokens set up on a local machine.
assert username is None or password is not None
repository_argument_or_none = "" if username else ("--repository reqif_release")
user_password = f"-u{username} -p{password}" if username is not None else ""
command = f"""
rm -rfv dist/ &&
python3 -m build &&
twine check dist/* &&
twine upload dist/reqif-*.tar.gz
{repository_argument_or_none}
{user_password}
"""
run_invoke_cmd(context, command)
@task
def release_local(context):
run_invoke_cmd(
context,
"""
rm -rfv dist/ && pip install -e .
""",
)
# https://github.com/github-changelog-generator/github-changelog-generator
# gem install github_changelog_generator
@task
def changelog(context, github_token):
command = f"""
github_changelog_generator
--token {github_token}
--user strictdoc-project
--project reqif
"""
run_invoke_cmd(context, command)