Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/helper_scripts/run_recipes.py
928 views
1
#!/usr/bin/env python3
2
3
import glob
4
import os
5
import shutil
6
import subprocess
7
import sys
8
import tempfile
9
import traceback
10
from multiprocessing import Pool
11
12
import matplotlib
13
14
from yt.config import ytcfg
15
16
matplotlib.use("Agg")
17
18
FPATTERNS = ["*.png", "*.txt", "*.h5", "*.dat", "*.mp4"]
19
DPATTERNS = ["LC*", "LR", "DD0046"]
20
BADF = [
21
"cloudy_emissivity.h5",
22
"apec_emissivity.h5",
23
"xray_emissivity.h5",
24
"AMRGridData_Slice_x_density.png",
25
]
26
CWD = os.getcwd()
27
ytcfg["yt", "serialize"] = False
28
BLACKLIST = ["opengl_ipython", "opengl_vr"]
29
30
31
def prep_dirs():
32
for directory in glob.glob(f"{ytcfg.get('yt', 'test_data_dir')}/*"):
33
os.symlink(directory, os.path.basename(directory))
34
35
36
def run_recipe(payload):
37
(recipe,) = payload
38
module_name, ext = os.path.splitext(os.path.basename(recipe))
39
dest = os.path.join(os.path.dirname(recipe), "_static", module_name)
40
if module_name in BLACKLIST:
41
return 0
42
if not os.path.exists(f"{CWD}/_temp/{module_name}.done"):
43
sys.stderr.write(f"Started {module_name}\n")
44
tmpdir = tempfile.mkdtemp()
45
os.chdir(tmpdir)
46
prep_dirs()
47
try:
48
subprocess.check_call(["python", recipe])
49
except Exception as exc:
50
trace = "".join(traceback.format_exception(*sys.exc_info()))
51
trace += f" in module: {module_name}\n"
52
trace += f" recipe: {recipe}\n"
53
raise Exception(trace) from exc
54
open(f"{CWD}/_temp/{module_name}.done", "wb").close()
55
for pattern in FPATTERNS:
56
for fname in glob.glob(pattern):
57
if fname not in BADF:
58
shutil.move(fname, f"{dest}__{fname}")
59
for pattern in DPATTERNS:
60
for dname in glob.glob(pattern):
61
shutil.move(dname, dest)
62
os.chdir(CWD)
63
shutil.rmtree(tmpdir, True)
64
sys.stderr.write(f"Finished with {module_name}\n")
65
return 0
66
67
68
for path in [
69
"_temp",
70
"source/cookbook/_static",
71
"source/visualizing/colormaps/_static",
72
]:
73
fpath = os.path.join(CWD, path)
74
if os.path.exists(fpath):
75
shutil.rmtree(fpath)
76
os.makedirs(fpath)
77
78
os.chdir("_temp")
79
recipes = []
80
for rpath in ["source/cookbook", "source/visualizing/colormaps"]:
81
fpath = os.path.join(CWD, rpath)
82
sys.path.append(fpath)
83
recipes += glob.glob(f"{fpath}/*.py")
84
WPOOL = Pool(processes=6)
85
RES = WPOOL.map_async(run_recipe, ((recipe,) for recipe in recipes))
86
RES.get()
87
os.chdir(CWD)
88
89