Files
Vijay Janapa Reddi 9c91cc5e4a fix(labs): inline WASM bootstrap so Pyodide can find it
marimo's html-wasm export bundles only the notebook .py file.
The shared labs/bootstrap.py is not available in the Pyodide
virtual filesystem, so `from bootstrap import setup_lab` fails
with ModuleNotFoundError on every lab in the browser smoke test.

WASM bootstrapping is inherently inline work: you cannot import
a module to install the modules it needs. Each lab's Cell 0 now
handles the two paths directly:

  - emscripten: micropip.install the runtime packages + wheel
  - native: bootstrap.native_bootstrap() for sys.path setup

bootstrap.py is simplified to native-only (the WASM path in
setup_lab was unreachable and its wheel_relpath() would also
have failed reading pyproject.toml from the virtual filesystem).

The existing test_static.py wheel-version consistency test still
catches drift: it reads the version from pyproject.toml and
asserts the inline micropip URL matches across all 33 labs.
2026-05-27 06:17:36 -04:00

25 lines
752 B
Python

"""Native-only bootstrap for Marimo co-labs (not part of the mlsysim wheel).
WASM bootstrap (micropip.install) is handled inline in each lab's Cell 0
because marimo's html-wasm export bundles only the notebook .py file —
bootstrap.py is not available in the Pyodide virtual filesystem.
"""
from __future__ import annotations
import sys
from pathlib import Path
def _repo_root(lab_file: str) -> Path:
return Path(lab_file).resolve().parents[2]
def native_bootstrap(lab_file: str) -> None:
"""Add repo root to sys.path for editable/local mlsysim imports."""
if sys.platform == "emscripten" or "mlsysim" in sys.modules:
return
root = str(_repo_root(lab_file))
if root not in sys.path:
sys.path.insert(0, root)