Skip to content

Commit

Permalink
travis-build.sh: validate Jupyter notebooks
Browse files Browse the repository at this point in the history
This is a first attempt at Travis executing Jupyter notebooks,
when the jupyter tool is present in the environment.

If any notebooks have cell execution errors, the build should fail.

This will be useful e.g. for imagej/tutorials#53.
  • Loading branch information
ctrueden committed May 23, 2018
1 parent 29b60a6 commit 8794ec8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,29 @@ EOL
echo travis_fold:end:travis-build.sh-maven
fi

# Execute Jupyter notebooks.
if which jupyter >/dev/null 2>/dev/null
then
echo travis_fold:start:travis-build.sh-jupyter
echo "= Jupyter notebooks ="
# NB: This part is fiddly. We want to loop over files even with spaces,
# so we use the "find ... -print0 | while read $'\0' ..." idiom.
# However, that runs the piped expression in a subshell, which means
# that any updates to the success variable will not persist outside
# the loop. So we suppress all stdout inside the loop, echoing only
# the final value of success upon completion, and then capture the
# echoed value back into the parent shell's success variable.
success=$(find . -name '*.ipynb' -print0 | {
while read -d $'\0' nbf
do
echo 1>&2
echo "== $nbf ==" 1>&2
jupyter nbconvert --execute --stdout "$nbf" >/dev/null
checkSuccess $?
done
echo $success
})
echo travis_fold:end:travis-build.sh-jupyter
fi

exit $success

0 comments on commit 8794ec8

Please sign in to comment.