forked from AstarVienna/ScopeSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runnotebooks.sh
executable file
·47 lines (38 loc) · 1.33 KB
/
runnotebooks.sh
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
#!/usr/bin/env bash
if [[ "x${1}" == "x--clone-irdb" ]] ; then
# Cloning IRDB
if [[ ! -e irdb ]] ; then
git clone https://github.com/AstarVienna/irdb.git
fi
# https://github.com/koalaman/shellcheck/wiki/SC2044
find . -iname "*.ipynb" -printf '%h\0' | sort -z | uniq -z | while IFS= read -r -d '' dirnotebooks; do
echo "${dirnotebooks}"
dirinstpkgs="${dirnotebooks}/inst_pkgs"
if [[ (! -e ./docs/source/examples/inst_pkgs) && (! -L ./docs/source/examples/inst_pkgs) ]] ; then
echo "Creating symlink to irdb: ${dirinstpkgs}"
ln -s irdb "${dirinstpkgs}"
else
echo "Directory exists, not creating symlink: ${dirinstpkgs}"
fi
# Comment out any download_package[s] in the notebooks.
pusd "${dirnotebooks}" || exit 1
sed -i -E 's|"(.*\.download_package)|"#\1|g' -- *.ipynb
popd || exit 1
done
fi
# https://github.com/koalaman/shellcheck/wiki/SC2044
find . -iname "*.ipynb" -print0 | while IFS= read -r -d '' fnnotebook
do
echo "Testing ${fnnotebook}"
fnpy="${fnnotebook%.ipynb}.py"
# Convert .ipynb file to .py.
jupytext --to py "${fnnotebook}"
# Run the python script and quit on first error.
python "${fnpy}" || exit 1
# Delete generated files if --delete is specified.
# By default do not delete any files.
if [ "x$1" = "x--delete" ]
then
rm "${fnpy}"
fi
done