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.

feat: configure auto-add script metadata to notebook file, when using uv (#2102)

Myles Scolnicka9c7563588a9
diff --git a/docs/guides/editor_features/configuration.md b/docs/guides/editor_features/configuration.md
deleted file mode 100644
index a025a48b1b..0000000000
--- a/docs/guides/editor_features/configuration.md
+++ /dev/null
@@ -1 +0,0 @@
-# Configuration
diff --git a/docs/guides/editor_features/index.md b/docs/guides/editor_features/index.md
index 21974eaddf..9af5f6fd08 100644
--- a/docs/guides/editor_features/index.md
+++ b/docs/guides/editor_features/index.md
@@ -15,11 +15,12 @@ notebooks. We've taken a batteries-included approach to designing the editor:
it comes _packed_ with features to make you productive when working
with code and data.
-| Guide | Description |
-| :------------------- | :---------------------------------------------- |
-| {doc}`overview` | An overview of editor features and configuration |
-| {doc}`ai_completion` | Code with the help of a language model |
-| {doc}`hotkeys` | Our hotkeys |
+| Guide | Description |
+| :------------------------ | :----------------------------------------------- |
+| {doc}`overview` | An overview of editor features and configuration |
+| {doc}`package_management` | Using package managers in marimo |
+| {doc}`ai_completion` | Code with the help of a language model |
+| {doc}`hotkeys` | Our hotkeys |
Highlights include:
diff --git a/docs/guides/editor_features/overview.md b/docs/guides/editor_features/overview.md
index 85e0f487c6..4f330238e9 100644
--- a/docs/guides/editor_features/overview.md
+++ b/docs/guides/editor_features/overview.md
@@ -24,6 +24,7 @@ A non-exhaustive list of settings:
- Outputs above or below code cells
- [Disable/enable autorun](/guides/reactivity.md#runtime-configuration)
+- Package installation
- Vim keybindings
- Dark mode
- Auto-save
@@ -67,14 +68,14 @@ marimo ships with the IDE panels that provide an overview of your notebook:
1. **file explorer**: view the file tree, open other notebooks
2. **variables**: explore variable values, see where they are defined and used, with go-to-definition
-2. **data explorer**: see dataframe and table schemas at a glance
-3. **dependency graph**: view dependencies between cells, drill-down on nodes and edges
-4. **table of contents**: corresponding to your markdown
-5. **documentation** - move your text cursor over a symbol to see its documentation
-6. **logs**: a continuous stream of stdout and stderr
-7. **scratchpad**: a scratchpad cell where you can execute throwaway code
-8. **snippets** - searchable snippets to copy directly into your notebook
-9. **feedback** - share feedback!
+3. **data explorer**: see dataframe and table schemas at a glance
+4. **dependency graph**: view dependencies between cells, drill-down on nodes and edges
+5. **table of contents**: corresponding to your markdown
+6. **documentation** - move your text cursor over a symbol to see its documentation
+7. **logs**: a continuous stream of stdout and stderr
+8. **scratchpad**: a scratchpad cell where you can execute throwaway code
+9. **snippets** - searchable snippets to copy directly into your notebook
+10. **feedback** - share feedback!
:::
::::
diff --git a/docs/guides/editor_features/package_management.md b/docs/guides/editor_features/package_management.md
new file mode 100644
index 0000000000..ba214a03ed
--- /dev/null
+++ b/docs/guides/editor_features/package_management.md
@@ -0,0 +1,27 @@
+# Package management
+
+marimo supports package management for `pip, rye, uv, poetry, pixi`. When marimo comes across a module that is not installed, you will be prompted to install it using your preferred package manager.
+
+Once the module is installed, all cells that depend on the module will be rerun.
+
+```{admonition} Package Installation
+:class: note
+
+We use some heuristic for guessing the package name in your registry (e.g. PyPI) from the module name. It is possible that the package name is different from the module name. If you encounter an error, please file an issue, so we can correct the heuristic.
+```
+
+## Auto-add inline script metadata (`uv` only)
+
+When using [uv](https://docs.astral.sh/uv), marimo can automatically add the package name metadata to your script, per [PEP 723](https://peps.python.org/pep-0723/). This metadata is used to manage the script's dependencies and Python version.
+
+For example, say you start marimo in a new virtual environment and spin up a new notebook. Whenever you add a new package, marimo will automatically add script metadata that looks like this:
+
+```python
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "pandas",
+# "altair",
+# ]
+# ///
+```
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index 930f460359..e73f87c326 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -458,6 +458,47 @@ export const UserConfigForm: React.FC = () => {
</FormItem>
)}
/>
+ <FormField
+ control={form.control}
+ disabled={isWasmRuntime}
+ name="package_management.add_script_metadata"
+ render={({ field }) => {
+ if (form.getValues("package_management.manager") !== "uv") {
+ return <div />;
+ }
+
+ return (
+ <div className="flex flex-col gap-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ Auto-add script metadata
+ </FormLabel>
+ <FormControl>
+ <Checkbox
+ data-testid="auto-instantiate-checkbox"
+ disabled={field.disabled}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ <FormDescription>
+ Whether marimo should automatically add package metadata to
+ scripts. See more about{" "}
+ <a
+ href="https://docs.marimo.io/guides/editor_features/package_management.html"
+ target="_blank"
+ rel="noreferrer"
+ className="text-link hover:underline"
+ >
+ package metadata
+ </a>
+ .
+ </FormDescription>
+ </div>
+ );
+ }}
+ />
</SettingGroup>
<SettingGroup title="Runtime">
<FormField
diff --git a/frontend/src/core/config/__tests__/config-schema.test.ts b/frontend/src/core/config/__tests__/config-schema.test.ts
index c6e47072fd..03bbed833c 100644
--- a/frontend/src/core/config/__tests__/config-schema.test.ts
+++ b/frontend/src/core/config/__tests__/config-schema.test.ts
@@ -49,6 +49,7 @@ test("default UserConfig - empty", () => {
"preset": "default",
},
"package_management": {
+ "add_script_metadata": false,
"manager": "pip",
},
"runtime": {
@@ -99,6 +100,7 @@ test("default UserConfig - one level", () => {
"preset": "default",
},
"package_management": {
+ "add_script_metadata": false,
"manager": "pip",
},
"runtime": {
diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.ts
index f4c6b485d5..2f8ef00160 100644
--- a/frontend/src/core/config/config-schema.ts
+++ b/frontend/src/core/config/config-schema.ts
@@ -90,6 +90,7 @@ export const UserConfigSchema = z
package_management: z
.object({
manager: z.enum(PackageManagerNames).default("pip"),
+ add_script_metadata: z.boolean().default(false),
})
.default({ manager: "pip" }),
ai: z
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index c20fe867cf..f711eeb1a0 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -159,9 +159,12 @@ class PackageManagementConfig(TypedDict):
**Keys.**
- `manager`: the package manager to use
+ - `add_script_metadata`: if true, add script metadata to the notebook
+ Currently only supports `uv`
"""
manager: Literal["pip", "rye", "uv", "poetry", "pixi"]
+ add_script_metadata: bool
@dataclass
@@ -230,7 +233,7 @@ DEFAULT_CONFIG: MarimoConfig = {
"autosave_delay": 1000,
"format_on_save": False,
},
- "package_management": {"manager": "pip"},
+ "package_management": {"manager": "pip", "add_script_metadata": False},
"server": {
"browser": "default",
"follow_symlink": False,
diff --git a/marimo/_runtime/packages/package_manager.py b/marimo/_runtime/packages/package_manager.py
index 66fc2af034..23073f0fa5 100644
--- a/marimo/_runtime/packages/package_manager.py
+++ b/marimo/_runtime/packages/package_manager.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import abc
import shutil
import subprocess
+from typing import List
class PackageManager(abc.ABC):
@@ -53,6 +54,21 @@ class PackageManager(abc.ABC):
proc = subprocess.run(command) # noqa: ASYNC101
return proc.returncode == 0
+ def update_notebook_script_metadata(
+ self,
+ filepath: str,
+ import_namespaces_to_add: List[str],
+ import_namespaces_to_remove: List[str],
+ ) -> None:
+ del filepath, import_namespaces_to_add, import_namespaces_to_remove
+ """
+ Add or remove inline script metadata metadata
+ in the marimo notebook.
+
+ This follows PEP 723 https://peps.python.org/pep-0723/
+ """
+ return
+
class CanonicalizingPackageManager(PackageManager):
"""Base class for package managers.
diff --git a/marimo/_runtime/packages/pypi_package_manager.py b/marimo/_runtime/packages/pypi_package_manager.py
index af26567a5c..69b49e8690 100644
--- a/marimo/_runtime/packages/pypi_package_manager.py
+++ b/marimo/_runtime/packages/pypi_package_manager.py
@@ -1,6 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+from typing import List
+
from marimo._runtime.packages.module_name_to_pypi_name import (
module_name_to_pypi_name,
)
@@ -48,6 +50,42 @@ class UvPackageManager(PypiPackageManager):
async def _install(self, package: str) -> bool:
return self.run(["uv", "pip", "install", package])
+ def update_notebook_script_metadata(
+ self,
+ filepath: str,
+ import_namespaces_to_add: List[str],
+ import_namespaces_to_remove: List[str],
+ ) -> None:
+ # Convert from module name to package name
+ packages_to_add = [
+ self.module_to_package(im) for im in import_namespaces_to_add
+ ]
+ packages_to_remove = [
+ self.module_to_package(im) for im in import_namespaces_to_remove
+ ]
+
+ # Filter to packages that are found by "uv pip show"
+ packages_to_add = [
+ im for im in packages_to_add if self._is_installed(im)
+ ]
+ packages_to_remove = [
+ im for im in packages_to_remove if self._is_installed(im)
+ ]
+
+ if packages_to_add:
+ self.run(
+ ["uv", "--quiet", "add", "--script", filepath]
+ + packages_to_add
+ )
+ if packages_to_remove:
+ self.run(
+ ["uv", "--quiet", "remove", "--script", filepath]
+ + packages_to_remove
+ )
+
+ def _is_installed(self, package: str) -> bool:
+ return self.run(["uv", "--quiet", "pip", "show", package])
+
class RyePackageManager(PypiPackageManager):
name = "rye"
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index fe2eed491c..78fce62531 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -16,7 +16,7 @@ import time
import traceback
from copy import copy
from multiprocessing import connection
-from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, cast
+from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, cast
from uuid import uuid4
from marimo import _loggers
@@ -639,6 +639,27 @@ class Kernel:
cell_id, code, carried_imports=carried_imports
)
+ # For any newly imported namespaces, add them to the metadata
+ #
+ # TODO(akshayka): Consider using the module watcher to discover
+ # packages used by a notebook; that would have the benefit of
+ # discovering transitive dependencies, ie if a notebook used a
+ # local module that in turn used packages available on PyPI.
+ if self._should_add_script_metadata():
+ cell = self.graph.cells.get(cell_id, None)
+ if cell:
+ prev_imports: set[Name] = (
+ set([im.namespace for im in previous_cell.imports])
+ if previous_cell
+ else set()
+ )
+ to_add = cell.imported_namespaces - prev_imports
+ to_remove = prev_imports - cell.imported_namespaces
+ self._add_script_metadata(
+ import_namespaces_to_add=list(to_add),
+ import_namespaces_to_remove=list(to_remove),
+ )
+
LOGGER.debug(
"graph:\n\tcell id %s\n\tparents %s\n\tchildren %s\n\tsiblings %s",
cell_id,
@@ -762,6 +783,14 @@ class Kernel:
del self.cell_metadata[cell_id]
cell = self.graph.cells[cell_id]
cell.import_workspace.imported_defs = set()
+ if self._should_add_script_metadata():
+ self._add_script_metadata(
+ import_namespaces_to_add=[],
+ import_namespaces_to_remove=[
+ im.namespace for im in cell.imports
+ ],
+ )
+
return self._deactivate_cell(cell_id)
def mutate_graph(
@@ -1164,6 +1193,7 @@ class Kernel:
@kernel_tracer.start_as_current_span("rename_file")
async def rename_file(self, filename: str) -> None:
self.globals["__file__"] = filename
+ self.app_metadata.filename = filename
roots = set()
for cell in self.graph.cells.values():
if "__file__" in cell.refs:
@@ -1615,6 +1645,12 @@ class Kernel:
for pkg in package_statuses
if package_statuses[pkg] == "installed"
]
+
+ # If a package was not installed at cell registration time, it won't
+ # yet be in the script metadata.
+ if self._should_add_script_metadata():
+ self._add_script_metadata(installed_modules, [])
+
cells_to_run = set(
cid
for module in installed_modules
@@ -1623,6 +1659,39 @@ class Kernel:
if cells_to_run:
await self._if_autorun_then_run_cells(cells_to_run)
+ def _should_add_script_metadata(self) -> bool:
+ return (
+ self.user_config["package_management"]["add_script_metadata"]
+ and self.app_metadata.filename is not None
+ and self.package_manager is not None
+ )
+
+ def _add_script_metadata(
+ self,
+ import_namespaces_to_add: List[str],
+ import_namespaces_to_remove: List[str],
+ ) -> None:
+ filename = self.app_metadata.filename
+
+ if not filename or not self.package_manager:
+ return
+
+ try:
+ LOGGER.debug(
+ "Updating script metadata: %s. Adding namespaces: %s."
+ " Removing namespaces: %s",
+ filename,
+ import_namespaces_to_add,
+ import_namespaces_to_remove,
+ )
+ self.package_manager.update_notebook_script_metadata(
+ filepath=filename,
+ import_namespaces_to_add=import_namespaces_to_add,
+ import_namespaces_to_remove=import_namespaces_to_remove,
+ )
+ except Exception as e:
+ LOGGER.error("Failed to add script metadata to notebook: %s", e)
+
@kernel_tracer.start_as_current_span("preview_dataset_column")
async def preview_dataset_column(
self, request: PreviewDatasetColumnRequest
diff --git a/openapi/api.yaml b/openapi/api.yaml
index 3868da3bc5..6db873f572 100644
--- a/openapi/api.yaml
+++ b/openapi/api.yaml
@@ -993,7 +993,6 @@ components:
required:
- activate_on_typing
- copilot
- - codeium_api_key
type: object
display:
properties:
@@ -1056,6 +1055,8 @@ components:
type: object
package_management:
properties:
+ add_script_metadata:
+ type: boolean
manager:
enum:
- pip
@@ -1066,6 +1067,7 @@ components:
type: string
required:
- manager
+ - add_script_metadata
type: object
runtime:
properties:
@@ -1782,7 +1784,7 @@ components:
type: object
info:
title: marimo API
- version: 0.8.0
+ version: 0.8.2
openapi: 3.1.0
paths:
/@file/{filename_and_length}:
diff --git a/openapi/src/api.ts b/openapi/src/api.ts
index 2ed5294e14..479ccf6134 100644
--- a/openapi/src/api.ts
+++ b/openapi/src/api.ts
@@ -2087,7 +2087,7 @@ export interface components {
};
completion: {
activate_on_typing: boolean;
- codeium_api_key: string | null;
+ codeium_api_key?: string | null;
copilot: boolean | ("github" | "codeium");
};
display: {
@@ -2115,6 +2115,7 @@ export interface components {
preset: "default" | "vim";
};
package_management: {
+ add_script_metadata: boolean;
/** @enum {string} */
manager: "pip" | "rye" | "uv" | "poetry" | "pixi";
};
diff --git a/scripts/pycopyright.sh b/scripts/pycopyright.sh
index 9e366d28ce..cf7a52e5e1 100755
--- a/scripts/pycopyright.sh
+++ b/scripts/pycopyright.sh
@@ -6,23 +6,37 @@ dir="marimo"
# Counter for updated files
count=0
+skip_dirs=(
+ "marimo/_smoke_tests"
+)
# Iterate over each Python file and add copyright notice if it isn't there
-while read file
-do
- # Check if the file does not start with "# Copyright"
- if ! grep -q '^# Copyright' "$file"; then
- # Create a temporary file
- tmp_file=$(mktemp)
- # Prepend "# Copyright" followed by two new lines to the temporary file
- echo -e "# Copyright 2024 Marimo. All rights reserved." > "$tmp_file"
- # Append the original file content to the temporary file
- cat "$file" >> "$tmp_file"
- # Replace the original file with the temporary file
- mv "$tmp_file" "$file"
- ((count++))
+while read file; do
+ # Check if the file is in a directory to skip
+ skip=false
+ for skip_dir in "${skip_dirs[@]}"; do
+ if [[ $file == $skip_dir* ]]; then
+ skip=true
+ break
+ fi
+ done
+
+ # If the file is not in a directory to skip, process it
+ if ! $skip; then
+ # Check if the file does not start with "# Copyright"
+ if ! grep -q '^# Copyright' "$file"; then
+ # Create a temporary file
+ tmp_file=$(mktemp)
+ # Prepend "# Copyright" followed by two new lines to the temporary file
+ echo -e "# Copyright 2024 Marimo. All rights reserved." >"$tmp_file"
+ # Append the original file content to the temporary file
+ cat "$file" >>"$tmp_file"
+ # Replace the original file with the temporary file
+ mv "$tmp_file" "$file"
+ ((count++))
+ fi
fi
done < <(find "$dir" -type f -name "*.py" -print)
-if (( count > 0 )); then
+if ((count > 0)); then
echo "$(tput bold)added copyright notices to $count files$(tput sgr0)"
fi
diff --git a/tests/_config/test_config.py b/tests/_config/test_config.py
index cf6ca04a90..18b058ca8f 100644
--- a/tests/_config/test_config.py
+++ b/tests/_config/test_config.py
@@ -30,7 +30,10 @@ def test_configure_full() -> None:
"format_on_save": False,
},
keymap={"preset": "vim", "overrides": {}},
- package_management={"manager": "pip"},
+ package_management={
+ "manager": "pip",
+ "add_script_metadata": False,
+ },
)
)
diff --git a/tests/_runtime/test_add_script_metadata.py b/tests/_runtime/test_add_script_metadata.py
new file mode 100644
index 0000000000..c5c8b88864
--- /dev/null
+++ b/tests/_runtime/test_add_script_metadata.py
@@ -0,0 +1,209 @@
+# Copyright 2024 Marimo. All rights reserved.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+import pytest
+
+from marimo._config.config import (
+ merge_default_config,
+)
+from marimo._dependencies.dependencies import DependencyManager
+from tests.conftest import MockedKernel
+
+if TYPE_CHECKING:
+ import pathlib
+
+HAS_UV = DependencyManager.which("uv")
+
+
[email protected](not HAS_UV, reason="uv not installed")
+async def test_add_script_metadata_uv(
+ tmp_path: pathlib.Path, mocked_kernel: MockedKernel
+) -> None:
+ filename = str(tmp_path / "notebook.py")
+ # Create empty file
+ with open(filename, "w") as f: # noqa: ASYNC230
+ f.write("")
+
+ k = mocked_kernel.k
+ await k.rename_file(filename)
+ k._update_runtime_from_user_config(
+ merge_default_config(
+ {
+ "package_management": {
+ "manager": "uv",
+ "add_script_metadata": True,
+ }
+ },
+ )
+ )
+
+ # Add marimo, skip os
+ k._maybe_register_cell("0", "import marimo as mo\nimport os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' in contents
+ assert '"os",' not in contents
+
+ # Add markdown
+ k._maybe_register_cell("1", "import markdown")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' in contents
+ assert '"os",' not in contents
+ assert '"markdown",' in contents
+
+ # Remove marimo
+ k._maybe_register_cell("0", "import os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' not in contents
+ assert '"markdown",' in contents
+ assert '"os",' not in contents
+
+
[email protected](not HAS_UV, reason="uv not installed")
+async def test_add_script_metadata_uv_deletion(
+ tmp_path: pathlib.Path, mocked_kernel: MockedKernel
+) -> None:
+ filename = str(tmp_path / "notebook.py")
+ # Create empty file
+ with open(filename, "w") as f: # noqa: ASYNC230
+ f.write("")
+
+ k = mocked_kernel.k
+ await k.rename_file(filename)
+ k._update_runtime_from_user_config(
+ merge_default_config(
+ {
+ "package_management": {
+ "manager": "uv",
+ "add_script_metadata": True,
+ }
+ },
+ )
+ )
+
+ # Add marimo, skip os
+ k._maybe_register_cell("0", "import marimo as mo\nimport os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' in contents
+ assert '"os",' not in contents
+
+ # Add markdown
+ k._maybe_register_cell("1", "import markdown")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' in contents
+ assert '"os",' not in contents
+ assert '"markdown",' in contents
+
+ # Remove marimo
+ k._delete_cell("0")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' not in contents
+ assert '"markdown",' in contents
+ assert '"os",' not in contents
+
+ # Remove markdown
+ k._delete_cell("1")
+
+ with open(filename) as f: # noqa: ASYNC230
+ contents = f.read()
+ assert '"marimo",' not in contents
+ assert '"markdown",' not in contents
+ assert '"os",' not in contents
+
+
[email protected](not HAS_UV, reason="uv not installed")
+async def test_add_script_metadata_uv_off(
+ tmp_path: pathlib.Path, mocked_kernel: MockedKernel
+) -> None:
+ filename = str(tmp_path / "notebook.py")
+ # Create empty file
+ with open(filename, "w") as f: # noqa: ASYNC230
+ f.write("")
+
+ k = mocked_kernel.k
+ await k.rename_file(filename)
+ k._update_runtime_from_user_config(
+ merge_default_config(
+ {
+ "package_management": {
+ "manager": "uv",
+ "add_script_metadata": False,
+ }
+ },
+ )
+ )
+
+ # Add
+ k._maybe_register_cell("0", "import marimo as mo\nimport os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ assert "" == f.read()
+
+
[email protected](not HAS_UV, reason="uv not installed")
+async def test_add_script_metadata_uv_no_filename(
+ tmp_path: pathlib.Path, mocked_kernel: MockedKernel
+) -> None:
+ filename = str(tmp_path / "notebook.py")
+ # Create empty file
+ with open(filename, "w") as f: # noqa: ASYNC230
+ f.write("")
+
+ k = mocked_kernel.k
+ k._update_runtime_from_user_config(
+ merge_default_config(
+ {
+ "package_management": {
+ "manager": "uv",
+ "add_script_metadata": True,
+ }
+ },
+ )
+ )
+
+ # Add
+ k._maybe_register_cell("0", "import marimo as mo\nimport os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ assert "" == f.read()
+
+
+async def test_add_script_metadata_pip_noop(
+ tmp_path: pathlib.Path, mocked_kernel: MockedKernel
+) -> None:
+ filename = str(tmp_path / "notebook.py")
+ # Create empty file
+ with open(filename, "w") as f: # noqa: ASYNC230
+ f.write("")
+
+ k = mocked_kernel.k
+ await k.rename_file(filename)
+ k._update_runtime_from_user_config(
+ merge_default_config(
+ {
+ "package_management": {
+ "manager": "pip",
+ "add_script_metadata": True,
+ }
+ },
+ )
+ )
+
+ # Add
+ k._maybe_register_cell("0", "import marimo as mo\nimport os")
+
+ with open(filename) as f: # noqa: ASYNC230
+ assert "" == f.read()
diff --git a/tests/_server/templates/snapshots/export1.txt b/tests/_server/templates/snapshots/export1.txt
index 68d7014baf..c14a87d863 100644
--- a/tests/_server/templates/snapshots/export1.txt
+++ b/tests/_server/templates/snapshots/export1.txt
@@ -56,7 +56,7 @@
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"add_script_metadata": false, "manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"width": "compact"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>notebook</title>
diff --git a/tests/_server/templates/snapshots/export2.txt b/tests/_server/templates/snapshots/export2.txt
index 6bf3e98c53..e165480cea 100644
--- a/tests/_server/templates/snapshots/export2.txt
+++ b/tests/_server/templates/snapshots/export2.txt
@@ -56,7 +56,7 @@
<marimo-filename hidden></marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"add_script_metadata": false, "manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"width": "compact"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>marimo</title>
diff --git a/tests/_server/templates/snapshots/export3.txt b/tests/_server/templates/snapshots/export3.txt
index 39baa22e4f..6726562031 100644
--- a/tests/_server/templates/snapshots/export3.txt
+++ b/tests/_server/templates/snapshots/export3.txt
@@ -56,7 +56,7 @@
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"add_script_metadata": false, "manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"width": "compact"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>notebook</title>
diff --git a/tests/_server/templates/snapshots/export4.txt b/tests/_server/templates/snapshots/export4.txt
index 7aed1bc471..053d16abf1 100644
--- a/tests/_server/templates/snapshots/export4.txt
+++ b/tests/_server/templates/snapshots/export4.txt
@@ -56,7 +56,7 @@
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "dataframes": "rich", "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"add_script_metadata": false, "manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"css_file": "custom.css", "width": "compact"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>notebook</title>