File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Iterate through and execute all notebooks
3
+ """
4
+ from pathlib import Path
5
+
6
+ import nbformat as nbf
7
+ from nbconvert .preprocessors import ExecutePreprocessor
8
+
9
+
10
+ def main ():
11
+ p = Path ('.' )
12
+ notebook_paths = p .glob ('**/*.ipynb' )
13
+ exceptions = {}
14
+ for nb_path in notebook_paths :
15
+ if '.ipynb_checkpoints' in str (nb_path ):
16
+ continue
17
+ print (nb_path )
18
+ notebook = nbf .read (nb_path , 4 )
19
+ try :
20
+ ep = ExecutePreprocessor ()
21
+ print ('About to execute' )
22
+ ep .preprocess (notebook )
23
+ print ('Done executing' )
24
+ except Exception as e :
25
+ exceptions [str (nb_path )] = e
26
+
27
+ if exceptions :
28
+ print ('⚠️' * 20 )
29
+ print ('\n \n Failures in these notebooks:' )
30
+ print ('\n ' .join (exceptions .keys ()), '\n \n ' )
31
+ print ('⚠️' * 20 )
32
+ for nb , error in exceptions .items ():
33
+ print (f'{ nb } : \n { error } ' )
34
+ else :
35
+ print ('🎉🎉 Everything worked! 🎉🎉' )
36
+
37
+
38
+ if __name__ == '__main__' :
39
+ main ()
You can’t perform that action at this time.
0 commit comments