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: support skipping update check in `marimo edit` (#1948)

Mut Zeb99ca956cada
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py
index 6fb4fa231f..92cc229250 100644
--- a/marimo/_cli/cli.py
+++ b/marimo/_cli/cli.py
@@ -250,6 +250,14 @@ edit_help_msg = "\n".join(
multiple=True,
help="Allowed origins for CORS. Can be repeated. Use * for all origins.",
)
+ "--skip-update-check",
+ is_flag=True,
+ default=False,
+ show_default=True,
+ type=bool,
+ help="Don't check if a new version of marimo is available for download.",
+)
@click.argument("name", required=False)
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
def edit(
@@ -261,11 +269,13 @@ def edit(
token_password: Optional[str],
base_url: str,
allow_origins: Optional[tuple[str, ...]],
+ skip_update_check: bool,
name: Optional[str],
args: tuple[str, ...],
) -> None:
- # Check for version updates
- check_for_updates()
+ if not skip_update_check:
+ # Check for version updates
+ check_for_updates()
if name is not None:
# Validate name, or download from URL
diff --git a/marimo/_cli/upgrade.py b/marimo/_cli/upgrade.py
index b0b0a4c373..4863134ff5 100644
--- a/marimo/_cli/upgrade.py
+++ b/marimo/_cli/upgrade.py
@@ -12,6 +12,8 @@ from marimo._cli.print import green, orange
from marimo._server.api.status import HTTPException
from marimo._utils.config.config import ConfigReader
+FETCH_TIMEOUT = 5
+
@dataclass
class MarimoCLIState:
@@ -90,7 +92,7 @@ def _update_with_latest_version(state: MarimoCLIState) -> MarimoCLIState:
def _fetch_data_from_url(url: str) -> Dict[str, Any]:
- with urllib.request.urlopen(url) as response:
+ with urllib.request.urlopen(url, timeout=FETCH_TIMEOUT) as response:
status = response.status
if status == 200:
data = response.read()
diff --git a/marimo/_utils/config/config.py b/marimo/_utils/config/config.py
index 82664e6758..dd98c3581e 100644
--- a/marimo/_utils/config/config.py
+++ b/marimo/_utils/config/config.py
@@ -46,8 +46,13 @@ class ConfigReader:
def _get_home_directory() -> str:
# If in pytest, we want to set a temporary directory
if os.environ.get("PYTEST_CURRENT_TEST"):
- tmpdir = TemporaryDirectory()
- return tmpdir.name
+ # If the home directory is given by test, take it
+ home_dir = os.environ.get("MARIMO_PYTEST_HOME_DIR")
+ if home_dir is not None:
+ return home_dir
+ else:
+ tmpdir = TemporaryDirectory()
+ return tmpdir.name
else:
return os.path.expanduser("~")
diff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.py
index d51eb63cb1..c1dc8a08cc 100644
--- a/tests/_cli/test_cli.py
+++ b/tests/_cli/test_cli.py
@@ -15,20 +15,32 @@ import subprocess
import sys
import tempfile
import time
+import urllib.error
import urllib.request
from typing import Any, Callable, Iterator, Optional
import pytest
+import tomlkit
from marimo import __version__
from marimo._ast import codegen
from marimo._ast.cell import CellConfig
+from marimo._utils.config.config import ROOT_DIR as CONFIG_ROOT_DIR
def _is_win32() -> bool:
return sys.platform == "win32"
+def _can_access_pypi() -> bool:
+ try:
+ pypi_url = "https://pypi.org/pypi/marimo/json"
+ with urllib.request.urlopen(pypi_url, timeout=5):
+ return True
+ except urllib.error.URLError:
+ return False
+
+
@contextlib.contextmanager
def _patch_signals_win32() -> Iterator[None]:
old_handler: Any = None
@@ -125,6 +137,13 @@ def _get_port() -> int:
raise OSError("Could not find an unused port.")
+def _read_toml(filepath: str) -> Optional[dict]:
+ if not os.path.exists(filepath):
+ return None
+ with open(filepath, "r") as file:
+ return tomlkit.parse(file.read())
+
+
def test_cli_help_exit_code() -> None:
# smoke test: makes sure CLI starts
# helpful for catching issues related to
@@ -228,6 +247,58 @@ def test_cli_edit_with_additional_args(temp_marimo_file: str) -> None:
)
+ condition=not _can_access_pypi(),
+ reason="update check won't work without access to pypi",
+)
+def test_cli_edit_update_check() -> None:
+ with tempfile.TemporaryDirectory() as tempdir:
+ port = _get_port()
+ p = subprocess.Popen(
+ ["marimo", "edit", "-p", str(port), "--headless", "--no-token"],
+ env={**os.environ, "MARIMO_PYTEST_HOME_DIR": tempdir},
+ )
+ contents = _try_fetch(port)
+ _check_contents(p, b"marimo-mode data-mode='home'", contents)
+
+ state_contents = _read_toml(
+ os.path.join(tempdir, CONFIG_ROOT_DIR, "state.toml")
+ )
+ assert state_contents is not None
+ assert state_contents.get("last_checked_at") is not None
+
+
+ condition=not _can_access_pypi(),
+ reason="update check skip is only detectable if pypi is accessible",
+)
+def test_cli_edit_skip_update_check() -> None:
+ with tempfile.TemporaryDirectory() as tempdir:
+ port = _get_port()
+ p = subprocess.Popen(
+ [
+ "marimo",
+ "edit",
+ "-p",
+ str(port),
+ "--headless",
+ "--no-token",
+ "--skip-update-check",
+ ],
+ env={**os.environ, "MARIMO_PYTEST_HOME_DIR": tempdir},
+ )
+ contents = _try_fetch(port)
+ _check_contents(p, b"marimo-mode data-mode='home'", contents)
+
+ state_contents = _read_toml(
+ os.path.join(tempdir, CONFIG_ROOT_DIR, "state.toml")
+ )
+ assert (
+ state_contents is None
+ or state_contents.get("last_checked_at") is None
+ )
+
+
def test_cli_new() -> None:
port = _get_port()
p = subprocess.Popen(