File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ # run_notebooks.py
2
+
3
+ import os
4
+ import nbformat
5
+ from nbconvert .preprocessors import ExecutePreprocessor
6
+
7
+
8
+ def run_all_notebooks (path = '.' ):
9
+ print (f"🔍 Scanning for notebooks in: { os .path .abspath (path )} \n " )
10
+
11
+ for root , _ , files in os .walk (path ):
12
+ for file in files :
13
+ if file .endswith (".ipynb" ) and not file .startswith ("." ):
14
+ notebook_path = os .path .join (root , file )
15
+ print (f"▶️ Running: { notebook_path } " )
16
+
17
+ with open (notebook_path , encoding = "utf-8" ) as f :
18
+ nb = nbformat .read (f , as_version = 4 )
19
+
20
+ ep = ExecutePreprocessor (timeout = 600 , kernel_name = 'python3' )
21
+
22
+ try :
23
+ ep .preprocess (nb , {'metadata' : {'path' : root }})
24
+ print (f"✅ Success: { notebook_path } \n " )
25
+ except Exception as e :
26
+ print (f"❌ Failed: { notebook_path } \n Error: { e } \n " )
27
+ raise RuntimeError (f"Notebook execution failed: { notebook_path } " ) from e
28
+
29
+
30
+ if __name__ == "__main__" :
31
+ run_all_notebooks ("/workspaces/azure-ai-content-understanding-python/notebooks" )
You can’t perform that action at this time.
0 commit comments