-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
122 lines (88 loc) · 2.69 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
from pathlib import Path
from typing import Optional
from invoke.collection import Collection
from invoke.context import Context
from invoke.tasks import task
ROOT_PATH = Path(__file__).parent
SRC_PATH = ROOT_PATH / "xarizmi"
TEST_PATH = ROOT_PATH / "tests"
_PATHS = (SRC_PATH, TEST_PATH)
def run_autoformat(ctx: Context, path: Path):
with ctx.cd(ROOT_PATH):
path = path.relative_to(ROOT_PATH)
ctx.run(
f"autoflake -r --in-place --remove-all-unused-imports {path}",
pty=True,
echo=True,
)
ctx.run(f"isort {path} ", pty=True, echo=True)
ctx.run(f"black {path}", pty=True, echo=True)
print("Finished running autoformat!")
@task
def autoformat(ctx: Context) -> None:
for path in _PATHS:
run_autoformat(ctx, path)
def run_linters(
ctx: Context, path: Path, exclude: Optional[list[str]] = None
) -> None:
with ctx.cd(ROOT_PATH):
print(f"\U000027A1 Running code quality checks on {path.name}")
path = path.relative_to(ROOT_PATH)
ctx.run(
f"autoflake -cr --remove-all-unused-imports {path} --quiet",
hide="out",
echo=True,
)
ctx.run(
f"isort --check --diff {path} ",
pty=True,
echo=True,
)
ctx.run("mypy --version", pty=True, echo=True)
ctx.run(f"mypy {path}", pty=True, echo=True)
ctx.run(f"flake8 {path}", pty=True, echo=True)
ctx.run(f"black --check {path}", pty=True, echo=True)
print("Finished linting!")
@task
def lint(ctx: Context) -> None:
for path in _PATHS:
run_linters(ctx, path)
@task
def test(ctx: Context) -> None:
ctx.run("pytest -vv tests")
@task
def build(ctx: Context) -> None:
ctx.run("python3.12 setup.py sdist bdist_wheel")
print("Finished build!")
@task
def deploy(ctx: Context) -> None:
ctx.run("python3.12 -m twine upload dist/*")
print("Finished deploy!")
@task
def freeze(ctx: Context) -> None:
ctx.run("pip freeze > requirements_lock.txt")
print("Freezed python packages")
@task
def install(ctx: Context) -> None:
ctx.run("pip install -r requirements.txt")
ctx.run("pip install -r requirements_dev.txt")
print("Freezed python packages")
@task
def tag(ctx: Context) -> None:
import xarizmi
ctx.run(f"git tag v{xarizmi.__version__}")
ctx.run("git push --tags")
@task
def coverage(ctx: Context) -> None:
ctx.run("pytest --cov=xarizmi tests")
ctx.run("coverage html")
ns = Collection()
ns.add_task(autoformat)
ns.add_task(lint)
ns.add_task(test)
ns.add_task(build)
ns.add_task(deploy)
ns.add_task(freeze)
ns.add_task(install)
ns.add_task(tag)
ns.add_task(coverage)