Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def evaluate_notebook(nb_path, dest_path=None, skip_exceptions=False,substring=None, end=None, skip_execute=None,skip_output=None, offset=0, timeout=300, ipython_startup=None,patterns_to_take_with_me=None):
if patterns_to_take_with_me is None:
patterns_to_take_with_me = []
notebook = nbformat.read(nb_path, as_version=4)
kwargs = dict(timeout=timeout,
kernel_name='python%s'%sys.version_info[0],
allow_errors=skip_exceptions)
cwd = os.getcwd()
filedir, filename = os.path.split(nb_path)
os.chdir(filedir)
#profile_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'profile_docs')
#print("Ignoring %s...hope that's ok"%profile_dir)
not_nb_runner = ExecutePreprocessor1000(**kwargs)
if ipython_startup is not None:
not_nb_runner._ipython_startup = ipython_startup
if not os.path.isfile(dest_path):
# TODO but this isn't true, is it? it's running the originl nb
print('INFO: Writing evaluated notebook to {dest_path!s}'.format(
dest_path=os.path.abspath(dest_path)))
try:
if not skip_execute:
not_nb_runner.preprocess(notebook,{})
except CellExecutionError as e:
print('')
print(e)
os.chdir(cwd)
if skip_execute: