-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
110 lines (93 loc) · 2.63 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
"""Shell utils for units."""
from invoke import task
from invoke.context import Context
@task
def clean(
ctx: Context,
bytecode: bool = False,
pytest: bool = False,
mypy: bool = False,
extra: str = "",
) -> None:
"""
Clean up the project directory.
Args:
ctx: The Invoke context.
bytecode: Whether to clean up compiled Python files.
pytest: Whether to clean up pytest cache and coverage files.
mypy: Whether to clean up mypy cache files.
extra: Additional directories or files to clean up.
"""
patterns = ["build", "dist", "*.egg-info"]
if bytecode:
patterns.append("**/*.pyc")
if pytest:
patterns.extend([".pytest_cache", ".coverage"])
if mypy:
patterns.append(".mypy_cache")
if extra:
patterns.append(extra)
for pattern in patterns:
ctx.run(f"rm -rf {pattern}", hide=True, warn=True)
@task
def install(
ctx: Context,
editable: bool = False,
testing: bool = False,
dev: bool = False,
report: bool = False,
) -> None:
"""
Install the project in editable mode.
Args:
ctx: The Invoke context.
editable: Whether to install in editable mode.
testing: Whether to install test dependencies.
dev: Whether to install development dependencies.
report: If report, show the command output.
"""
command = "pip install ."
if editable:
command += " -e"
deps: list[str] = []
if testing:
deps.append("test")
if dev:
deps.append("dev")
if deps:
command += f"[{','.join(deps)}]"
hide = not report
result = ctx.run(command, hide=hide, warn=True)
if hide and result:
print(result.stdout.splitlines()[-1])
@task
def precommit(ctx: Context) -> None:
"""
Run pre-commit checks.
Args:
ctx: The Invoke context.
"""
ctx.run("pre-commit run --all-files", warn=True)
@task
def test(
ctx: Context,
integration: bool = False,
report: bool = False,
) -> None:
"""
Run unit and integration tests.
Args:
ctx: The Invoke context.
integration: Whether to run integration tests.
report: If report, show the command output.
"""
hide = not report
print("Running unit tests...")
result = ctx.run("pytest tests/unit", hide=hide, warn=True)
if hide and result:
print(result.stdout.splitlines()[-1])
if integration:
print("Running integration tests...")
result = ctx.run("pytest tests/integration", hide=hide, warn=True)
if hide and result:
print(result.stdout.splitlines()[-1])