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
feat: add wasm watch and some docs on set up (#3572)
Shahmir Varqhaf9d5c37304c0
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex a4fecd8f4b..e77473dde5 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -168,7 +168,9 @@ make fe-test### Python-Using Make:+We use [pytest syntax](https://docs.pytest.org/en/stable/how-to/usage.html) for Python tests.++#### Using Make```bashmake py-test@@ -176,27 +178,25 @@ make py-test#### Using Hatch-**Run a specific tests.**+Run a specific test```bashhatch run test:test tests/_ast/```-**Run a specific test with optional dependencies.**-+Run tests with optional dependencies```bashhatch run test-optional:test tests/_ast/```-**Run tests with a specific Python version.**-+Run tests with a specific Python version```bashhatch run +py=3.10 test:test tests/_ast/# orhatch run +py=3.10 test-optional:test tests/_ast/```-**Run all tests across all Python versions.**+Run all tests across all Python versionsNot recommended since it takes a long time.diff --git a/docs/guides/editor_features/watching.md b/docs/guides/editor_features/watching.mdindex ca8d9af3e3..007630a84d 100644--- a/docs/guides/editor_features/watching.md+++ b/docs/guides/editor_features/watching.md@@ -45,3 +45,17 @@ Guide](module_autoreloading.md)!!! noteSupport for watching data files and automatically refreshing cells that depend on them is coming soon. Follow along at <https://github.com/marimo-team/marimo/issues/3258>+## Developing in WASM mode++Follow these steps to develop a notebook using your own editor, while previewing it as a WebAssembly notebook in the browser. This lets you take advantage of local development tools while seeing the notebook as it appears when deployed as a [WebAssembly notebook](../wasm.md).+```bash+# in one terminal, start a watched edit session+marimo edit notebook.py --watch++# in another terminal+marimo export html-wasm notebook.py -o output_dir --watch++# in a third terminal, serve the WASM application+cd path/to/output_dir+python -m http.server # or a server that watches for changes+```\ No newline at end of filediff --git a/docs/guides/exporting.md b/docs/guides/exporting.mdindex 4c58c75e97..a1238c1141 100644--- a/docs/guides/exporting.md+++ b/docs/guides/exporting.md@@ -146,6 +146,7 @@ Options:- `--mode`: Choose between `run` (read-only) or `edit` (allows editing)- `--output`: Directory to save the HTML and required assets- `--show-code/--no-show-code`: Whether to initially show or hide the code in the notebook+- `--watch/--no-watch`: Watch the notebook for changes and automatically export!!! note "Note"diff --git a/marimo/_cli/export/commands.py b/marimo/_cli/export/commands.pyindex bea15d5a7e..50021dc21b 100644--- a/marimo/_cli/export/commands.py+++ b/marimo/_cli/export/commands.py@@ -414,6 +414,12 @@ and cannot be opened directly from the file system (e.g. file://).show_default=True,required=True,)+ "--watch/--no-watch",+ default=False,+ show_default=True,+ help=("Whether to watch the original file and export upon change"),+)@click.option("--show-code/--no-show-code",default=False,@@ -432,6 +438,7 @@ def html_wasm(name: str,output: str,mode: Literal["edit", "run"],+ watch: bool,show_code: bool,) -> None:"""Export a notebook as a WASM-powered standalone HTML file."""@@ -475,7 +482,7 @@ def html_wasm()outfile = os.path.join(out_dir, filename)- return watch_and_export(MarimoPath(name), outfile, False, export_callback)+ return watch_and_export(MarimoPath(name), outfile, watch, export_callback)export.add_command(html)diff --git a/tests/_cli/test_cli_export.py b/tests/_cli/test_cli_export.pyindex 78e4d238d3..4298c9ba69 100644--- a/tests/_cli/test_cli_export.py+++ b/tests/_cli/test_cli_export.py@@ -7,6 +7,7 @@ import jsonimport shutilimport subprocessimport sys+import timefrom os import pathfrom pathlib import Pathfrom typing import TYPE_CHECKING@@ -161,6 +162,52 @@ class TestExportHTML:)assert "<marimo-wasm" in html+ @pytest.mark.skipif(+ # if hangs on watchdog, add a dependency check+ condition=_is_win32(),+ reason="flaky on Windows",+ )+ @staticmethod+ def test_cli_export_html_wasm_watch(temp_marimo_file: str) -> None:+ out_dir = Path(temp_marimo_file).parent / "out"+ p = subprocess.Popen(+ [+ "marimo",+ "export",+ "html-wasm",+ temp_marimo_file,+ "--output",+ out_dir,+ "--watch",+ ],+ stdout=subprocess.PIPE,+ stderr=subprocess.PIPE,+ )++ watch_echo_found = False+ for _ in range(10): # read 10 lines+ line = p.stdout.readline()+ if not line:+ break+ line_str = line.decode()+ if f"Watching {temp_marimo_file}" in line_str:+ watch_echo_found = True+ break+ time.sleep(0.01) # avoid flaky test+ assert watch_echo_found is True++ # Modify file+ with open(temp_marimo_file, "a") as f:+ f.write("\n# comment\n")++ assert p.poll() is None+ for _ in range(5):+ line = p.stdout.readline().decode()+ if line:+ assert "Re-exporting" in line+ break+ time.sleep(0.01)+@staticmethoddef test_cli_export_async(temp_async_marimo_file: str) -> None:p = subprocess.run(