-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
103 lines (84 loc) · 1.74 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
import shlex
from pathlib import Path
from invoke.tasks import task # type: ignore reportUnknownVariableType
from invoke.context import Context
from functools import wraps
from typing import Callable
import inspect
from what2 import dbg
from pathlib import Path
__all__ = [
"pytest",
"exp",
"rufff",
"mk_task",
]
def find_task_dir(ctx: Context):
cwd = Path(ctx.cwd).absolute()
dbg(cwd)
while cwd.parent != cwd:
tasks = cwd / 'tasks.py'
if tasks.exists():
return cwd
else:
cwd = cwd.parent
def run(ctx: Context, cmd: list[str]):
task_dir = find_task_dir(ctx)
with ctx.cd(task_dir):
cmd_str = shlex.join(cmd)
return ctx.run(cmd_str, echo=True, pty=True)
def mk_task(fn: Callable):
"""
Decorator for a function that returns a shell command as a list of strings and runs them in the invoke context.
"""
@task
@wraps(fn)
def wrapper(ctx: Context, *args, **kwargs):
cmd = fn(ctx, *args, **kwargs)
return run(ctx, cmd)
return wrapper
@mk_task
def pytest(ctx: Context):
return [
'poetry',
'run',
'python',
'-m',
'pytest',
'-x',
'-rs'
]
@mk_task
def rufff(ctx: Context):
return [
'poetry',
'run',
'ruff',
'check',
str(root_dir),
'--fix',
]
@mk_task
def py(ctx: Context):
return [
'poetry',
'run',
'python',
]
@mk_task
def exp(ctx: Context):
return [
'poetry',
'run',
'python',
'exp.py',
]
@mk_task
def atr(ctx: Context):
return [
'poetry',
'run',
'autodoc2',
'list',
'./src/what_the_doc',
]