-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodo.py
58 lines (40 loc) · 1.27 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
from pathlib import Path
DOIT_CONFIG = {"default_tasks": ["make_mod"]}
# Build directory
BUILD_DIR = Path(__file__).parent / "_build"
def make_builddir():
BUILD_DIR.mkdir(exist_ok=True)
def task_make_builddir():
return {"actions": [make_builddir]}
# Core "module building" task
def print_deps(mod, dependencies):
print("%s -> %s" % (mod, dependencies))
def make_mod(mod):
(BUILD_DIR / mod).touch()
def task_make_mod():
for mod in MOD_IMPORTS.keys():
yield {
"name": mod,
"actions": [
(print_deps, (mod,)),
(make_mod, (mod,)),
],
"targets": [BUILD_DIR / mod],
"task_dep": ["make_builddir"],
"calc_dep": ["get_dep:%s" % mod],
}
# "Dynamic" dependencies calculation
MOD_IMPORTS = {"a": ["b", "c"], "b": ["f", "g"], "c": [], "f": ["c"], "g": []}
def get_dep(mod):
# fake implementation
return {
"file_dep": [str(BUILD_DIR / dep) for dep in MOD_IMPORTS[mod]],
"task_dep": [f"make_mod:{dep}" for dep in MOD_IMPORTS[mod]],
}
def task_get_dep():
"""get direct dependencies for each module"""
for mod in MOD_IMPORTS.keys():
yield {
"name": mod,
"actions": [(get_dep, [mod])],
}