Skip to content

Commit

Permalink
fix: marimo edit --sandbox no longer creates new files (#3181)
Browse files Browse the repository at this point in the history
Fixes #3174
  • Loading branch information
mscolnick authored Dec 16, 2024
1 parent 0cc583f commit c9f0a7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion marimo/_cli/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _pyproject_toml_to_requirements_txt(


def get_dependencies_from_filename(name: str) -> List[str]:
if not name or not os.path.exists(name):
return []
try:
contents, _ = FileContentReader().read_file(name)
return _get_dependencies(contents) or []
Expand Down Expand Up @@ -239,7 +241,7 @@ def run_in_sandbox(
atexit.register(lambda: os.unlink(temp_file_path))

# Get Python version requirement if available
if name is not None:
if name is not None and os.path.exists(name):
contents, _ = FileContentReader().read_file(name)
pyproject = _read_pyproject(contents)
python_version = (
Expand Down
21 changes: 21 additions & 0 deletions tests/_cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,27 @@ def test_cli_sandbox_edit(temp_marimo_file: str) -> None:
_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_edit_new_file() -> None:
port = _get_port()
d = tempfile.TemporaryDirectory()
path = os.path.join(d.name, "new_sandbox_file.py")
p = subprocess.Popen(
[
"marimo",
"edit",
path,
"-p",
str(port),
"--headless",
"--no-token",
"--sandbox",
]
)
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()
Expand Down
9 changes: 9 additions & 0 deletions tests/_cli/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_get_python_version_requirement,
_pyproject_toml_to_requirements_txt,
_read_pyproject,
get_dependencies_from_filename,
)


Expand Down Expand Up @@ -222,3 +223,11 @@ def test_get_dependencies_with_python_version():
assert pyproject_no_python is not None
assert _get_python_version_requirement(pyproject_no_python) is None
assert _get_dependencies(SCRIPT_NO_PYTHON) == ["polars"]


def test_get_dependencies_with_nonexistent_file():
# Test with a non-existent file
assert get_dependencies_from_filename("nonexistent_file.py") == []

# Test with None
assert get_dependencies_from_filename(None) == [] # type: ignore

0 comments on commit c9f0a7f

Please sign in to comment.