Skip to content

Play Notebook Marimo Globals

The Harvest, Territory, and Chemistry play_mo.py notebooks keep their interactive pygame loop in a single marimo cell. marimo still treats top-level imports and helper definitions inside a cell as notebook-level names, so generic helpers such as blit_frame and build_keymap can trip "redefines variables from other cells" errors when a notebook is edited or split.

The play notebooks avoid that by:

  • importing shared rendering modules under domain-specific aliases, e.g. harvest_rgb_renderer instead of binding blit_frame directly;
  • giving local helpers domain-specific names, e.g. build_territory_keymap;
  • keeping mutable pygame toggles in a small runtime_state dict instead of using nonlocal from notebook cell scope.

After touching these files, run:

uv run marimo check --strict notebooks/gridworlds/harvest/play_mo.py
uv run marimo check --strict notebooks/gridworlds/territory/play_mo.py
uv run marimo check --strict notebooks/gridworlds/chemistry/play_mo.py