forked from WithSecureOpenSource/failures-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
52 lines (39 loc) · 1.29 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
import os
import shutil
import sys
from pathlib import Path
from invoke import task
IN_CI = os.getenv("GITHUB_WORKFLOW")
ROOT_DIR = Path(".").resolve()
UTEST_DIR = ROOT_DIR / "utest"
@task
def lint(ctx):
print("=" * 20, "isort")
ctx.run("isort failure_analysis")
print("=" * 20, "black")
black_cmd = ["black", "--config", "pyproject.toml", "utest", "failure_analysis", "tasks.py"]
if IN_CI:
black_cmd.insert(1, "--check")
black_cmd.insert(2, "--diff")
ctx.run(" ".join(black_cmd))
print("=" * 20, "flake8")
ctx.run("flake8 utest failure_analysis")
print("=" * 20, "mypy")
ctx.run("mypy --show-error-codes utest failure_analysis")
print("=" * 20)
@task
def test(ctx):
ctx.run("pytest --showlocals --tb=long utest")
def _log_error(function, path, excinfo):
if Path(path).exists():
print(f"On function: '{function}' and with path: '{path}'")
print(f"Got error:\n{excinfo}")
sys.exit(1)
@task
def clean(ctx):
shutil.rmtree(ROOT_DIR / ".pytest_cache", onerror=_log_error)
shutil.rmtree(UTEST_DIR / ".pytest_cache", onerror=_log_error)
shutil.rmtree(ROOT_DIR / "dist", onerror=_log_error)
@task
def release(ctx):
ctx.run("semantic-release publish")