-
Notifications
You must be signed in to change notification settings - Fork 87
/
dodo.py
173 lines (141 loc) · 4.04 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import os
from pathlib import Path
import platform
import shutil
from typing import Dict
import webbrowser
from doit.action import CmdAction
TESTPLAN_UI_DIR = Path("testplan/web_ui/testing")
TESTPLAN_UI_SRC = TESTPLAN_UI_DIR / "src"
TESTPLAN_UI_SOURCES = list(TESTPLAN_UI_SRC.rglob("*.js")) + list(
TESTPLAN_UI_SRC.rglob("*.jsx")
)
def UICommand(command, **kwargs):
kwargs["cwd"] = TESTPLAN_UI_DIR
return CmdAction(
command,
**kwargs,
)
def updated_env(env_update: Dict[str, str]):
env = os.environ.copy()
env.update(env_update)
return env
def task_install_ui_deps():
target = TESTPLAN_UI_DIR / "node_modules"
return {
"file_dep": [
TESTPLAN_UI_DIR / "package.json",
TESTPLAN_UI_DIR / "pnpm-lock.yaml",
],
"targets": [target],
"actions": [UICommand("pnpm install")],
"clean": [(shutil.rmtree, (target,))],
"doc": "Install UI dependencies (use pnpm/node)",
}
def task_build_ui():
target = TESTPLAN_UI_DIR / "build"
return {
"task_dep": ["install_ui_deps"],
"file_dep": TESTPLAN_UI_SOURCES,
"targets": [target],
"actions": [
UICommand("pnpm prebuild"),
UICommand("pnpm build"),
],
"clean": [(shutil.rmtree, (target,))],
"doc": "Build the UI bundle",
}
def task_black():
def black_cmd(update):
return f'python -m black{" --check" if not update else ""} .'
return {
"actions": [CmdAction(black_cmd)],
"params": [
{"name": "update", "short": "u", "type": bool, "default": False}
],
"doc": "Run blcak formatter check. Usi it before commit :)",
}
def task_pylint():
return {
"actions": ["pylint --rcfile pylintrc testplan"],
"doc": "Run pylint",
}
def task_lint_ui():
return {
"file_dep": TESTPLAN_UI_SOURCES,
"actions": [UICommand("pnpm lint", env=updated_env({"CI": "true"}))],
"task_dep": ["install_ui_deps"],
"doc": "Run lint on UI javascript code",
}
def task_crlf_check():
yield {
"name": None,
"doc": "Check that no crlf in source files",
}
if platform.system() == "Linux":
yield {
"name": "linux",
"actions": ["! git ls-files --eol | grep w/crlf"],
}
else:
yield {"name": "notsupported", "actions": None}
def task_lint():
return {
"actions": None,
"task_dep": ["black", "pylint", "crlf_check"],
"doc": "Run lint on python and javascript code",
}
def task_test_ui():
return {
"file_dep": TESTPLAN_UI_SOURCES
+ list(TESTPLAN_UI_SRC.rglob("*.js.snap")),
"actions": [
UICommand(
"pnpm test",
env=updated_env({"CI": "true"}),
)
],
"task_dep": ["install_ui_deps"],
"doc": "Test the UI code",
}
def task_test():
return {
"actions": ["pytest tests --verbose"],
"verbosity": 2,
"doc": "Test the python code",
}
def task_build():
return {
"actions": ["python -m build -w"],
"task_dep": ["build_ui"],
"doc": "Build a wheel package",
}
def task_build_dev():
return {
"actions": [
CmdAction(
"python -m build -w", env=updated_env({"DEV_BUILD": "1"})
)
],
"task_dep": ["build_ui"],
"doc": "Build a dev package (just a version number difference)",
}
def task_build_docs():
def open_browser(open_browser):
if open_browser:
webbrowser.open(str(Path("doc/en/html/index.html").absolute()))
return {
"actions": [
CmdAction("python -m sphinx -b html . html", cwd=Path("doc/en")),
open_browser,
],
"params": [
{
"name": "open_browser",
"short": "o",
"type": bool,
"default": False,
}
],
"doc": "Build the documentation",
}