|
1 | 1 | #!/bin/bash
|
2 | 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 | + |
3 | 12 | # 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 |
| 13 | +files_to_process=$(find tutorials -type f) |
10 | 14 |
|
11 | 15 | OUTDIR="_build/ipynbs"
|
12 | 16 |
|
13 | 17 | # Identify Markdown files that are Jupytext and convert them all.
|
14 | 18 | for file in ${files_to_process}; do
|
| 19 | + # Ensure result directory exists |
15 | 20 | echo "Making directory: $OUTDIR/$(dirname $file)"
|
16 | 21 | mkdir -p $OUTDIR/$(dirname $file)
|
17 | 22 |
|
18 | 23 | echo loop in $file
|
19 | 24 | # Extract the kernel information from the Jupytext Markdown file.
|
20 | 25 | kernel_info=$(grep -A 10 '^---$' "$file" | grep -E 'kernelspec')
|
21 |
| - # Skip if no kernel information was found. |
| 26 | + # Copy directly if not a notebook file |
22 | 27 | if [ -z "$kernel_info" ]; then
|
23 | 28 | cp $file $OUTDIR/$file
|
24 | 29 | continue
|
25 | 30 | fi
|
26 | 31 | # Convert to ipynb format, to be consumed by pytest nbval plugin.
|
27 | 32 | notebook_file="${file%.md}.ipynb"
|
28 | 33 | jupytext --to ipynb "$file" --output $OUTDIR/${notebook_file}
|
29 |
| - # Stash file in array to be cleaned up at the end. |
30 | 34 | done
|
0 commit comments