@@ -747,7 +747,7 @@ def _create_code(num):
747
747
return _function_text + call_line
748
748
749
749
750
- def run_notebook (notebook , root_path = "." , timeout = 30 ):
750
+ def run_notebook (notebook , root_path = "." , timeout = 30 , prerun = None ):
751
751
"""Run a notebook in Jupyter
752
752
753
753
This function will copy all of the files in ``root_path`` to a
@@ -766,6 +766,9 @@ def run_notebook(notebook, root_path=".", timeout=30):
766
766
The root notebook folder (default ".")
767
767
timeout : int
768
768
Length of time to run the notebook in seconds (default 30)
769
+ prerun : function
770
+ Function to run prior to starting the notebook, takes the
771
+ temporary copy of root_path as a parameter
769
772
770
773
"""
771
774
import nbformat
@@ -774,6 +777,8 @@ def run_notebook(notebook, root_path=".", timeout=30):
774
777
workdir = os .path .join (td , 'work' )
775
778
notebook_dir = os .path .join (workdir , os .path .dirname (notebook ))
776
779
shutil .copytree (root_path , workdir )
780
+ if prerun is not None :
781
+ prerun (workdir )
777
782
fullpath = os .path .join (workdir , notebook )
778
783
with open (fullpath , "r" ) as f :
779
784
nb = nbformat .read (f , as_version = 4 )
0 commit comments