Skip to content

Commit c2d86b9

Browse files
authored
Marimo build, test, deploy workflow (#22)
* wip: make marimo html-wasm example * feat: build all marimo notebooks and push to GH pages * docs: update README * chore: just pin to major versions * feat: add integration test for plant explorer * add playwright to wasm env * add pytest fixture which spins up a test server * futz around with playwright selectors to interact with different UI elements & look at charts * update GHA + export script to accommodate testing changes * update README :) * fix plant-explorer which didn't have a parquet engine imported -_- * docs: updates from PR review
1 parent 2b70842 commit c2d86b9

File tree

11 files changed

+1993
-42
lines changed

11 files changed

+1993
-42
lines changed

.github/workflows/deploy-marimo-pages.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,37 @@
22
name: Deploy Marimo Pages
33

44
on:
5+
workflow_dispatch:
56
push:
67
branches:
78
- main
89
paths:
9-
- "marimo/**"
10+
- "wasm/marimo/**"
11+
- "scripts/export_marimo_notebooks.py"
12+
- "pixi.toml"
13+
- "pixi.lock"
1014
- ".github/workflows/deploy-marimo-pages.yml"
11-
workflow_dispatch:
12-
1315
jobs:
1416
build:
1517
runs-on: ubuntu-latest
1618

1719
steps:
1820
- name: Checkout repository
19-
uses: actions/checkout@v5
21+
uses: actions/checkout@v6
2022

21-
- name: Set up pixi
22-
uses: prefix-dev/setup-pixi@v0.9.0
23+
- name: Install pixi
24+
uses: prefix-dev/setup-pixi@v0.9.3
2325
with:
24-
cache: true
26+
environments: wasm
2527

2628
- name: Ensure docs directory exists
2729
run: mkdir -p docs/
2830

2931
- name: Export Marimo notebooks
30-
run: |
31-
pixi run marimo export html-wasm marimo/sec10k-data-review.py -o docs/sec10k-data-review.html --mode edit
32-
33-
- name: Verify generated files
34-
run: |
35-
echo "Generated files:"
36-
find docs -type f -name "*.html" -exec ls -la {} \;
32+
run: pixi run -e wasm export-wasm-marimo
3733

3834
- name: Upload Pages Artifact
39-
uses: actions/upload-pages-artifact@v3
35+
uses: actions/upload-pages-artifact@v4
4036
with:
4137
path: docs/
4238

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Integration Tests
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- "wasm/marimo/**"
8+
- "scripts/export_marimo_notebooks.py"
9+
- "pixi.toml"
10+
- "pixi.lock"
11+
- ".github/workflows/integration-tests.yml"
12+
- "tests/playwright/**"
13+
14+
jobs:
15+
wasm-marimo-playwright:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
22+
- name: Install pixi
23+
uses: prefix-dev/setup-pixi@v0.9.3
24+
with:
25+
environments: wasm
26+
27+
- name: Install Playwright browser
28+
run: pixi run -e wasm playwright install --with-deps chromium
29+
30+
- name: Run Playwright tests against exported notebooks
31+
run: pixi run -e wasm test-wasm-marimo

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
**/*.swp
44
dask-worker-space
55
**/__pycache__/
6+
docs/
7+
tests/playwright/_build/

README.md

Lines changed: 103 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,44 @@ This repository contains a collection of
55
and software distributed by [Catalyst Cooperative](https://catalyst.coop)'s
66
[Public Utility Data Liberation (PUDL) project](https://github.com/catalyst-cooperative/pudl).
77

8-
The notebooks in the top-level directory of the repository are mirrored from the
9-
[Kaggle
10-
notebooks](https://www.kaggle.com/datasets/catalystcooperative/pudl-project/data).
11-
**Any changes made to these notebooks directly in this repository will be overwritten.**
8+
We have multiple categories of notebooks in this repository:
129

10+
| Category | File location | Description | Live view | Local dev env |
11+
| --- | --- | --- | --- | --- |
12+
| [Kaggle notebooks](#kaggle-notebooks) | repository root | Mirrored from the [Kaggle notebooks](https://www.kaggle.com/code/catalystcooperative/). Any changes made to these notebooks directly in this repository will be overwritten. | [Kaggle](https://www.kaggle.com/code/catalystcooperative/) | `pixi run -e kaggle jupyter lab` |
13+
| [WebAssembly Marimo notebooks](#webassembly-marimo-notebooks) | `wasm/marimo` | Marimo notebooks designed for exporting as interactive browser dashboards. | [PUDL Data Viewer](https://data.catalyst.coop/secret-gallery) | `pixi run -e wasm marimo edit` |
1314

14-
## Run Jupyter Notebooks on Kaggle
15+
## General development notes
1516

16-
The easiest way to get up and running with the Jupyter examples and a fresh copy of all the
17-
PUDL data is on [Kaggle](https://www.kaggle.com).
17+
We use `pixi` to manage the Python environment. You can install it according to
18+
[their instructions](https://pixi.sh/latest/installation).
19+
20+
We use multiple `pixi` environments to manage the various quirks of the
21+
different execution environments of our notebooks: we currently have `kaggle`
22+
and `wasm` defined. We also have `dev` defined for repository-infrastructure
23+
related tools.
24+
25+
Speaking of which - you probably want to install the pre-commit hooks if you're
26+
planning on making changes to the notebooks, the repository infrastructure, or
27+
anything else that might require you to commit something.
28+
29+
```
30+
$ pixi run -e dev pre-commit install
31+
```
32+
33+
## Kaggle notebooks
34+
35+
These are notebooks which explore how to access PUDL and showcase some potential
36+
analyses you can do. They are intended to serve as jumping-off points for your
37+
own code.
38+
39+
Critically, these are mirrored from Kaggle, and updates in this repository will
40+
be overwritten from Kaggle.
41+
42+
### Running on Kaggle
43+
44+
The easiest way to get up and running with a fresh copy of all the PUDL data is
45+
on [Kaggle](https://www.kaggle.com).
1846

1947
Kaggle offers substantial free computing resources and convenient data storage, so you
2048
can start playing with the PUDL data without needing to set up any software or download
@@ -26,24 +54,15 @@ any data.
2654
- [03 EIA-930 Sanity Checks](https://www.kaggle.com/code/catalystcooperative/03-eia-930-sanity-checks)
2755
- [04 Renewable Generation Profiles](https://www.kaggle.com/code/catalystcooperative/04-renewable-generation-profiles)
2856
- [05 FERC-714 Electricity Demand Forecast Biases](https://www.kaggle.com/code/catalystcooperative/05-ferc-714-electricity-demand-forecast-biases)
57+
- [06 PUDL Imputed Electricity Demand](https://www.kaggle.com/code/catalystcooperative/06-pudl-imputed-electricity-demand)
58+
- [07 FERC EQR Access](www.kaggle.com/code/catalystcooperative/07-ferc-eqr-access)
2959

3060
You'll find the [PUDL data dictionary](https://catalystcoop-pudl.readthedocs.io/en/latest/data_dictionaries/pudl_db.html)
3161
helpful for interpreting the data.
3262

33-
## Run Kaggle Notebooks Locally
63+
### Running locally
3464

35-
You can also work with these notebooks and the PUDL data locally.
36-
37-
We use `pixi` to manage the Python environment. You can install it according to
38-
[their instructions](https://pixi.sh/latest/installation).
39-
40-
Then install the project environment including development dependencies:
41-
42-
```
43-
$ pixi install -e kaggle
44-
```
45-
46-
To run the Jupyter notebooks, run:
65+
To run these notebooks locally, run:
4766

4867
```
4968
$ pixi run -e kaggle jupyter lab
@@ -58,15 +77,13 @@ You can find detailed instructions for how to download the data in our [data
5877
access
5978
documentation](https://catalystcoop-pudl.readthedocs.io/en/nightly/data_access.html#quick-reference).
6079

61-
## Developer notes
80+
#### Updating the dependencies
6281

63-
To install the pre-commit hooks, run:
82+
The Kaggle Python environment is an eternally shifting patchwork of
83+
dependencies. We try to keep the Pixi environment up to date by occasionally
84+
running a notebook on Kaggle that just checks dependency versions.
6485

65-
```
66-
$ pixi run -e dev pre-commit install
67-
```
68-
69-
To update the Kaggle dependency pins:
86+
To update the Kaggle dependency pins yourself:
7087

7188
1. Create a Kaggle API token and put it in your env as `KAGGLE_API_TOKEN`.
7289
2. Run the sync script:
@@ -78,6 +95,65 @@ $ pixi run -e dev sync-kaggle-deps
7895
dependencies to `--exclude` in the `sync-kaggle-deps` pixi task.
7996

8097

98+
## WebAssembly Marimo notebooks
99+
100+
These are designed to be exported to HTML and viewed in a web browser as an
101+
interactive dashboard or visualization.
102+
103+
### Viewing in-browser
104+
105+
These are currently viewable on the [PUDL Data
106+
Viewer](https://data.catalyst.coop/secret-gallery). Click through and play
107+
around!
108+
109+
### Running locally
110+
111+
Run `marimo edit` to start editing:
112+
113+
```
114+
$ pixi run -e wasm marimo edit wasm/marimo
115+
```
116+
117+
If you want to export the notebooks to WebAssembly and see if they work as
118+
standalone HTML pages:
119+
120+
```
121+
$ pixi run -e wasm export-wasm-marimo --serve
122+
```
123+
124+
Then go to `localhost:8000/<your-notebook-name>.html` to see it work!
125+
126+
This uses [`pyodide`](https://pyodide.org/) to run Python in your browser, which
127+
comes with a few quirks:
128+
129+
* Marimo is currently (as of 2026-02-27) pinned to version `0.27.7` - which
130+
means the [libraries that are
131+
available](https://pyodide.org/en/0.27.7/usage/packages-in-pyodide.html) in
132+
`pyodide` are pretty old. To minimize shock while going from `marimo edit` to
133+
the exported version, we pin dependencies based on those versions.
134+
* You have to explicitly import `fastparquet` or `pyarrow` for
135+
`pandas.read_parquet` to actually work. `fastparquet` is 3-10x faster.
136+
137+
See the [Marimo docs](https://docs.marimo.io/guides/wasm/) for more details.
138+
139+
140+
Finally, if you want to add automated tests with `playwright`:
141+
142+
First, install a browser driver for `playwright`:
143+
144+
```
145+
$ pixi run -e wasm playwright install --with-deps chromium
146+
```
147+
148+
Then, run the tests:
149+
150+
```
151+
$ pixi run -e wasm test-wasm-marimo
152+
```
153+
154+
You can add more tests in `tests/playwright/...`
155+
156+
81157
## Stalk us on the Internet
82158

83159
- <https://catalyst.coop>

0 commit comments

Comments
 (0)