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