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: supress warnings for meta information in config in markdown (#8290)
Dylan Madisetti21df34379019
diff --git a/marimo/_ast/app_config.py b/marimo/_ast/app_config.pyindex 6b27f739d0..ec535cc1a6 100644--- a/marimo/_ast/app_config.py+++ b/marimo/_ast/app_config.py@@ -42,6 +42,11 @@ class _AppConfig:# The type of SQL output to displaysql_output: SqlOutputType = "auto"+ @staticmethod+ def sanitize(updates: dict[str, Any]) -> dict[str, Any]:+ """Return only recognized config keys, silently dropping others."""+ return {k: v for k, v in updates.items() if hasattr(_AppConfig, k)}+@staticmethoddef from_untrusted_dict(updates: dict[str, Any], silent: bool = Falsediff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.pyindex b5065ea7e4..42bfac9e2b 100644--- a/marimo/_ast/codegen.py+++ b/marimo/_ast/codegen.py@@ -22,6 +22,7 @@ from marimo._ast.visitor import Name, VariableDatafrom marimo._convert.converters import MarimoConvertfrom marimo._schemas.serialization import NotebookSerializationV1from marimo._types.ids import CellId_t+from marimo._utils.marimo_path import MarimoPathfrom marimo._version import __version__if TYPE_CHECKING:@@ -486,15 +487,53 @@ def generate_app_constructor(config: Optional[_AppConfig]) -> str:def generate_filecontents_from_ir(ir: NotebookSerializationV1) -> str:+ # Markdown frontmatter may contain non-config metadata (e.g., author,+ # description). Suppress warnings for unrecognized keys from markdown.+ silent = (+ MarimoPath(ir.filename).is_markdown()+ if ir.filename and ir.filename != "<marimo>"+ else False+ )+ header_comments = _extract_header_comments(ir)return generate_filecontents(codes=[cell.code for cell in ir.cells],names=[cell.name for cell in ir.cells],cell_configs=[CellConfig.from_dict(cell.options) for cell in ir.cells],- config=_AppConfig.from_untrusted_dict(ir.app.options),- header_comments=ir.header.value if ir.header else None,+ config=_AppConfig.from_untrusted_dict(ir.app.options, silent=silent),+ header_comments=header_comments,)+def _extract_header_comments(ir: NotebookSerializationV1) -> Optional[str]:+ """Extract script preamble from header.++ For markdown notebooks, Header.value may contain YAML-encoded frontmatter+ metadata (with a 'header' key for the script preamble, and/or a+ 'pyproject' key for inline dependencies). For Python notebooks, it's the+ raw script preamble.+ """+ if not ir.header or not ir.header.value:+ return None+ from marimo._utils import yaml++ try:+ parsed = yaml.load(ir.header.value)+ if isinstance(parsed, dict):+ # YAML dict means frontmatter metadata; extract script preamble+ header = parsed.get("header", None)+ pyproject = parsed.get("pyproject", None)+ if header:+ return str(header)+ if pyproject:+ from marimo._utils.scripts import wrap_script_metadata++ return wrap_script_metadata(pyproject)+ return None+ except (yaml.YAMLError, AssertionError):+ pass+ return ir.header.value++def generate_filecontents(codes: list[str],names: list[str],diff --git a/marimo/_ast/load.py b/marimo/_ast/load.pyindex 0b029ceb25..7beeb053e1 100644--- a/marimo/_ast/load.py+++ b/marimo/_ast/load.py@@ -7,6 +7,7 @@ from typing import Literal, Optional, Unionfrom marimo import _loggersfrom marimo._ast.app import App, InternalApp+from marimo._ast.app_config import _AppConfigfrom marimo._ast.parse import (MarimoFileError,NonMarimoPythonScriptError,@@ -19,6 +20,7 @@ from marimo._schemas.serialization import (UnparsableCell,)from marimo._session.notebook.serializer import get_notebook_serializer+from marimo._utils.marimo_path import MarimoPathLOGGER = _loggers.marimo_logger()@@ -84,7 +86,14 @@ def load_notebook_ir(# Use filepath from notebook if not explicitly providedif filepath is None:filepath = notebook.filename- app = App(**notebook.app.options, _filename=filepath)++ # Markdown frontmatter may contain non-config metadata (e.g., author,+ # description). Filter to only pass recognized config keys to App().+ options = notebook.app.options+ if filepath and MarimoPath(filepath).is_markdown():+ options = _AppConfig.sanitize(options)++ app = App(**options, _filename=filepath)for cell in notebook.cells:if isinstance(cell, UnparsableCell):app._unparsable_cell(cell.code, **cell.options)diff --git a/marimo/_convert/markdown/from_ir.py b/marimo/_convert/markdown/from_ir.pyindex 81547dfdfd..35c9f762f3 100644--- a/marimo/_convert/markdown/from_ir.py+++ b/marimo/_convert/markdown/from_ir.py@@ -62,9 +62,18 @@ def convert_from_ir_to_markdown(})- # Add header from notebook if present+ # Recover frontmatter metadata from headerif notebook.header and notebook.header.value:- metadata["header"] = notebook.header.value.strip()+ try:+ frontmatter = yaml.load(notebook.header.value)+ if isinstance(frontmatter, dict):+ # Insert metadata before config so config takes precedence+ _recovered = dict(frontmatter)+ _recovered.update(metadata)+ metadata = _recovered+ except (yaml.YAMLError, AssertionError):+ # Not valid YAML dict — treat as script preamble+ metadata["header"] = notebook.header.value.strip()# Add the expected qmd filter to the metadata.is_qmd = filename.endswith(".qmd")diff --git a/marimo/_convert/markdown/to_ir.py b/marimo/_convert/markdown/to_ir.pyindex 509808ed87..0cf787c09e 100644--- a/marimo/_convert/markdown/to_ir.py+++ b/marimo/_convert/markdown/to_ir.py@@ -195,7 +195,12 @@ class SafeWrap(Generic[T]):def _tree_to_ir(root: Element) -> SafeWrap[NotebookSerializationV1]:+ from marimo._ast.app_config import _AppConfig+ from marimo._utils import yaml+ from marimo._utils.scripts import wrap_script_metadata+app_config = app_config_from_root(root)+ config_only = _AppConfig.sanitize(app_config)sources: list[str] = []names: list[str] = []@@ -208,14 +213,28 @@ def _tree_to_ir(root: Element) -> SafeWrap[NotebookSerializationV1]:)sources.append(get_source_from_tag(child))- from marimo._utils.scripts import wrap_script_metadata-- header = root.get("header", None)+ header_str = root.get("header", None)pyproject = root.get("pyproject", None)- if pyproject and not header:- header = wrap_script_metadata(pyproject)++ # Collect non-config frontmatter metadata+ frontmatter = {k: v for k, v in app_config.items() if k not in config_only}+ if pyproject:+ frontmatter["pyproject"] = pyproject+ if header_str:+ frontmatter["header"] = header_str++ # Build header: frontmatter YAML for md, or script preamble+ if frontmatter:+ header_value = yaml.dump(frontmatter, sort_keys=False)+ elif pyproject and not header_str:+ header_value = wrap_script_metadata(pyproject)+ elif header_str:+ header_value = header_str+ else:+ header_value = None+notebook = NotebookSerializationV1(- app=AppInstantiation(options=app_config),+ app=AppInstantiation(options=config_only),cells=[CellDef(name=name,@@ -224,7 +243,7 @@ def _tree_to_ir(root: Element) -> SafeWrap[NotebookSerializationV1]:)for name, source, config in zip(names, sources, cell_config)],- header=Header(value=header) if header else None,+ header=Header(value=header_value) if header_value else None,)return SafeWrap(notebook)diff --git a/marimo/_session/notebook/serializer.py b/marimo/_session/notebook/serializer.pyindex b5f35933f9..e0bcf85d00 100644--- a/marimo/_session/notebook/serializer.py+++ b/marimo/_session/notebook/serializer.py@@ -102,14 +102,21 @@ class MarkdownNotebookSerializer(NotebookSerializer):return convert_from_md_to_marimo_ir(content, filepath=filepath)def extract_header(self, path: Path) -> Optional[str]:- """Extract YAML frontmatter from Markdown file."""- from marimo._utils.inline_script_metadata import (- get_headers_from_markdown,- )+ """Extract full frontmatter metadata from Markdown file as YAML.++ Unlike Python files where only the script preamble matters, markdown+ frontmatter can carry arbitrary metadata (author, description, tags,+ etc.) that must survive through the save lifecycle. Return the full+ frontmatter as YAML so _save_file() preserves it all.+ """+ from marimo._convert.markdown.to_ir import extract_frontmatter+ from marimo._utils import yamlmarkdown = path.read_text(encoding="utf-8")- headers = get_headers_from_markdown(markdown)- return headers.get("header", None) or headers.get("pyproject", None)+ frontmatter, _ = extract_frontmatter(markdown)+ if not frontmatter:+ return None+ return yaml.dump(frontmatter, sort_keys=False)# Default format handlersdiff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.pyindex 8d7444fd23..58b2b3b64d 100644--- a/tests/_cli/test_cli.py+++ b/tests/_cli/test_cli.py@@ -557,6 +557,46 @@ def test_cli_edit_new_file() -> None:_check_contents(p, b'"serverToken": ', contents)+def test_cli_edit_markdown_no_config_warnings() -> None:+ """Markdown frontmatter metadata should not produce config warnings.++ Regression test for https://github.com/marimo-team/marimo/issues/8259+ """+ d = tempfile.TemporaryDirectory()+ path = os.path.join(d.name, "notebook.md")+ with open(path, "w") as f:+ f.write(+ "---\n"+ "title: My Notebook\n"+ "author: Test Author\n"+ 'description: "A test notebook"\n'+ "---\n\n"+ "```python {.marimo}\n"+ "x = 1\n"+ "```\n"+ )++ port = _get_port()+ p = subprocess.Popen(+ [+ "marimo",+ "edit",+ path,+ "-p",+ str(port),+ "--headless",+ "--no-token",+ "--skip-update-check",+ ],+ stderr=subprocess.PIPE,+ )+ contents = _try_fetch(port)+ assert contents is not None+ p.kill()+ _, stderr = p.communicate(timeout=5)+ assert b"Unrecognized key" not in stderr++def test_cli_edit_with_additional_args(temp_marimo_file: str) -> None:port = _get_port()p = subprocess.Popen(diff --git a/tests/_convert/markdown/test_markdown_conversion.py b/tests/_convert/markdown/test_markdown_conversion.pyindex c22e22b5b8..dddd408709 100644--- a/tests/_convert/markdown/test_markdown_conversion.py+++ b/tests/_convert/markdown/test_markdown_conversion.py@@ -172,6 +172,34 @@ def test_markdown_just_frontmatter() -> None:assert app.cell_manager.cell_data_at(ids[0]).code == ""+def test_markdown_frontmatter_metadata_roundtrip() -> None:+ """Frontmatter metadata should survive md -> IR -> md roundtrip."""+ script = dedent(+ remove_empty_lines(+ """+ ---+ title: "My Title"+ author: "Marimo Team"+ description: "A notebook description"+ ---++ ```python {.marimo}+ x = 1+ ```+ """+ )+ )++ notebook_ir = convert_from_md_to_marimo_ir(script)+ roundtripped = MarimoConvert.from_ir(notebook_ir).to_markdown()+ assert "author: Marimo Team" in roundtripped+ # Description is preserved but YAML may use folded style (>-)+ from marimo._convert.markdown.to_ir import extract_frontmatter++ meta, _ = extract_frontmatter(roundtripped)+ assert meta["description"] == "A notebook description"++@pytest.mark.requires("duckdb")def test_markdown_with_sql() -> None:script = dedent(