Return a deep copy of the graph by recompiling all cells. This is mainly useful in the case where recompilation must be done due to a dynamically changing notebook, where the line cache must be consistent with the cell code, e.g. for debugging.
(self, filename: None | str = None)
| 375 | return processed - refs |
| 376 | |
| 377 | def copy(self, filename: None | str = None) -> DirectedGraph: |
| 378 | """Return a deep copy of the graph by recompiling all cells. |
| 379 | |
| 380 | This is mainly useful in the case where recompilation must be done |
| 381 | due to a dynamically changing notebook, where the line cache must be |
| 382 | consistent with the cell code, e.g. for debugging. |
| 383 | """ |
| 384 | from marimo._ast.compiler import compile_cell |
| 385 | |
| 386 | graph = DirectedGraph() |
| 387 | with self.lock: |
| 388 | for cid, old_cell in self.topology.cells.items(): |
| 389 | cell = compile_cell( |
| 390 | old_cell.code, |
| 391 | cell_id=cid, |
| 392 | filename=filename, |
| 393 | ) |
| 394 | # Carry over import data manually |
| 395 | imported_defs = old_cell.import_workspace.imported_defs |
| 396 | is_import_block = old_cell.import_workspace.is_import_block |
| 397 | cell.import_workspace.imported_defs = imported_defs |
| 398 | cell.import_workspace.is_import_block = is_import_block |
| 399 | # Reregister |
| 400 | graph.register_cell(cid, cell) |
| 401 | return graph |
| 402 | |
| 403 | @property |
| 404 | def cells(self) -> Mapping[CellId_t, CellImpl]: |