17
17
FILECHECK_LLVM_9_EXEC = "FileCheck-9.0.1"
18
18
19
19
20
- def one_line_command (string ):
21
- return re .sub ("\\ s+" , " " , string ).strip ()
22
-
23
-
24
20
def run_invoke_cmd (context , cmd ) -> invoke .runners .Result :
21
+ def one_line_command (string ):
22
+ return re .sub ("\\ s+" , " " , string ).strip ()
23
+
25
24
return context .run (
26
- cmd , env = None , hide = False , warn = False , pty = False , echo = True
25
+ one_line_command (cmd ),
26
+ env = None ,
27
+ hide = False ,
28
+ warn = False ,
29
+ pty = False ,
30
+ echo = True ,
27
31
)
28
32
29
33
@@ -66,8 +70,7 @@ def run_lit_tests(
66
70
llvm_only_value = "1" if llvm_only else ""
67
71
focus_or_none = f"--filter { focus } " if focus else ""
68
72
69
- command = one_line_command (
70
- f"""
73
+ command = f"""
71
74
lit
72
75
--param REAL_ONLY={ llvm_only_value }
73
76
--param FILECHECK_EXEC="{ filecheck_exec } "
@@ -76,18 +79,15 @@ def run_lit_tests(
76
79
{ focus_or_none }
77
80
{ cwd } /tests/integration
78
81
"""
79
- )
80
82
81
83
run_invoke_cmd (context , command )
82
84
83
85
84
86
@task
85
87
def lint_black_diff (context ):
86
- command = one_line_command (
87
- """
88
+ command = """
88
89
black . --color 2>&1
89
90
"""
90
- )
91
91
result = run_invoke_cmd (context , command )
92
92
93
93
# black always exits with 0, so we handle the output.
@@ -99,24 +99,20 @@ def lint_black_diff(context):
99
99
100
100
@task
101
101
def lint_flake8 (context ):
102
- command = one_line_command (
103
- """
102
+ command = """
104
103
flake8 filecheck/ --statistics --max-line-length 80 --show-source
105
104
"""
106
- )
107
105
run_invoke_cmd (context , command )
108
106
109
107
110
108
@task
111
109
def lint_pylint (context ):
112
- command = one_line_command (
113
- """
110
+ command = """
114
111
pylint
115
112
--rcfile=.pylint.ini
116
113
--disable=c-extension-no-member
117
114
filecheck/ tasks.py
118
115
""" # pylint: disable=line-too-long
119
- )
120
116
try :
121
117
run_invoke_cmd (context , command )
122
118
except invoke .exceptions .UnexpectedExit as exc :
@@ -134,7 +130,7 @@ def lint(_):
134
130
def test_unit (context ):
135
131
run_invoke_cmd (
136
132
context ,
137
- one_line_command (
133
+ (
138
134
"""
139
135
coverage run
140
136
--rcfile=.coveragerc
@@ -146,7 +142,7 @@ def test_unit(context):
146
142
)
147
143
run_invoke_cmd (
148
144
context ,
149
- one_line_command (
145
+ (
150
146
"""
151
147
coverage report --sort=cover
152
148
"""
@@ -158,7 +154,7 @@ def test_unit(context):
158
154
def test_coverage_report (context ):
159
155
run_invoke_cmd (
160
156
context ,
161
- one_line_command (
157
+ (
162
158
"""
163
159
coverage html
164
160
"""
@@ -212,8 +208,7 @@ def check(_):
212
208
213
209
@task
214
210
def clean (context ):
215
- find_command = one_line_command (
216
- """
211
+ find_command = """
217
212
find
218
213
.
219
214
-type f \\ (
@@ -228,22 +223,19 @@ def clean(context):
228
223
-not -path "**Expected**"
229
224
-not -path "**Input**"
230
225
"""
231
- )
232
226
233
227
find_result = run_invoke_cmd (context , find_command )
234
228
find_result_stdout = find_result .stdout .strip ()
235
229
236
- echo_command = one_line_command (
237
- f"""echo { find_result_stdout } | xargs rm -rfv"""
238
- )
230
+ echo_command = f"""echo { find_result_stdout } | xargs rm -rfv"""
239
231
run_invoke_cmd (context , echo_command )
240
232
241
233
242
234
@task
243
235
def docs_sphinx (context , open_doc = False ):
244
236
run_invoke_cmd (
245
237
context ,
246
- one_line_command (
238
+ (
247
239
"""
248
240
cd docs && make html SPHINXOPTS="-W --keep-going -n"
249
241
"""
@@ -252,7 +244,7 @@ def docs_sphinx(context, open_doc=False):
252
244
if open_doc :
253
245
run_invoke_cmd (
254
246
context ,
255
- one_line_command (
247
+ (
256
248
"""
257
249
open docs/_build/html/index.html
258
250
"""
@@ -264,12 +256,64 @@ def docs_sphinx(context, open_doc=False):
264
256
# gem install github_changelog_generator
265
257
@task
266
258
def changelog (context , github_token ):
267
- command = one_line_command (
268
- f"""
259
+ command = f"""
269
260
CHANGELOG_GITHUB_TOKEN={ github_token }
270
261
github_changelog_generator
271
262
--user mull-project
272
263
--project FileCheck.py
273
264
"""
274
- )
275
265
run_invoke_cmd (context , command )
266
+
267
+
268
+ @task ()
269
+ def release (context , test_pypi = False , username = None , password = None ):
270
+ """
271
+ A release can be made to PyPI or test package index (TestPyPI):
272
+ https://pypi.org/project/filecheck/
273
+ https://test.pypi.org/project/filecheck/
274
+ """
275
+
276
+ # When a username is provided, we also need password, and then we don't use
277
+ # tokens set up on a local machine.
278
+ assert username is None or password is not None
279
+
280
+ repository_argument_or_none = (
281
+ ""
282
+ if username
283
+ else (
284
+ "--repository filecheck_test"
285
+ if test_pypi
286
+ else "--repository filecheck_release"
287
+ )
288
+ )
289
+ user_password = f"-u{ username } -p{ password } " if username is not None else ""
290
+
291
+ run_invoke_cmd (
292
+ context ,
293
+ """
294
+ rm -rfv dist/
295
+ """ ,
296
+ )
297
+ run_invoke_cmd (
298
+ context ,
299
+ """
300
+ python3 -m build
301
+ """ ,
302
+ )
303
+ run_invoke_cmd (
304
+ context ,
305
+ """
306
+ twine check dist/*
307
+ """ ,
308
+ )
309
+ # The token is in a core developer's .pypirc file.
310
+ # https://test.pypi.org/manage/account/token/
311
+ # https://packaging.python.org/en/latest/specifications/pypirc/#pypirc
312
+ run_invoke_cmd (
313
+ context ,
314
+ f"""
315
+ twine upload dist/filecheck-*.tar.gz
316
+ { repository_argument_or_none }
317
+ { user_password }
318
+ """ ,
319
+ )
0 commit comments