Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Skip disabled cells in script (#1373)

Maksim Ivanov944e56c9651b
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.py
index f774d40159..342660e052 100644
--- a/marimo/_ast/app.py
+++ b/marimo/_ast/app.py
@@ -241,7 +241,11 @@ class App:
# graph
# - dict of defs -> values
return (
- tuple(outputs[cid] for cid in self._cell_manager.valid_cell_ids()),
+ tuple(
+ outputs[cid]
+ for cid in self._cell_manager.valid_cell_ids()
+ if not self._graph.is_disabled(cid)
+ ),
# omit defs that were never defined at runtime, eg due to
# conditional definitions like
#
@@ -263,7 +267,7 @@ class App:
outputs: dict[CellId_t, Any] = {}
for cid in self._execution_order:
cell = self._cell_manager.cell_data_at(cid).cell
- if cell is not None:
+ if cell is not None and not self._graph.is_disabled(cid):
self._execution_context = ExecutionContext(
cell_id=cid, setting_element_value=False
)
@@ -285,7 +289,7 @@ class App:
outputs: dict[CellId_t, Any] = {}
for cid in self._execution_order:
cell = self._cell_manager.cell_data_at(cid).cell
- if cell is not None:
+ if cell is not None and not self._graph.is_disabled(cid):
self._execution_context = ExecutionContext(
cell_id=cid, setting_element_value=False
)
diff --git a/tests/_smoke_tests/test_run_as_script.py b/tests/_smoke_tests/test_run_as_script.py
index 9aeca71014..417326c00d 100644
--- a/tests/_smoke_tests/test_run_as_script.py
+++ b/tests/_smoke_tests/test_run_as_script.py
@@ -122,3 +122,30 @@ class TestRunTutorialsAsScripts:
capture_output=True,
)
self.assert_errored(p, reason="MultipleDefinitionError")
+
+ def test_run_disabled_cells(self, tmp_path: pathlib.Path) -> None:
+ code = """
+import marimo
+
+app = marimo.App()
+
+def enabled_cell():
+ print("enabled cell")
+
[email protected](disabled=True)
+def disabled_cell():
+ print("disabled cell")
+
+if __name__ == "__main__":
+ app.run()
+ """
+ file = tmp_path / "mod.py"
+ file.write_text(code)
+ p = subprocess.run(
+ ["python", str(file)],
+ capture_output=True,
+ )
+ self.assert_not_errored(p)
+ assert "enabled cell" in p.stdout.decode()
+ assert "disabled cell" not in p.stdout.decode()