-
Notifications
You must be signed in to change notification settings - Fork 7
/
dodo.py
103 lines (78 loc) · 2.78 KB
/
dodo.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
# https://pydoit.org/tasks.html
# from doit import cmd_list
# # Tab Completion
#
# For Bash:
#
# ```
# doit tabcompletion --shell bash > doit_comp.sh
# source doit_comp.sh
# ```
#
# For ZSH:
#
# ```
# doit tabcompletion --shell zsh > ~/.local/share/zsh/zfunc/_doit
# ```
from doit.action import TaskFailed
from doit.tools import Interactive, LongRunning
from tasks.tailwindcss import ( # noqa: F401
task__tailwind_install,
task_tailwind_build,
task_tailwind_watch,
)
from tasks.task_dict import TaskDict, TaskDictGen
DOIT_CONFIG = {
"default_tasks": ["_list"],
"action_string_formatting": "new",
"verbosity": 2,
}
UV_RUN = ["uv", "run", "--frozen"]
def task__list() -> TaskDict:
cmd = [*UV_RUN, "doit", "list", "--all", "--status", "--sort=definition"]
return {"actions": [cmd]}
def task_serve() -> TaskDictGen:
"""Start the prod server."""
cmd = LongRunning([*UV_RUN, "fastapi", "run", "app/main.py"], shell=False)
yield {"basename": "serve", "actions": [cmd]}
yield {"basename": "s", "actions": [cmd]}
def task_dev() -> TaskDict:
"""Setup development environment."""
return {"actions": None, "task_dep": ["_uv_sync", "_tailwind_install"]}
def task__uv_sync() -> TaskDict:
cmd = ["uv", "sync", "--frozen"]
return {"file_dep": ["pyproject.toml"], "actions": [cmd], "targets": ["uv.lock"]}
def task_watch() -> TaskDictGen:
"""Start the dev server every time Python files change."""
def cmd(args: list[str]) -> None:
cmd_action = LongRunning(
[*UV_RUN, "fastapi", "dev", "app/main.py", *args],
shell=False,
env={"MURCHACE_DEBUG": "1"},
)
cmd_action.execute()
yield {"basename": "watch", "actions": [cmd], "pos_arg": "args"}
yield {"basename": "w", "actions": [cmd], "pos_arg": "args"}
def task_test() -> TaskDictGen:
"""Run various tests."""
from tasks import tailwindcss
actions = [
[*UV_RUN, "ruff", "check"],
[*UV_RUN, "ruff", "format", "--diff"],
[*UV_RUN, "pyright", "--stats"],
[*UV_RUN, "pytest"],
# Lint Jinja template files
# [*UV_RUN, "djlint", "app/templates", "--ignore", "H006,H030,H031"]
tailwindcss.comparison_test,
]
yield {"basename": "test", "actions": actions}
yield {"basename": "t", "actions": actions}
def task_snapshot_review() -> TaskDictGen:
"""Review inline snapshot tests."""
def cmd(files_or_dirs: list[str]) -> TaskFailed | None:
cmd_action = Interactive(
[*UV_RUN, "pytest", "--inline-snapshot=review", *files_or_dirs], shell=False
)
return cmd_action.execute()
yield {"basename": "snapshot-review", "actions": [cmd], "pos_arg": "files_or_dirs"}
yield {"basename": "sr", "actions": [cmd], "pos_arg": "files_or_dirs"}