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: Do not construct a full app just to check parsing (#4790)
Dylan Madisetti686d097ee43e
diff --git a/marimo/_ast/load.py b/marimo/_ast/load.pyindex 9ea9904709..a1220de1d0 100644--- a/marimo/_ast/load.py+++ b/marimo/_ast/load.py@@ -3,7 +3,7 @@ from __future__ import annotationsimport importlib.utilimport sys-from typing import Optional+from typing import Literal, Optionalfrom marimo import _loggersfrom marimo._ast.app import App, InternalApp@@ -73,6 +73,33 @@ def _static_load(filename: str) -> Optional[App]:return app+def notebook_is_openable(filename: str) -> Literal[True]:+ """Attempts to parse an app- should raise SyntaxError on failure.++ Args:+ filename: Path to a marimo notebook file (.py or .md)++ Returns:+ True if a falid code path.++ Raises:+ SyntaxError: If the file contains a syntax error+ """++ if filename.endswith(".md") or filename.endswith(".qmd"):+ contents = _maybe_contents(filename)+ if not contents:+ # We can still "open" it+ return True+ from marimo._cli.convert.markdown import convert_from_md++ _ = convert_from_md(contents)+ return True+ _ = parse_notebook(filename)+ # NB. A invalid notebook can still be opened.+ return True++def load_app(filename: Optional[str]) -> Optional[App]:"""Load and return app from a marimo-generated module.diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.pyindex fda6a38942..6b47787e5a 100644--- a/marimo/_cli/cli.py+++ b/marimo/_cli/cli.py@@ -13,7 +13,8 @@ import clickimport marimo._cli.cli_validators as validatorsfrom marimo import __version__, _loggers-from marimo._ast import codegen, load+from marimo._ast import codegen+from marimo._ast.load import notebook_is_openablefrom marimo._cli.config.commands import configfrom marimo._cli.convert.commands import convertfrom marimo._cli.development.commands import development@@ -56,7 +57,7 @@ def helpful_usage_error(self: Any, file: Any = None) -> None:def check_app_correctness(filename: str) -> None:try:- load.load_app(filename)+ notebook_is_openable(filename)except SyntaxError:import traceback