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.

fix: use encoding='utf-8' for remove marimo notebooks (#4004)

Myles Scolnick4e5febf93d00
diff --git a/marimo/_cli/file_path.py b/marimo/_cli/file_path.py
index 1973c83ba2..1b51dd2396 100644
--- a/marimo/_cli/file_path.py
+++ b/marimo/_cli/file_path.py
@@ -285,7 +285,7 @@ class RemoteFileHandler(FileHandler):
# If doesn't end in .py, add it
if not path_to_app.endswith(".py"):
path_to_app += ".py"
- with open(path_to_app, "w") as f:
+ with open(path_to_app, "w", encoding="utf-8") as f:
f.write(content)
LOGGER.info("App saved to %s", path_to_app)
return path_to_app
diff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.py
index 39e387f835..9d8d2a3920 100644
--- a/tests/_cli/test_cli.py
+++ b/tests/_cli/test_cli.py
@@ -27,6 +27,7 @@ from marimo._ast.cell import CellConfig
from marimo._dependencies.dependencies import DependencyManager
from marimo._server.templates.templates import get_version
from marimo._utils.config.config import ROOT_DIR as CONFIG_ROOT_DIR
+from marimo._utils.platform import is_windows
from marimo._utils.toml import read_toml
if TYPE_CHECKING:
@@ -597,6 +598,24 @@ def test_cli_sandbox_edit_new_file() -> None:
_check_contents(p, b"marimo-mode data-mode='edit'", contents)
[email protected](is_windows(), reason="Windows will prompt for Docker")
+def test_cli_edit_by_url() -> None:
+ port = _get_port()
+ p = subprocess.Popen(
+ [
+ "marimo",
+ "edit",
+ "https://github.com/marimo-team/marimo/blob/main/examples/ui/button.py",
+ "-p",
+ str(port),
+ "--headless",
+ "--no-token",
+ ]
+ )
+ contents = _try_fetch(port)
+ _check_contents(p, b"marimo-mode data-mode='edit'", contents)
+
+
@pytest.mark.skipif(not HAS_UV, reason="uv is required for sandbox tests")
def test_cli_sandbox_run(temp_marimo_file: str) -> None:
port = _get_port()