Skip to content

Commit 1600ab5

Browse files
authored
Merge pull request #199 from mull-project/stanislaw/python_313
tasks: release task
2 parents 4ccdf13 + 432a8b5 commit 1600ab5

File tree

2 files changed

+78
-32
lines changed

2 files changed

+78
-32
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ exclude = [
1616
[project]
1717
name = "filecheck"
1818
description = "Python port of LLVM's FileCheck, flexible pattern matching file verifier"
19-
authors = ["Stanislav Pankevich <[email protected]>"]
19+
authors = [
20+
{ name = "Stanislav Pankevich", email = "[email protected]" }
21+
]
2022
dynamic = ["version"]
2123
readme = "README.md"
2224
license = "Apache-2.0"

tasks.py

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
FILECHECK_LLVM_9_EXEC = "FileCheck-9.0.1"
1818

1919

20-
def one_line_command(string):
21-
return re.sub("\\s+", " ", string).strip()
22-
23-
2420
def run_invoke_cmd(context, cmd) -> invoke.runners.Result:
21+
def one_line_command(string):
22+
return re.sub("\\s+", " ", string).strip()
23+
2524
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,
2731
)
2832

2933

@@ -66,8 +70,7 @@ def run_lit_tests(
6670
llvm_only_value = "1" if llvm_only else ""
6771
focus_or_none = f"--filter {focus}" if focus else ""
6872

69-
command = one_line_command(
70-
f"""
73+
command = f"""
7174
lit
7275
--param REAL_ONLY={llvm_only_value}
7376
--param FILECHECK_EXEC="{filecheck_exec}"
@@ -76,18 +79,15 @@ def run_lit_tests(
7679
{focus_or_none}
7780
{cwd}/tests/integration
7881
"""
79-
)
8082

8183
run_invoke_cmd(context, command)
8284

8385

8486
@task
8587
def lint_black_diff(context):
86-
command = one_line_command(
87-
"""
88+
command = """
8889
black . --color 2>&1
8990
"""
90-
)
9191
result = run_invoke_cmd(context, command)
9292

9393
# black always exits with 0, so we handle the output.
@@ -99,24 +99,20 @@ def lint_black_diff(context):
9999

100100
@task
101101
def lint_flake8(context):
102-
command = one_line_command(
103-
"""
102+
command = """
104103
flake8 filecheck/ --statistics --max-line-length 80 --show-source
105104
"""
106-
)
107105
run_invoke_cmd(context, command)
108106

109107

110108
@task
111109
def lint_pylint(context):
112-
command = one_line_command(
113-
"""
110+
command = """
114111
pylint
115112
--rcfile=.pylint.ini
116113
--disable=c-extension-no-member
117114
filecheck/ tasks.py
118115
""" # pylint: disable=line-too-long
119-
)
120116
try:
121117
run_invoke_cmd(context, command)
122118
except invoke.exceptions.UnexpectedExit as exc:
@@ -134,7 +130,7 @@ def lint(_):
134130
def test_unit(context):
135131
run_invoke_cmd(
136132
context,
137-
one_line_command(
133+
(
138134
"""
139135
coverage run
140136
--rcfile=.coveragerc
@@ -146,7 +142,7 @@ def test_unit(context):
146142
)
147143
run_invoke_cmd(
148144
context,
149-
one_line_command(
145+
(
150146
"""
151147
coverage report --sort=cover
152148
"""
@@ -158,7 +154,7 @@ def test_unit(context):
158154
def test_coverage_report(context):
159155
run_invoke_cmd(
160156
context,
161-
one_line_command(
157+
(
162158
"""
163159
coverage html
164160
"""
@@ -212,8 +208,7 @@ def check(_):
212208

213209
@task
214210
def clean(context):
215-
find_command = one_line_command(
216-
"""
211+
find_command = """
217212
find
218213
.
219214
-type f \\(
@@ -228,22 +223,19 @@ def clean(context):
228223
-not -path "**Expected**"
229224
-not -path "**Input**"
230225
"""
231-
)
232226

233227
find_result = run_invoke_cmd(context, find_command)
234228
find_result_stdout = find_result.stdout.strip()
235229

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"""
239231
run_invoke_cmd(context, echo_command)
240232

241233

242234
@task
243235
def docs_sphinx(context, open_doc=False):
244236
run_invoke_cmd(
245237
context,
246-
one_line_command(
238+
(
247239
"""
248240
cd docs && make html SPHINXOPTS="-W --keep-going -n"
249241
"""
@@ -252,7 +244,7 @@ def docs_sphinx(context, open_doc=False):
252244
if open_doc:
253245
run_invoke_cmd(
254246
context,
255-
one_line_command(
247+
(
256248
"""
257249
open docs/_build/html/index.html
258250
"""
@@ -264,12 +256,64 @@ def docs_sphinx(context, open_doc=False):
264256
# gem install github_changelog_generator
265257
@task
266258
def changelog(context, github_token):
267-
command = one_line_command(
268-
f"""
259+
command = f"""
269260
CHANGELOG_GITHUB_TOKEN={github_token}
270261
github_changelog_generator
271262
--user mull-project
272263
--project FileCheck.py
273264
"""
274-
)
275265
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

Comments
 (0)