Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_notebook(path):
"""
Returns a Notebook object loaded from the location specified at 'path'.
Args:
path (str): Path to notebook ".ipynb" file.
Returns:
A Notebook object.
"""
if not path.endswith(".ipynb"):
raise PapermillException(
"Notebooks should have an '.ipynb' file extension. Provided path: '%s'", path)
nb = Notebook()
nb.path = path
nb.node = load_notebook_node(path)
return nb
def __setitem__(self, key, value):
# If notebook is a path str then load the notebook.
if isinstance(value, string_types):
value = read_notebook(value)
if not isinstance(value, Notebook):
raise PapermillException(
"Value must either be a path string or a Papermill Notebook object. Found: '%s'" % str(type(value)))
self._notebooks[key] = value