File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,68 @@ def test_ensure_python_version_in_script_metadata(tmp_path: Path) -> None:
633633 assert f">={ major } .{ minor } " in content
634634
635635
636+ def test_ensure_python_version_preserves_formatting (tmp_path : Path ) -> None :
637+ """Test that adding requires-python preserves formatting and only modifies the header.
638+
639+ Regression test for #8054. Also verifies that similar patterns in file (e.g., docstrings) are not affected.
640+ """
641+ import platform
642+
643+ # Multi-line deps list that would be reformatted by re-serialization,
644+ # plus a docstring with similar-looking text that should not be modified
645+ original = '''# /// script
646+ # dependencies = [
647+ # "polars",
648+ # "marimo>=0.8.0",
649+ # ]
650+ # ///
651+ import marimo
652+
653+ app = marimo.App()
654+
655+ @app.cell
656+ def __():
657+ """
658+ Example of PEP 723 metadata:
659+
660+ # /// script
661+ # requires-python = ">=3.11"
662+ # ///
663+ """
664+ return ()
665+ '''
666+ script_path = tmp_path / "test.py"
667+ script_path .write_text (original )
668+
669+ _ensure_python_version_in_script_metadata (str (script_path ))
670+
671+ content = script_path .read_text ()
672+ major , minor = platform .python_version_tuple ()[:2 ]
673+ expected = f'''# /// script
674+ # requires-python = ">={ major } .{ minor } "
675+ # dependencies = [
676+ # "polars",
677+ # "marimo>=0.8.0",
678+ # ]
679+ # ///
680+ import marimo
681+
682+ app = marimo.App()
683+
684+ @app.cell
685+ def __():
686+ """
687+ Example of PEP 723 metadata:
688+
689+ # /// script
690+ # requires-python = ">=3.11"
691+ # ///
692+ """
693+ return ()
694+ '''
695+ assert content == expected
696+
697+
636698def test_ensure_python_version_in_script_metadata_noop_when_present (
637699 tmp_path : Path ,
638700) -> None :
You can’t perform that action at this time.
0 commit comments