Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def listdir(self, path):
with chdir(self._cwd):
return [os.path.join(path, fn) for fn in os.listdir(path)]
logger.info("Working directory: {}".format(get_pretty_path(cwd)))
nb = load_notebook_node(input_path)
# Parameterize the Notebook.
if parameters:
nb = parameterize_notebook(nb, parameters, report_mode)
nb = prepare_notebook_metadata(nb, input_path, output_path, report_mode)
if not prepare_only:
# Fetch the kernel name if it's not supplied
kernel_name = kernel_name or nb.metadata.kernelspec.name
# Execute the Notebook in `cwd` if it is set
with chdir(cwd):
nb = papermill_engines.execute_notebook_with_engine(
engine_name,
nb,
input_path=input_path,
output_path=output_path if request_save_on_cell_execute else None,
kernel_name=kernel_name,
progress_bar=progress_bar,
log_output=log_output,
start_timeout=start_timeout,
stdout_file=stdout_file,
stderr_file=stderr_file,
**engine_kwargs
)
# Check for errors first (it saves on error before raising)
raise_for_execution_errors(nb, output_path)
def write(self, buf, path):
with chdir(self._cwd):
dirname = os.path.dirname(path)
if dirname and not os.path.exists(dirname):
raise FileNotFoundError("output folder {} doesn't exist.".format(dirname))
with io.open(path, 'w', encoding="utf-8") as f:
f.write(buf)
def read(self, path):
try:
with chdir(self._cwd):
with io.open(path, 'r', encoding="utf-8") as f:
return f.read()
except IOError as e:
try:
# Check if path could be a notebook passed in as a
# string
json.loads(path)
return path
except ValueError:
# Propagate the IOError
raise e