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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: support mairmo edit on marimo.app (#4840)
Myles Scolnick8fda46c55163
diff --git a/marimo/_cli/file_path.py b/marimo/_cli/file_path.pyindex 71e3ade8f7..097fee1600 100644--- a/marimo/_cli/file_path.py+++ b/marimo/_cli/file_path.py@@ -11,7 +11,7 @@ from tempfile import TemporaryDirectoryfrom typing import Optionalfrom urllib.error import HTTPError-from marimo import _loggers+from marimo import __version__, _loggersfrom marimo._cli.print import greenfrom marimo._utils.marimo_path import MarimoPathfrom marimo._utils.url import is_url@@ -105,7 +105,7 @@ class StaticNotebookReader(FileReader):request = urllib.request.Request(url,# User agent to avoid 403 Forbidden some bot protection- headers={"User-Agent": "Mozilla/5.0"},+ headers={"User-Agent": f"marimo/{__version__}"},)file_contents = (urllib.request.urlopen(request).read().decode("utf-8")@@ -123,27 +123,38 @@ class StaticNotebookReader(FileReader):return download(url)# Starts with https://static.marimo.app/, append /download- if url.startswith("https://static.marimo.app/"):+ if url.startswith("https://static.marimo.app/static"):return download(os.path.join(url, "download"))+ # Starts with https://marimo.app/+ if url.startswith("https://marimo.app/"):+ return download(url)+# Otherwise, not a static marimo notebookreturn False, ""@staticmethoddef _extract_code_from_static_notebook(file_contents: str) -> str:+ assert StaticNotebookReader.CODE_SUFFIX in file_contents, (+ "<marimo-code> not found in file contents"+ )# normalize hidden attributefile_contents = file_contents.replace("hidden=''", 'hidden=""')- return file_contents.split(StaticNotebookReader.CODE_PREFIX)[1].split(- StaticNotebookReader.CODE_SUFFIX- )[0]+ prefix = StaticNotebookReader.CODE_PREFIX+ suffix = StaticNotebookReader.CODE_SUFFIX+ encoded_code = file_contents.split(prefix)[1].split(suffix)[0]+ return urllib.parse.unquote(encoded_code)@staticmethoddef _extract_filename_from_static_notebook(file_contents: str) -> str:+ if StaticNotebookReader.FILENAME_SUFFIX not in file_contents:+ return "notebook.py"# normalize hidden attributefile_contents = file_contents.replace("hidden=''", 'hidden=""')- return file_contents.split(StaticNotebookReader.FILENAME_PREFIX)[- 1- ].split(StaticNotebookReader.FILENAME_SUFFIX)[0]+ prefix = StaticNotebookReader.FILENAME_PREFIX+ suffix = StaticNotebookReader.FILENAME_SUFFIX+ encoded_filename = file_contents.split(prefix)[1].split(suffix)[0]+ return urllib.parse.unquote(encoded_filename)class GitHubSourceReader(FileReader):diff --git a/tests/_cli/test_file_path.py b/tests/_cli/test_file_path.pyindex 69196ae462..0b5251be98 100644--- a/tests/_cli/test_file_path.py+++ b/tests/_cli/test_file_path.py@@ -131,7 +131,7 @@ def test_local_file_reader(tmp_path: Path) -> None:def test_static_notebook_reader() -> None:reader = StaticNotebookReader()- valid_url = "https://static.marimo.app/example"+ valid_url = "https://static.marimo.app/static/example"invalid_url = "https://example.com/file.py"with patch.object(@@ -274,9 +274,9 @@ def test_generic_url_reader_with_query_params():def test_static_notebook_reader_url_formats():reader = StaticNotebookReader()urls = [- "https://static.marimo.app/example",- "https://static.marimo.app/example/",- "https://static.marimo.app/example.html",+ "https://static.marimo.app/static/example",+ "https://static.marimo.app/static/example/",+ "https://static.marimo.app/static/example.html",]for url in urls:with patch.object(