ci: don't try to render mermaid images when testing notebooks (#4414)

This commit is contained in:
Vadym Barda
2025-04-25 17:09:18 -04:00
committed by GitHub
parent 9637f3b1be
commit 64448404de
2 changed files with 12 additions and 9 deletions
+7 -6
View File
@@ -88,10 +88,11 @@ def has_blocklisted_command(code: str, metadata: dict) -> bool:
return True
return False
def add_mermaid_retries(code: str) -> str:
def remove_mermaid(code: str) -> str:
return code.replace(
"draw_mermaid_png()",
"draw_mermaid_png(max_retries=10, retry_delay=2.0)"
"display(Image(graph.get_graph().draw_mermaid_png()))",
# replace with a dummy statement
"print()"
)
@@ -188,12 +189,12 @@ def add_vcr_to_notebook(
return notebook
def add_mermaid_retries_to_notebook(notebook: nbformat.NotebookNode) -> nbformat.NotebookNode:
def remove_mermaid_from_notebook(notebook: nbformat.NotebookNode) -> nbformat.NotebookNode:
for cell in notebook.cells:
if cell.cell_type != "code":
continue
cell.source = add_mermaid_retries(cell.source)
cell.source = remove_mermaid(cell.source)
return notebook
@@ -218,7 +219,7 @@ def process_notebooks(should_comment_install_cells: bool) -> None:
notebook, cassette_prefix=cassette_prefix
)
notebook = add_mermaid_retries_to_notebook(notebook)
notebook = remove_mermaid_from_notebook(notebook)
if notebook_path in NOTEBOOKS_NO_EXECUTION:
# Add a cell at the beginning to indicate that this notebook should not be executed