def notebook_loader(nb_path, kernel_name="wandb_python", **kwargs): with open(utils.notebook_path("setup.ipynb")) as f: setupnb = nbformat.read(f, as_version=4) setupcell = setupnb['cells'][0] # Ensure the notebooks talks to our mock server new_source = setupcell['source'].replace("__WANDB_BASE_URL__", live_mock_server.base_url) setupcell['source'] = new_source with open(utils.notebook_path(nb_path)) as f: nb = nbformat.read(f, as_version=4) nb['cells'].insert(0, setupcell) client = utils.WandbNotebookClient(nb) with client.setup_kernel(**kwargs): # Run setup commands for mocks client.execute_cell(0, store_history=False) yield client
def notebook_loader(nb_path, kernel_name="wandb_python", save_code=True, **kwargs): with open(utils.notebook_path("setup.ipynb")) as f: setupnb = nbformat.read(f, as_version=4) setupcell = setupnb["cells"][0] # Ensure the notebooks talks to our mock server new_source = setupcell["source"].replace( "__WANDB_BASE_URL__", live_mock_server.base_url, ) if save_code: new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", nb_path) else: new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", "") setupcell["source"] = new_source nb_path = utils.notebook_path(nb_path) shutil.copy(nb_path, os.path.join(os.getcwd(), os.path.basename(nb_path))) with open(nb_path) as f: nb = nbformat.read(f, as_version=4) nb["cells"].insert(0, setupcell) try: client = utils.WandbNotebookClient(nb, kernel_name=kernel_name) with client.setup_kernel(**kwargs): # Run setup commands for mocks client.execute_cells(-1, store_history=False) yield client finally: with open(os.path.join(os.getcwd(), "notebook.log"), "w") as f: f.write(client.all_output_text()) wandb.termlog("Find debug logs at: %s" % os.getcwd()) wandb.termlog(client.all_output_text())