8
8
BASE_DIR = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
9
9
NOTEBOOK_DIR = os .path .join (BASE_DIR , 'docs' , 'source' , 'notebooks' )
10
10
11
+
11
12
def list_notebooks ():
12
13
"""Get an iterator of filepaths to notebooks in NOTEBOOK_DIR"""
13
14
return glob .glob (os .path .join (NOTEBOOK_DIR , '*.ipynb' ))
14
15
16
+
15
17
def execute_notebook (notebook_path ):
16
18
"""Run and overwrite a notebook file."""
17
19
ep = ExecutePreprocessor (timeout = - 1 )
18
20
with open (notebook_path , 'r' ) as buff :
19
21
nb = nbformat .read (buff , as_version = nbformat .NO_CONVERT )
20
22
try :
21
23
t0 = time .time ()
22
- _ = ep .preprocess (nb , {'metadata' : {'path' : NOTEBOOK_DIR }})
24
+ ep .preprocess (nb , {'metadata' : {'path' : NOTEBOOK_DIR }})
23
25
t1 = time .time ()
24
26
27
+ except KeyboardInterrupt :
28
+ raise
29
+
25
30
except BaseException as e :
26
31
t1 = time .time ()
27
32
return False , 'Failed after {:.1f}s:\n {}' .format (t1 - t0 , str (e ))
@@ -31,8 +36,9 @@ def execute_notebook(notebook_path):
31
36
32
37
return True , 'Succeeded after {:.1f}s' .format (t1 - t0 )
33
38
39
+
34
40
def run_all_notebooks ():
35
- """Tries to re-run all notebooks. Prints failures at end."""
41
+ """Try to re-run all notebooks. Print failures at end."""
36
42
failed = []
37
43
for notebook_path in list_notebooks ():
38
44
print ('Executing {}' .format (os .path .basename (notebook_path )))
@@ -46,6 +52,5 @@ def run_all_notebooks():
46
52
print ('\n ' .join (failed ))
47
53
48
54
49
-
50
55
if __name__ == '__main__' :
51
56
run_all_notebooks ()
0 commit comments