forked from TuringLang/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-example.bash
68 lines (52 loc) · 1.96 KB
/
render-example.bash
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/bash
if [ ! -d "./env" ]; then
echo "Virtual environment doesn't exist, creating one"
# Install virtualenv
python3 -m pip install --user virtualenv
# Create a new environment
python3 -m venv env
# Activate the environment
source env/bin/activate
# Install needed packages
pip install jupyter
fi
# check to see if the markdown directory exists
if [ ! -d "./markdown" ]; then
mkdir markdown
fi
# Activate the environment
source env/bin/activate
for filename in *.ipynb; do
ipyAge=$(stat -c %Y -- "$filename")
outPath="markdown/${filename/.ipynb/.md}"
if [ -f $outPath ]; then
mdAge=$(stat -c %Y -- $outPath)
mdExists=0
else
mdAge=0
mdExists=0
fi
if [ $mdExists -ne 0 ] || (( $ipyAge > $mdAge )); then
echo "$filename needs to be reconverted as it has been updated."
# Update the notebook itself by executing everything.
env/bin/jupyter-nbconvert "$filename" --to notebook --inplace --ExecutePreprocessor.kernel_name="julia-1.4" --execute --ExecutePreprocessor.timeout=-1 --ExecutePreprocessor.startup_timeout=120
# Capture the exit code.
retVal=$?
# Check if we ran the notebook without issues.
if [ $retVal -ne 0 ]; then
# We had an error code -- terminate early.
# Note: Remove this line if you want to run all the notebooks and ignore
# any errors that might appear.
echo "Error converting $filename"
# Return the error code we got.
# exit $retVal
else
# No errors happened, so we can convert the notebook to markdown.
echo "Converting $filename to $outPath"
env/bin/jupyter-nbconvert "$filename" --to markdown --output-dir="markdown"
echo "Adding YAML headers to $outpath"
julia -e "include(\"weave-examples.jl\"); handle_file(\"$outPath\")"
fi
fi
done
# exit 0