forked from Unidata/python-training
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_notebooks.py
57 lines (47 loc) · 2.04 KB
/
run_notebooks.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
#!/usr/bin/env python
import subprocess
import os.path
NOTEBOOKS_DIR = 'pages/'
SKIP_NOTEBOOKS = [
os.path.join('workshop/Bonus', 'What to do when things go wrong.ipynb'),
os.path.join('workshop/Bonus', 'netCDF-Writing.ipynb'),
os.path.join('workshop/AWIPS', 'AWIPS_Grids_and_Cartopy.ipynb'),
os.path.join('workshop/AWIPS', 'Grid_Levels_and_Parameters.ipynb'),
os.path.join('workshop/AWIPS', 'Map_Resources_and_Topography.ipynb'),
os.path.join('workshop/AWIPS', 'Model_Sounding_Data.ipynb'),
os.path.join('workshop/AWIPS', 'NEXRAD_Level_3_Plot_with_Matplotlib.ipynb'),
os.path.join('workshop/AWIPS', 'Satellite_Imagery.ipynb'),
os.path.join('workshop/AWIPS', 'Upper_Air_BUFR_Soundings.ipynb'),
os.path.join('workshop/AWIPS', 'Watch_and_Warning_Polygons.ipynb'),
os.path.join('gallery', 'Sounding_Plotter.ipynb'),
os.path.join('gallery', 'Precipitation_Map.ipynb'),
os.path.join('gallery', 'upperair_500_obs_contours.ipynb')
#os.path.join('workshop/MetPy_Advanced', 'QG Analysis.ipynb'),
#os.path.join('workshop/MetPy_Case_Study', 'MetPy_Case_Study.ipynb')
]
def run_notebook(notebook):
args = ['jupyter', 'nbconvert', '--execute',
'--ExecutePreprocessor.timeout=900',
'--ExecutePreprocessor.kernel_name=python3',
'--to=notebook', '--inplace']
args.append(notebook)
with subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=None) as proc:
proc.wait()
return proc.returncode
results = []
def log_result(result):
results.append(result)
if __name__ == '__main__':
import glob
import multiprocessing as mp
import sys
ret = 0
notebooks = set(glob.glob(os.path.join(NOTEBOOKS_DIR, '**', '*.ipynb'), recursive=True))
notebooks -= set(os.path.join(NOTEBOOKS_DIR, s) for s in SKIP_NOTEBOOKS)
with mp.Pool(processes=6) as pool:
for notebook in notebooks:
pool.apply_async(run_notebook, args=(notebook,), callback=log_result)
pool.close()
pool.join()
ret = max(results)
sys.exit(ret)