Closed bonbonblond closed 1 week ago
problem in demoInversion: import nbformat from nbconvert.preprocessors import ExecutePreprocessor from contextlib import redirect_stdout, redirect_stderr from io import StringIO
path_demoGenData = "research/synthetic_cases_generator/demo_genData.ipynb"
def run_notebook(notebook_path):
with open(notebook_path) as f:
notebook = nbformat.read(f, as_version=4)
# Configurer l'ExecutePreprocessor pour exécuter toutes les cellules
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
# Exécuter le notebook
try:
ep.preprocess(notebook, {'metadata': {'path': './'}})
print("Notebook exécuté avec succès.")
except Exception as e:
print(f"Erreur lors de l'exécution du notebook : {e}")
def import_notebook_values(notebook_path):
with open(notebook_path) as f:
notebook = nbformat.read(f, as_version=4)
# Create a dictionary to hold the globals
notebook_globals = {}
# Suppress standard output and error using `redirect_stdout` and `redirect_stderr`
with StringIO() as buf, redirect_stdout(buf), redirect_stderr(buf):
try:
# Execute each code cell
for cell in notebook.cells:
if cell.cell_type == 'code':
exec(cell.source, notebook_globals)
except Exception as e:
print(f"Error while executing notebook: {e}")
run_notebook(path_demoGenData) import_notebook_values(path_demoGenData); Please debug and submit a new PR
Il manquait une ligne de code dans le pull-request précédent. J'en ai profité pour corriger des fautes d'orthographe dans des commentaires.