-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdodo.py
110 lines (91 loc) · 2.84 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
from pathlib import Path
from textwrap import dedent
import yaml
from doit.action import CmdAction
from raw_svg import render_math_svg
HERE = Path(__file__).parent
DOIT_CONFIG = {"default_tasks": ["build_jb"]}
def task_svg_math():
for svg_file in HERE.glob("raw_svg/*.svg"):
target = render_math_svg.OUTPUT / svg_file.name
yield {
"name": svg_file.name,
"actions": [(render_math_svg.main, [svg_file])],
"targets": [target],
"file_dep": [svg_file, render_math_svg.__file__],
}
def task_clean_svg_cache():
return {
"actions": [(render_math_svg.clean_cache)],
"file_dep": [render_math_svg.CACHE.resolve()],
}
def task_build_jb():
return {
"actions": [["jb", "build", "."]],
"task_dep": [
"svg_math",
"execute_python_scripts",
# "execute_matlab_scripts",
],
"uptodate": [False],
"verbosity": 2,
}
def task_clean_jb():
return {
"actions": [["jb", "clean", "."]],
"verbosity": 2,
}
def task_clean_all():
return {
"actions": [["jb", "clean", "-a", "."]],
"verbosity": 2,
}
def read_toc():
folders = set()
TOC_file = HERE / "_toc.yml"
TOC = yaml.safe_load(TOC_file.read_text())
chapters = [p["chapters"] for p in TOC["parts"]]
for chapter in chapters:
for section in chapter:
folder = Path(section["file"]).parent
folders.add(folder)
return folders
def task_execute_python_scripts():
folders = read_toc()
scripts = set()
for folder in folders:
script_folder = folder.joinpath("scripts")
if script_folder.is_dir():
scripts.update(script_folder.glob("*.py"))
for script in scripts:
yield {
"actions": [CmdAction(f"python {script.name}", cwd=(HERE / script.parent))],
"name": script.name,
"verbosity": 2,
"file_dep": [script],
}
def task_execute_matlab_scripts():
folders = read_toc()
scripts = set()
for folder in folders:
script_folder = folder.joinpath("scripts")
if script_folder.is_dir():
scripts.update(script_folder.glob("*.m"))
for script in scripts:
yield {
"actions": [
CmdAction(
dedent(
f"""\
/Applications/MATLAB_R2021a.app/bin/matlab -nodisplay \
-nosplash -nodesktop -r 'try, run("{script.name}"); \
catch, quit(1, "force"); end; quit(0, "force");'
"""
),
cwd=(HERE / script.parent),
)
],
"name": script.name,
"verbosity": 2,
"file_dep": [script],
}