@@ -16,16 +16,34 @@ def should_skip(notebook_path: str, skip_list: List[str]) -> bool:
1616
1717
1818def run_notebook (notebook_path : str , root : str ) -> Tuple [bool , Optional [str ]]:
19- """Execute a single notebook."""
19+ """Execute a single notebook and print outputs of each cell ."""
2020 try :
2121 print (f"🔧 running: { notebook_path } " )
2222 with open (notebook_path , encoding = "utf-8" ) as f :
2323 nb = nbformat .read (f , as_version = 4 )
2424
25- ep = ExecutePreprocessor (
26- timeout = SINGLE_NOTEBOOK_TIMEOUT ,
27- kernel_name = "python3" )
25+ ep = ExecutePreprocessor (timeout = SINGLE_NOTEBOOK_TIMEOUT , kernel_name = "python3" )
2826 ep .preprocess (nb , {"metadata" : {"path" : root }})
27+
28+ # Print outputs of each cell
29+ for i , cell in enumerate (nb .cells ):
30+ if cell .cell_type == 'code' :
31+ print (f"\n 📦 Cell { i + 1 } :\n { cell .source .strip ()} " )
32+ for output in cell .get ('outputs' , []):
33+ if output .output_type == 'stream' :
34+ print (output .text )
35+ elif output .output_type == 'error' :
36+ print ("❌ Error:" )
37+ print ("\n " .join (output .get ('traceback' , [])))
38+ elif output .output_type == 'execute_result' :
39+ data = output .get ('data' , {})
40+ if 'text/plain' in data :
41+ print (data ['text/plain' ])
42+ elif output .output_type == 'display_data' :
43+ data = output .get ('data' , {})
44+ if 'text/plain' in data :
45+ print (data ['text/plain' ])
46+
2947 return True , None
3048 except Exception as e :
3149 return False , str (e )
0 commit comments