Skip to content

Commit 9c7ac39

Browse files
PeterOgdenschelleg
authored andcommitted
Add a prerun function to run_notebooks (#1012)
1 parent 67feca2 commit 9c7ac39

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pynq/utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ def _create_code(num):
747747
return _function_text + call_line
748748

749749

750-
def run_notebook(notebook, root_path=".", timeout=30):
750+
def run_notebook(notebook, root_path=".", timeout=30, prerun=None):
751751
"""Run a notebook in Jupyter
752752
753753
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):
766766
The root notebook folder (default ".")
767767
timeout : int
768768
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
769772
770773
"""
771774
import nbformat
@@ -774,6 +777,8 @@ def run_notebook(notebook, root_path=".", timeout=30):
774777
workdir = os.path.join(td, 'work')
775778
notebook_dir = os.path.join(workdir, os.path.dirname(notebook))
776779
shutil.copytree(root_path, workdir)
780+
if prerun is not None:
781+
prerun(workdir)
777782
fullpath = os.path.join(workdir, notebook)
778783
with open(fullpath, "r") as f:
779784
nb = nbformat.read(f, as_version=4)

0 commit comments

Comments
 (0)