Skip to content

Commit b3830b2

Browse files
authored
Merge pull request #58 from ksunden/jupyterlite
WIP: enable jupyterlite pixi tasks
2 parents 38619bb + e7d2c81 commit b3830b2

File tree

6 files changed

+116
-14
lines changed

6 files changed

+116
-14
lines changed

.github/workflows/cd.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ jobs:
2929
- name: Setup pixi
3030
uses: prefix-dev/setup-pixi@19eac09b398e3d0c747adc7921926a6d802df4da # v0.8.8
3131

32-
- name: Build executed notebooks and HTML
32+
- name: Build HTML
3333
run: pixi run build
3434

35+
- name: Build jupyterlite
36+
run: pixi run build_wasm
37+
3538
- name: Upload executed notebooks as GitHub artifact (for debugging)
3639
uses: actions/upload-artifact@v4
3740
with:

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@ jobs:
100100

101101
- name: Build static site
102102
run: pixi run build
103+
104+
pixi_build_wasm:
105+
name: Build jupyterlite site with pixi
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- name: Setup pixi
111+
uses: prefix-dev/setup-pixi@v0.8.1
112+
113+
- name: Build jupyterlite site
114+
run: pixi run build_wasm

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ _build/*
55
# No .ipynb files should be stored in this repository.
66
*.ipynb
77

8+
# Jupyterlite Database
9+
.jupyterlite.doit.db
10+
811
# We treat this repository as a library, not an application, and thus we do not
912
# include the lockfile in source control. For a specific event, like a
1013
# workshop, we suggest committing the lockfile on a branch dedicated to the

activate.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
mkdir -p ${CONDA_PREFIX}/share/jupyter/lab/settings
6+
cp ${PIXI_PROJECT_ROOT}/.binder/overrides.json ${CONDA_PREFIX}/share/jupyter/lab/settings/overrides.json

convert_all_jupyterlite.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# This is a script which copies the contents of the tutorials
4+
# directory into a build directory (_build/ipynbs).
5+
# The notebook markdown files are converted to ipynbs with other
6+
# files (non-executable md files, static images, etc) are copied
7+
# directly.
8+
# This is intended for jupyterlite to build pointing to the build
9+
# directory since the markdown files do not currently work in
10+
# jupyterlite.
11+
12+
# Find Markdown files convert.
13+
files_to_process=$(find tutorials -type f)
14+
15+
OUTDIR="_build/ipynbs"
16+
17+
# Identify Markdown files that are Jupytext and convert them all.
18+
for file in ${files_to_process}; do
19+
# Ensure result directory exists
20+
echo "Making directory: $OUTDIR/$(dirname $file)"
21+
mkdir -p $OUTDIR/$(dirname $file)
22+
23+
echo loop in $file
24+
# Extract the kernel information from the Jupytext Markdown file.
25+
kernel_info=$(grep -A 10 '^---$' "$file" | grep -E 'kernelspec')
26+
# Copy directly if not a notebook file
27+
if [ -z "$kernel_info" ]; then
28+
cp $file $OUTDIR/$file
29+
continue
30+
fi
31+
# Convert to ipynb format, to be consumed by pytest nbval plugin.
32+
notebook_file="${file%.md}.ipynb"
33+
jupytext --to ipynb "$file" --output $OUTDIR/${notebook_file}
34+
done

pixi.toml

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ authors = [
55
"Ross Barnowski <rossbar@caltech.edu>",
66
"Kyle Sunden <git@ksunden.space>",
77
]
8-
channels = ["conda-forge"]
8+
channels = ["https://repo.mamba.pm/emscripten-forge", "conda-forge"]
99
description = "Add a short description here"
1010
name = "executable-tutorials"
11-
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
11+
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64", "emscripten-wasm32"]
1212
version = "0.1.0"
1313

14-
[tasks]
14+
[feature.base]
15+
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
16+
17+
[feature.base.tasks]
1518
build = { cmd = [
1619
"sphinx-build",
1720
".", # source directory
@@ -25,22 +28,23 @@ clean = "rm -rf _build/*"
2528
start = "jupyter lab --FileContentsManager.preferred_dir tutorials"
2629
test = "bash ./test.sh"
2730

28-
[activation]
31+
[feature.base.activation]
2932
# Workaround overrides JupyterLab configuration (at the environment level) to
3033
# make double-clicking on a Jupytext Markdown file open that file as a
3134
# notebook. This is important for the development workflow for contributors.
32-
scripts = ["bash .binder/postBuild"]
35+
scripts = ["activate.sh"]
3336

34-
[dependencies]
37+
[feature.base.dependencies]
3538
python = ">=3.11"
3639
matplotlib-base = ">=3.9"
37-
ipympl = ">=0.9"
3840
jupyterlab = ">=4.2"
3941
jupyterlab-myst = ">=2.4"
4042
pytest = ">=8.3.5,<9"
4143
nbval = ">=0.11.0,<0.12"
44+
jupytext = ">=1.17.1,<2"
45+
ipympl = ">=0.9"
4246

43-
[pypi-dependencies]
47+
[feature.base.pypi-dependencies]
4448
sphinx = ">=8.0.2"
4549
myst-nb = ">=1.1"
4650
jupytext = ">=1.16"
@@ -49,19 +53,59 @@ sphinx-copybutton = ">=0.5"
4953
sphinx-design = "*"
5054
pytest-custom_exit_code = "*"
5155

56+
[feature.py312]
57+
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
58+
5259
[feature.py312.dependencies]
5360
python = "3.12.*"
5461

62+
[feature.py313]
63+
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
64+
5565
[feature.py313.dependencies]
5666
python = "3.13.*"
5767

58-
[feature.jupyterlite.dependencies]
68+
[feature.jupyterlite-runtime]
69+
channels = ["https://repo.mamba.pm/emscripten-forge", "conda-forge"]
70+
platforms = ["emscripten-wasm32"]
71+
72+
[feature.jupyterlite-runtime.dependencies]
73+
xeus-python = "*"
74+
python = ">=3.11"
75+
matplotlib = ">=3.9"
76+
ipympl = ">=0.9"
77+
jupytext = ">=1.16"
78+
79+
[feature.jupyterlite-host]
80+
channels = ["conda-forge"]
81+
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
82+
83+
[feature.jupyterlite-host.dependencies]
5984
jupyterlab = "~=4.2.4"
6085
jupyterlite-core = "==0.4.0"
61-
jupyterlite-pyodide-kernel = "==0.4.1"
86+
jupyterlite-xeus = "*"
6287
notebook = "~=7.2.1"
88+
jupyterlab-myst = ">=2.4"
89+
jupytext = ">=1.16"
90+
ipympl = ">=0.9"
91+
92+
[feature.jupyterlite-host.tasks]
93+
setup_wasm = {cmd = "pixi install -e jupyterlite-runtime", inputs = ["pixi.lock"]}
94+
convert_ipynbs = {cmd = "bash convert_all_jupyterlite.sh", inputs = ["tutorials/"], outputs = ["_build/ipynbs"]}
95+
96+
[feature.jupyterlite-host.tasks.build_wasm]
97+
cmd = "jupyter lite build --XeusAddon.prefix=.pixi/envs/jupyterlite-runtime --contents _build/ipynbs/tutorials --output-dir _build/html/jupyterlite --settings-overrides=.binder/overrides.json --log-level DEBUG"
98+
depends-on = ["setup_wasm", "convert_ipynbs"]
99+
outputs = ["_build/html/jupyterlite/"]
100+
inputs = ["pixi.lock", "tutorials/"]
101+
102+
[feature.jupyterlite-host.tasks.start_wasm]
103+
cmd = "python -m http.server 8000 -d _build/html/jupyterlite/"
104+
depends-on = ["build_wasm"]
63105

64106
[environments]
65-
py312 = ["py312"]
66-
py313 = ["py313"]
67-
jupyterlite = ["jupyterlite"]
107+
default = ["base"]
108+
py312 = ["base", "py312"]
109+
py313 = ["base", "py313"]
110+
jupyterlite-runtime = ["jupyterlite-runtime"]
111+
jupyterlite-host = ["jupyterlite-host"]

0 commit comments

Comments
 (0)