Skip to content

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.

fix: imports being stripped by vanilla ruff (#3952)

Dylan Madisettib722dff82a13
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index 69237ae487..3b28f08296 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -24,9 +24,8 @@ MAX_LINE_LENGTH = 80
NOTICE = "\n".join(
[
- "# These imports are auto-generated by marimo.",
- "# Try modifying the source cell definitions",
- "# opposed to the following block.",
+ "# Imports used by your notebook.",
+ "# This section is automatically generated by marimo.",
]
)
@@ -131,7 +130,8 @@ def build_import_section(import_blocks: list[str]) -> str:
if not formatted:
return code
try:
- tidied = ruff(formatted, "check", "--fix-only")
+ # Note F401 strips unused imports, which is this whole block.
+ tidied = ruff(formatted, "check", "--fix-only", "--ignore=F401")
if tidied:
return tidied[stub_cell_id] + "\n\n"
# Thrown in WASM
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_toplevel.py b/tests/_ast/codegen_data/test_generate_filecontents_toplevel.py
index 6e5b9f03b8..0e4d958d20 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_toplevel.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_toplevel.py
@@ -7,9 +7,8 @@
import marimo
with marimo.import_guard():
- # These imports are auto-generated by marimo.
- # Try modifying the source cell definitions
- # opposed to the following block.
+ # Imports used by your notebook.
+ # This section is automatically generated by marimo.
import io
import textwrap
import typing
diff --git a/tests/_ast/test_pytest_toplevel.py b/tests/_ast/test_pytest_toplevel.py
index 0372055b99..dc22895be9 100644
--- a/tests/_ast/test_pytest_toplevel.py
+++ b/tests/_ast/test_pytest_toplevel.py
@@ -3,9 +3,8 @@
import marimo
with marimo.import_guard():
- # These imports are auto-generated by marimo.
- # Try modifying the source cell definitions
- # opposed to the following block.
+ # Imports used by your notebook.
+ # This section is automatically generated by marimo.
import pytest