Skip to content

Commit d64e68b

Browse files
committed
Add script to convert md files into ipynb for jupyterlite
1 parent ec9f315 commit d64e68b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

convert_all_jupyterlite.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Find Markdown files convert.
4+
all_markdown_files=$(find tutorials -type f)
5+
if [ $# -gt 0 ]; then
6+
files_to_process="$@"
7+
else
8+
files_to_process=$all_markdown_files
9+
fi
10+
11+
OUTDIR="_build/ipynbs"
12+
13+
# Identify Markdown files that are Jupytext and convert them all.
14+
for file in ${files_to_process}; do
15+
echo "Making directory: $OUTDIR/$(dirname $file)"
16+
mkdir -p $OUTDIR/$(dirname $file)
17+
18+
echo loop in $file
19+
# Extract the kernel information from the Jupytext Markdown file.
20+
kernel_info=$(grep -A 10 '^---$' "$file" | grep -E 'kernelspec')
21+
# Skip if no kernel information was found.
22+
if [ -z "$kernel_info" ]; then
23+
cp $file $OUTDIR/$file
24+
continue
25+
fi
26+
# Convert to ipynb format, to be consumed by pytest nbval plugin.
27+
notebook_file="${file%.md}.ipynb"
28+
jupytext --to ipynb "$file" --output $OUTDIR/${notebook_file}
29+
# Stash file in array to be cleaned up at the end.
30+
done

pixi.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ jupyterlab-myst = ">=2.4"
8989

9090
[feature.jupyterlite-host.tasks]
9191
setup_wasm = {cmd = "pixi install -e jupyterlite-runtime", inputs = ["pixi.lock"]}
92+
convert_ipynbs = {cmd = "bash convert_all_jupyterlite.sh", inputs = ["tutorials/"], outputs = ["_build/ipynbs"]}
9293

9394
[feature.jupyterlite-host.tasks.build_wasm]
94-
cmd = "jupyter lite build --XeusAddon.prefix=.pixi/envs/jupyterlite-runtime --contents tutorials --output-dir _build/html/jupyterlite --settings-overrides=.binder/overrides.json --log-level DEBUG"
95-
depends-on = ["setup_wasm"]
95+
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"
96+
depends-on = ["setup_wasm", "convert_ipynbs"]
9697
outputs = ["_build/html/jupyterlite/"]
9798
inputs = ["pixi.lock", "tutorials/"]
9899

0 commit comments

Comments
 (0)