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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: support runtime on-cell-change environment override (#11402)
Martha Cryancd38bc3b4f07
diff --git a/docs/guides/configuration/index.md b/docs/guides/configuration/index.mdindex a471536406..173cfdc6c4 100644--- a/docs/guides/configuration/index.md+++ b/docs/guides/configuration/index.md@@ -140,6 +140,7 @@ marimo supports the following environment variables for advanced configuration:| `MARIMO_STD_STREAM_MAX_BYTES` (deprecated, use `pyproject.toml`) | Maximum size of standard stream (stdout/stderr) output that marimo will display. Outputs larger than this will be truncated. | 1,000,000 (1MB) || `MARIMO_SKIP_UPDATE_CHECK` | If set to "1", marimo will skip checking for updates when starting. | Not set || `MARIMO_SQL_DEFAULT_LIMIT` | Default limit for SQL query results. If not set, no limit is applied. | Not set |+| `MARIMO_RUNTIME_ON_CELL_CHANGE` | Override `runtime.on_cell_change` in edit mode: `lazy` marks dependent cells stale; `autorun` automatically runs them. Takes precedence over user, project, and script configuration. Has no effect with `marimo run`, which always uses `autorun`. | Not set || `MARIMO_SESSION_COOKIE_SECURE` | If set to `true`/`1`, marks the session cookie as `Secure` so browsers only send it over HTTPS. Enable when serving marimo behind TLS. | `false` || `MARIMO_SESSION_SECRET` | Secret used to sign the session cookie. Defaults to a random value generated per server process, so sessions are invalidated on restart. Set to a stable value (e.g. `openssl rand -hex 32`) to keep sessions across restarts or replicas. | Random per process || `MARIMO_SERVER_TRANSPORT` | Experimental. The transport for streaming kernel messages to the browser: `websocket` or `sse`. Use `sse` when deploying behind proxies or services that do not support WebSockets. | `websocket` |diff --git a/marimo/_config/manager.py b/marimo/_config/manager.pyindex 5dc025ee47..7c54793bfa 100644--- a/marimo/_config/manager.py+++ b/marimo/_config/manager.py@@ -411,6 +411,12 @@ class EnvConfigReader(ConfigReader):project_config,allowed_values=("websocket", "sse"),)+ self._maybe_override_from_env(+ "MARIMO_RUNTIME_ON_CELL_CHANGE",+ ["runtime", "on_cell_change"],+ project_config,+ allowed_values=("lazy", "autorun"),+ )return project_configdiff --git a/tests/_config/test_manager.py b/tests/_config/test_manager.pyindex 0b7e9250f3..79e6c68b84 100644--- a/tests/_config/test_manager.py+++ b/tests/_config/test_manager.py@@ -1244,6 +1244,64 @@ def test_env_config_manager_boolean_case_insensitive(assert config["runtime"]["auto_instantiate"] is expected[email protected]("mode", ["lazy", "autorun"])+def test_env_config_manager_on_cell_change(+ monkeypatch: pytest.MonkeyPatch, mode: str+) -> None:+ monkeypatch.setenv("MARIMO_RUNTIME_ON_CELL_CHANGE", mode)+ assert EnvConfigReader().read() == {"runtime": {"on_cell_change": mode}}+++ ("value", "parsed"),+ [+ ("invalid", "invalid"),+ ("", ""),+ ("true", True),+ ("[lazy,autorun]", ["lazy", "autorun"]),+ ],+)+def test_env_config_manager_on_cell_change_invalid(+ monkeypatch: pytest.MonkeyPatch, value: str, parsed: Any+) -> None:+ monkeypatch.setenv("MARIMO_RUNTIME_ON_CELL_CHANGE", value)+ with patch("marimo._config.manager.LOGGER.warning") as warning:+ assert EnvConfigReader().read() == {}+ warning.assert_called_once_with(+ "Ignoring invalid value %r for %s; expected one of %s",+ parsed,+ "MARIMO_RUNTIME_ON_CELL_CHANGE",+ "'lazy', 'autorun'",+ )++[email protected]("mode", ["lazy", "autorun"])+def test_env_on_cell_change_overrides_files(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, mode: str+) -> None:+ file_mode = "autorun" if mode == "lazy" else "lazy"+ user_path = tmp_path / "marimo.toml"+ user_path.write_text(f'[runtime]\non_cell_change = "{file_mode}"\n')+ monkeypatch.setattr(+ UserConfigStore, "get_config_path", lambda _self: str(user_path)+ )+ (tmp_path / "pyproject.toml").write_text(+ f'[tool.marimo.runtime]\non_cell_change = "{file_mode}"\n'+ )+ notebook = tmp_path / "app.py"+ notebook.write_text(+ "# /// script\n# [tool.marimo.runtime]\n"+ f'# on_cell_change = "{file_mode}"\n# ///\n'+ )+ monkeypatch.setenv("MARIMO_RUNTIME_ON_CELL_CHANGE", mode)+ manager = get_default_config_manager(current_path=str(notebook))+ assert manager.get_config()["runtime"]["on_cell_change"] == mode+ assert manager.get_config_overrides()["runtime"]["on_cell_change"] == mode+ assert user_path.read_text() == (+ f'[runtime]\non_cell_change = "{file_mode}"\n'+ )++def test_env_config_manager_no_env_vars() -> None:"""Test that missing env vars return empty config"""manager = EnvConfigReader()