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
improvement: better tracebacks, padding, remove button for static files (#6912)
Myles Scolnicka3c491dc377a
diff --git a/.gitignore b/.gitignoreindex 815343939e..cad29aefbe 100644--- a/.gitignore+++ b/.gitignore@@ -74,9 +74,6 @@ docs/_build/profile_default/ipython_config.py-# pyenv-.python-version-# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependenciesdiff --git a/.python-version b/.python-versionnew file mode 100644index 0000000000..24ee5b1be9--- /dev/null+++ b/.python-version@@ -0,0 +1 @@+3.13diff --git a/frontend/src/components/editor/output/MarimoTracebackOutput.tsx b/frontend/src/components/editor/output/MarimoTracebackOutput.tsxindex 6847517d35..e5446f0808 100644--- a/frontend/src/components/editor/output/MarimoTracebackOutput.tsx+++ b/frontend/src/components/editor/output/MarimoTracebackOutput.tsx@@ -30,6 +30,7 @@ import type { CellId } from "@/core/cells/ids";import { insertDebuggerAtLine } from "@/core/codemirror/editing/debugging";import { aiEnabledAtom } from "@/core/config/config";import { getRequestClient } from "@/core/network/requests";+import { isStaticNotebook } from "@/core/static/static-state";import { isWasm } from "@/core/wasm/utils";import { renderHTML } from "@/plugins/core/RenderHTML";import { copyToClipboard } from "@/utils/copy";@@ -70,6 +71,17 @@ export const MarimoTracebackOutput = ({// Get last traceback infoconst tracebackInfo = extractAllTracebackInfo(traceback)?.at(0);+ // Don't show in wasm or static notebooks+ const showDebugger =+ tracebackInfo &&+ tracebackInfo.kind === "cell" &&+ !isWasm() &&+ !isStaticNotebook();++ const showAIFix = onRefactorWithAI && aiEnabled && !isStaticNotebook();++ const showSearch = !isStaticNotebook();+const handleRefactorWithAI = (triggerImmediately: boolean) => {onRefactorWithAI?.({prompt: `My code gives the following error:\n\n${lastTracebackLine}`,@@ -104,14 +116,14 @@ export const MarimoTracebackOutput = ({</AccordionItem></Accordion><div className="flex gap-2">- {onRefactorWithAI && aiEnabled && (+ {showAIFix && (<AIFixButtontooltip="Fix with AI"openPrompt={() => handleRefactorWithAI(false)}applyAutofix={() => handleRefactorWithAI(true)}/>)}- {tracebackInfo && tracebackInfo.kind === "cell" && !isWasm() && (+ {showDebugger && (<Tooltip content={"Attach pdb to the exception point."}><Buttonsize="xs"@@ -125,50 +137,52 @@ export const MarimoTracebackOutput = ({</Button></Tooltip>)}- <DropdownMenu>- <DropdownMenuTrigger asChild={true}>- <Button size="xs" variant="text">- Get help- <ChevronDown className="h-3 w-3 ml-1" />- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end" className="w-56">- <DropdownMenuItem asChild={true}>- <a- target="_blank"- href={`https://www.google.com/search?q=${encodeURIComponent(lastTracebackLine)}`}- rel="noreferrer"- >- <SearchIcon className="h-4 w-4 mr-2" />- Search on Google- <ExternalLinkIcon className="h-3 w-3 ml-auto" />- </a>- </DropdownMenuItem>- <DropdownMenuItem asChild={true}>- <a- target="_blank"- href="https://marimo.io/discord?ref=notebook"- rel="noopener"+ {showSearch && (+ <DropdownMenu>+ <DropdownMenuTrigger asChild={true}>+ <Button size="xs" variant="text">+ Get help+ <ChevronDown className="h-3 w-3 ml-1" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-56">+ <DropdownMenuItem asChild={true}>+ <a+ target="_blank"+ href={`https://www.google.com/search?q=${encodeURIComponent(lastTracebackLine)}`}+ rel="noreferrer"+ >+ <SearchIcon className="h-4 w-4 mr-2" />+ Search on Google+ <ExternalLinkIcon className="h-3 w-3 ml-auto" />+ </a>+ </DropdownMenuItem>+ <DropdownMenuItem asChild={true}>+ <a+ target="_blank"+ href="https://marimo.io/discord?ref=notebook"+ rel="noopener"+ >+ <MessageCircleIcon className="h-4 w-4 mr-2" />+ Ask in Discord+ <ExternalLinkIcon className="h-3 w-3 ml-auto" />+ </a>+ </DropdownMenuItem>+ <DropdownMenuItem+ onClick={() => {+ // Strip HTML from the traceback+ const div = document.createElement("div");+ div.innerHTML = traceback;+ const textContent = div.textContent || "";+ copyToClipboard(textContent);+ }}>- <MessageCircleIcon className="h-4 w-4 mr-2" />- Ask in Discord- <ExternalLinkIcon className="h-3 w-3 ml-auto" />- </a>- </DropdownMenuItem>- <DropdownMenuItem- onClick={() => {- // Strip HTML from the traceback- const div = document.createElement("div");- div.innerHTML = traceback;- const textContent = div.textContent || "";- copyToClipboard(textContent);- }}- >- <CopyIcon className="h-4 w-4 mr-2" />- Copy to clipboard- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>+ <CopyIcon className="h-4 w-4 mr-2" />+ Copy to clipboard+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )}</div></div>);diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsxindex af7c1ae0c2..edaf7dfeaf 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx@@ -21,13 +21,16 @@ export const VerticalLayoutWrapper: React.FC<PropsWithChildren<Props>> = ({<divclassName={cn("px-1 sm:px-16 md:px-20 xl:px-24 print:px-0 print:pb-0",+ // Large mobile bottom padding due to mobile browser navigation bar+ "pb-24 sm:pb-12",className,)}><divclassName={cn(- // Large mobile bottom padding due to mobile browser navigation bar- "m-auto pb-24 sm:pb-12",+ "m-auto",+ // This padding needs to be the same from above to be correctly applied+ "pb-24 sm:pb-12",appConfig.width === "compact" &&"max-w-(--content-width) min-w-[400px]",appConfig.width === "medium" &&diff --git a/frontend/src/core/cells/__tests__/session.test.ts b/frontend/src/core/cells/__tests__/session.test.tsindex ef2d360d1b..19801acc98 100644--- a/frontend/src/core/cells/__tests__/session.test.ts+++ b/frontend/src/core/cells/__tests__/session.test.ts@@ -210,8 +210,18 @@ describe("notebookStateFromSession", () => {it("handles console outputs in session cell", () => {const consoleOutputs = [- { type: "stream", name: "stdout", text: "Hello stdout" } as const,- { type: "stream", name: "stderr", text: "Hello stderr" } as const,+ {+ type: "stream",+ name: "stdout",+ text: "Hello stdout",+ mimetype: "text/plain",+ } as const,+ {+ type: "stream",+ name: "stderr",+ text: "Hello stderr",+ mimetype: "text/plain",+ } as const,];const session = createSession([createSessionCell("cell-1", [], consoleOutputs),@@ -356,7 +366,14 @@ describe("notebookStateFromSession", () => {createSessionCell("cell-1",[],- [{ type: "stream", name: "stdout", text: "output" }],+ [+ {+ type: "stream",+ name: "stdout",+ text: "output",+ mimetype: "text/plain",+ },+ ],),]);const notebook = createNotebook([diff --git a/frontend/src/core/cells/session.ts b/frontend/src/core/cells/session.tsindex 9c694aa0bc..985087d780 100644--- a/frontend/src/core/cells/session.ts+++ b/frontend/src/core/cells/session.ts@@ -229,7 +229,7 @@ function createCellRuntimeFromSession(return {channel: consoleOutput.name === "stderr" ? "stderr" : "stdout",data: consoleOutput.text,- mimetype: "text/plain",+ mimetype: consoleOutput.mimetype ?? "text/plain",timestamp: DEFAULT_TIMESTAMP,};}),diff --git a/marimo/_schemas/generated/session.yaml b/marimo/_schemas/generated/session.yamlindex c9fc03b6b8..e10a512cc8 100644--- a/marimo/_schemas/generated/session.yaml+++ b/marimo/_schemas/generated/session.yaml@@ -126,6 +126,31 @@ components:type: objectStreamOutput:properties:+ mimetype:+ enum:+ - application/json+ - application/vnd.marimo+error+ - application/vnd.marimo+traceback+ - application/vnd.marimo+mimebundle+ - application/vnd.vega.v5+json+ - application/vnd.vegalite.v5+json+ - application/vnd.jupyter.widget-view+json+ - image/png+ - image/svg+xml+ - image/tiff+ - image/avif+ - image/bmp+ - image/gif+ - image/jpeg+ - video/mp4+ - video/mpeg+ - text/html+ - text/plain+ - text/markdown+ - text/latex+ - text/csv+ nullable: true+ type: stringname:enum:- stdout@@ -141,6 +166,7 @@ components:- type- name- text+ - mimetypetype: objectTimeMetadata:properties:diff --git a/marimo/_schemas/session.py b/marimo/_schemas/session.pyindex 4637dfa4c5..7edf8a9f5e 100644--- a/marimo/_schemas/session.py+++ b/marimo/_schemas/session.py@@ -30,6 +30,7 @@ class StreamOutput(BaseDict):type: Literal["stream"]name: Literal["stdout", "stderr"]text: str+ mimetype: Optional[KnownMimeType]class StreamMediaOutput(BaseDict):diff --git a/marimo/_server/session/serialize.py b/marimo/_server/session/serialize.pyindex 27d737ec6b..e8d6640aa0 100644--- a/marimo/_server/session/serialize.py+++ b/marimo/_server/session/serialize.py@@ -151,6 +151,7 @@ def serialize_session_view(if console_out.channel == CellChannel.STDERRelse "stdout",text=str(console_out.data),+ mimetype=console_out.mimetype,))@@ -235,22 +236,33 @@ def deserialize_session(session: NotebookSessionV1) -> SessionView:else:is_stderr = console["name"] == "stderr"data = console["text"]- # HACK: We need to detect tracebacks in stderr by checking for HTML- # formatting.- is_traceback = (- is_stderr- and isinstance(data, str)- and data.startswith('<span class="codehilite">')- )++ # Use mimetype from console if available (new format)+ if "mimetype" in console and console["mimetype"] is not None:+ mimetype = console["mimetype"]+ else:+ # Backward compatibility: detect mimetype using heuristics+ # HACK: We need to detect tracebacks in stderr by checking for HTML+ # formatting.+ is_traceback = (+ is_stderr+ and isinstance(data, str)+ and data.startswith('<span class="codehilite">')+ )+ mimetype = cast(+ KnownMimeType,+ "application/vnd.marimo+traceback"+ if is_traceback+ else "text/plain",+ )+console_outputs.append(CellOutput(channel=CellChannel.STDERRif is_stderrelse CellChannel.STDOUT,data=data,- mimetype="application/vnd.marimo+traceback"- if is_traceback- else "text/plain",+ mimetype=mimetype,))diff --git a/packages/openapi/src/session.ts b/packages/openapi/src/session.tsindex eff7870e35..f4fb701de1 100644--- a/packages/openapi/src/session.ts+++ b/packages/openapi/src/session.ts@@ -72,6 +72,30 @@ export interface components {type: "streamMedia";};StreamOutput: {+ /** @enum {string|null} */+ mimetype:+ | "application/json"+ | "application/vnd.marimo+error"+ | "application/vnd.marimo+traceback"+ | "application/vnd.marimo+mimebundle"+ | "application/vnd.vega.v5+json"+ | "application/vnd.vegalite.v5+json"+ | "application/vnd.jupyter.widget-view+json"+ | "image/png"+ | "image/svg+xml"+ | "image/tiff"+ | "image/avif"+ | "image/bmp"+ | "image/gif"+ | "image/jpeg"+ | "video/mp4"+ | "video/mpeg"+ | "text/html"+ | "text/plain"+ | "text/markdown"+ | "text/latex"+ | "text/csv"+ | null;/** @enum {string} */name: "stdout" | "stderr";text: string;diff --git a/tests/_server/session/snapshots/console_session.json b/tests/_server/session/snapshots/console_session.jsonindex c18ae7414b..465bf47294 100644--- a/tests/_server/session/snapshots/console_session.json+++ b/tests/_server/session/snapshots/console_session.json@@ -12,14 +12,16 @@{"type": "stream","name": "stdout",- "text": "stdout message"+ "text": "stdout message",+ "mimetype": "text/plain"},{"type": "stream","name": "stderr",- "text": "stderr message"+ "text": "stderr message",+ "mimetype": "text/plain"}]}]-}+}\ No newline at end of filediff --git a/tests/_server/session/test_serialize_session.py b/tests/_server/session/test_serialize_session.pyindex dbf184e2d9..a33b4ed798 100644--- a/tests/_server/session/test_serialize_session.py+++ b/tests/_server/session/test_serialize_session.py@@ -693,6 +693,48 @@ def test_deserialize_error_with_traceback():assert console_output.data == tb+def test_deserialize_session_with_console_mimetype():+ """Test deserialization of a session with console output that has mimetype"""+ session = NotebookSessionV1(+ version=1,+ metadata={"marimo_version": "1.0.0"},+ cells=[+ {+ "id": "cell1",+ "code_hash": "123",+ "outputs": [],+ "console": [+ {+ "type": "stream",+ "name": "stdout",+ "text": "stdout message",+ "mimetype": "text/html",+ },+ {+ "type": "stream",+ "name": "stderr",+ "text": "stderr message",+ "mimetype": "text/plain",+ },+ ],+ }+ ],+ )++ view = deserialize_session(session)+ assert "cell1" in view.cell_operations+ cell = view.cell_operations["cell1"]+ assert isinstance(cell.console, list)+ assert len(cell.console) == 2+ console_outputs = cell.console+ assert console_outputs[0].channel == CellChannel.STDOUT+ assert console_outputs[0].data == "stdout message"+ assert console_outputs[0].mimetype == "text/html"+ assert console_outputs[1].channel == CellChannel.STDERR+ assert console_outputs[1].data == "stderr message"+ assert console_outputs[1].mimetype == "text/plain"++def test_serialize_session_with_dict_error():"""Test serialization of a session with a dictionary error"""view = SessionView()