From cb8113418ad034514cd3efd2bda8365c5f8352c4 Mon Sep 17 00:00:00 2001 From: Akshay Agrawal Date: Tue, 14 Jan 2025 15:07:37 -0800 Subject: [PATCH 1/2] improve: always add marimo in sandbox Necessary so sandboxed notebooks can be run as scripts with uv run nb.py. --- marimo/_runtime/runtime.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py index 27030a0ff67..be122d81994 100644 --- a/marimo/_runtime/runtime.py +++ b/marimo/_runtime/runtime.py @@ -549,6 +549,12 @@ def _update_runtime_from_user_config(self, config: MarimoConfig) -> None: ): self.package_manager = create_package_manager(package_manager) + if self._should_update_script_metadata(): + # All marimo notebooks depend on the marimo package; if the + # notebook already has an optional dependency group with marimo, + # such as marimo[sql], this is a NOOP. + self._update_script_metadata(["marimo"]) + if ( autoreload_mode == "lazy" or autoreload_mode == "autorun" # Pyodide doesn't support hot module reloading From 0820428881f3d45f9139d85ccacdb1151ae371f2 Mon Sep 17 00:00:00 2001 From: Akshay Agrawal Date: Tue, 14 Jan 2025 15:55:55 -0800 Subject: [PATCH 2/2] run less frequently, only on manager creation --- marimo/_runtime/runtime.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py index be122d81994..9c204c6771e 100644 --- a/marimo/_runtime/runtime.py +++ b/marimo/_runtime/runtime.py @@ -549,11 +549,12 @@ def _update_runtime_from_user_config(self, config: MarimoConfig) -> None: ): self.package_manager = create_package_manager(package_manager) - if self._should_update_script_metadata(): - # All marimo notebooks depend on the marimo package; if the - # notebook already has an optional dependency group with marimo, - # such as marimo[sql], this is a NOOP. - self._update_script_metadata(["marimo"]) + if self._should_update_script_metadata(): + # All marimo notebooks depend on the marimo package; if the + # notebook already has marimo as a dependency, or an optional + # dependency group with marimo, such as marimo[sql], this is a + # NOOP. + self._update_script_metadata(["marimo"]) if ( autoreload_mode == "lazy" or autoreload_mode == "autorun"