Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/actions/run-notebook/convert-notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@
for cell in nb.cells:
if cell.cell_type == "code":
if "pip" not in cell.source:
executable_cells.append(cell)
# Remove any lines that start with "!" or "%"
# These are "magic" commands such as "%matplotlib inline" that
# are not executable outside of a notebook environment.
executable = "\n".join([line for line in cell.source.split("\n") if not line.strip().startswith("!") and not line.strip().startswith("%")])
executable_cells.append(executable)

# Save executable cells to a notebook.py file
script_path = os.path.join(temp_dir, 'notebook.py')
with open(script_path, 'w', encoding="utf-8") as f:
for cell in executable_cells:
f.write(cell.source + '\n')
f.write(cell + '\n')

print(f"Script saved to {script_path}")

Expand Down
Loading