-
Notifications
You must be signed in to change notification settings - Fork 12
/
tasks.py
45 lines (33 loc) · 1.17 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
import re
from pathlib import Path
from invoke import Exit, task
@task
def release(ctx):
toml = Path("pyproject.toml").read_text()
match = re.search(r'version = "(.*?)"', toml)
if match:
version = match.group(1)
print(f"Releasing {version}")
ctx.run(f"git tag {version}", echo=True)
ctx.run(f"git push origin {version}", echo=True)
else:
print("Failed to find version in the pyproject.toml")
def run_test_cmd(ctx, cmd) -> int:
print("=" * 79)
print(f"> {cmd}")
return ctx.run(cmd, warn=True).exited
@task
def test(ctx):
failed_commands = []
# Uncomment when moved away from Travis. Now it fails without clear reason
# if run_test_cmd(ctx, "pre-commit run --all-files"):
# failed_commands.append("Pre commit hooks")
if run_test_cmd(ctx, "mypy openapi_to_fastapi"):
failed_commands.append("Mypy")
if run_test_cmd(ctx, "pytest"):
failed_commands.append("Unit tests")
if run_test_cmd(ctx, "flake8"):
failed_commands.append("flake8")
if failed_commands:
msg = "Errors: " + ", ".join(failed_commands)
raise Exit(message=msg, code=len(failed_commands))