nteract/papermill

TraitError when running notebook

Open

#655 geöffnet am 10. März 2022

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (402 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (5.381 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

🐛 Bug

When I try to run a notebook using pm.execute_notebook it raises a TraitError as shown below. The error is raised in some environments but not in others. I've tried to use the same version of dependency packages but that didn't fix the problem.

Function:

def run_notebook(
    nb_path: str,
    raise_on_error: bool = True,
    log_error: bool = False
) -> Tuple[str]:
    if not nb_path.endswith('.ipynb'):
        nb_path += '.ipynb'

    with open("out.txt", "w+") as stdout, open("err.txt", "w+") as stderr:
        try:
            pm.execute_notebook(
                input_path=nb_path,
                output_path=nb_path + "_log.ipynb",
                log_output=True,
                stdout_file=stdout,
                stderr_file=stderr
            )

        except pm.PapermillExecutionError as e:
            stderr.write(str(e))

            if raise_on_error is True:
                raise eval(f"{e.ename}('{e.evalue}')")
            else:
                err_msg = (
                    f"{nb_path}: Erro na execução ignorado devido ao"
                    f" parâmetro raise_on_error:\n{e}"
                )
                print(err_msg)
        finally:
            stdout.seek(0), stderr.seek(0)
            out = stdout.read()
            err = stderr.read()

            stdout.close()
            stderr.close()
            os.remove("out.txt")
            os.remove("err.txt")
            print(out, err)

Error: TraitError: The 'log' trait of a PapermillNotebookClient instance must be a Logger, but a value of class 'logging.Logger' (i.e. <Logger papermill (DEBUG)>) was specified.

Contributor Guide