-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecute_notebooks.py
More file actions
41 lines (32 loc) · 910 Bytes
/
execute_notebooks.py
File metadata and controls
41 lines (32 loc) · 910 Bytes
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
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
import numpy as np
nbfolder = "./notebooks/"
import glob
found = glob.glob(nbfolder + "*.ipynb")
print(found)
import re
numbers = []
matched = []
for f in found:
m = re.search(".*([0-9])\s.*.ipynb", f)
if m is not None:
n = m.group(1)
numbers.append(n)
matched.append(f)
print(numbers)
order = np.argsort(numbers)
found = np.array(matched)[order].tolist()
print(found)
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
for nbf in found:
print(f"Executing {nbf}")
nb = nbformat.read(open(nbf), as_version=4)
try:
out = ep.preprocess(nb, {'metadata': {'path': nbfolder}})
except CellExecutionError:
msg = 'Error executing the notebook "%s".\n\n' % nbf
# msg += 'See notebook "%s" for the traceback.' %
print(msg)
raise
break