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: copy public folder (#3354)
Myles Scolnick4febb5c3d37a
diff --git a/marimo/_cli/export/commands.py b/marimo/_cli/export/commands.pyindex 52bcad4b4b..bea15d5a7e 100644--- a/marimo/_cli/export/commands.py+++ b/marimo/_cli/export/commands.py@@ -444,6 +444,8 @@ def html_wasm(filename = os.path.basename(output)ignore_index_html = True+ marimo_file = MarimoPath(name)+def export_callback(file_path: MarimoPath) -> ExportResult:return export_as_wasm(file_path, mode, show_code=show_code)@@ -459,6 +461,13 @@ def html_wasm("notebook to run in the browser.")+ did_export_public = Exporter().export_public_folder(out_dir, marimo_file)+ if did_export_public:+ echo(+ f"The public folder next to your notebook was copied to "+ f"{green(out_dir)}."+ )+echo("To run the exported notebook, use:\n"f" python -m http.server --directory {out_dir}\n"diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.pyindex 2d8dfdf834..592662de02 100644--- a/marimo/_server/export/exporter.py+++ b/marimo/_server/export/exporter.py@@ -44,6 +44,7 @@ from marimo._server.templates.templates import (wasm_notebook_template,)from marimo._server.tokens import SkewProtectionToken+from marimo._utils.marimo_path import MarimoPathfrom marimo._utils.paths import import_filesLOGGER = _loggers.marimo_logger()@@ -378,6 +379,29 @@ class Exporter:),)+ def export_public_folder(+ self, directory: str, marimo_file: MarimoPath+ ) -> bool:+ public_dir = marimo_file.path.parent / "public"++ if public_dir.exists():+ import shutil++ # Copy public folder to the same directory as the notebook+ dirpath = Path(directory)+ if not dirpath.exists():+ dirpath.mkdir(parents=True, exist_ok=True)++ LOGGER.debug(f"Copying public folder to {dirpath}")+ shutil.copytree(+ public_dir,+ dirpath / "public",+ dirs_exist_ok=True,+ )+ return True++ return False+class AutoExporter:EXPORT_DIR = "__marimo__"diff --git a/tests/_cli/test_cli_export.py b/tests/_cli/test_cli_export.pyindex 9406d182af..1f479382da 100644--- a/tests/_cli/test_cli_export.py+++ b/tests/_cli/test_cli_export.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport asyncioimport inspectimport json+import shutilimport subprocessimport sysfrom os import path@@ -87,6 +88,33 @@ class TestExportHTML:assert "<marimo-wasm" in htmlassert Path(out_dir / ".nojekyll").exists()+ @staticmethod+ def test_cli_export_html_wasm_public_folder(temp_marimo_file: str) -> None:+ # Create public folder next to temp file with some content+ public_dir = Path(temp_marimo_file).parent / "public"+ public_dir.mkdir(exist_ok=True)+ (public_dir / "test.txt").write_text("test content")++ out_dir = Path(temp_marimo_file).parent / "out"+ p = subprocess.run(+ [+ "marimo",+ "export",+ "html-wasm",+ temp_marimo_file,+ "--output",+ out_dir,+ ],+ capture_output=True,+ )+ assert p.returncode == 0, p.stderr.decode()+ # Verify public folder was copied+ assert (out_dir / "public" / "test.txt").exists()+ assert (out_dir / "public" / "test.txt").read_text() == "test content"++ # Clean up+ shutil.rmtree(public_dir)+@staticmethoddef test_cli_export_html_wasm_output_is_file(temp_marimo_file: str,