| 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | # This script is called in a binder context. When this script is called, we are |
| 6 | # inside a git checkout of the scikit-optimize/scikit-optimize repo. This script is |
| 7 | # generating notebooks from the scikit-optimize python examples. |
| 8 | |
| 9 | if [[ ! -f /.dockerenv ]]; then |
| 10 | echo "This script was written for repo2docker and is supposed to run inside a docker container." |
| 11 | echo "Exiting because this script can delete data if run outside of a docker container." |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | # Back up content we need from the scikit-learn repo |
| 16 | TMP_CONTENT_DIR=/tmp/scikit-learn |
| 17 | mkdir -p $TMP_CONTENT_DIR |
| 18 | cp -r examples .binder $TMP_CONTENT_DIR |
| 19 | # delete everything in current directory including dot files and dot folders |
| 20 | find . -delete |
| 21 | |
| 22 | # Generate notebooks and remove other files from examples folder |
| 23 | GENERATED_NOTEBOOKS_DIR=.generated-notebooks |
| 24 | cp -r $TMP_CONTENT_DIR/examples $GENERATED_NOTEBOOKS_DIR |
| 25 | rm $GENERATED_NOTEBOOKS_DIR/utils.py |
| 26 | |
| 27 | find $GENERATED_NOTEBOOKS_DIR -name '*.py' -exec sphx_glr_python_to_jupyter.py '{}' + |
| 28 | NON_NOTEBOOKS=$(find $GENERATED_NOTEBOOKS_DIR -type f | grep -v '\.ipynb') |
| 29 | rm -f $NON_NOTEBOOKS |
| 30 | |
| 31 | # Put the .binder folder back (may be useful for debugging purposes) |
| 32 | mv $TMP_CONTENT_DIR/.binder . |
| 33 | # Final clean up |
| 34 | rm -rf $TMP_CONTENT_DIR |
| 35 | |
| 36 | # This is for compatibility with binder sphinx-gallery integration: this makes |
| 37 | # sure that the binder links generated by sphinx-gallery are correct even tough |
| 38 | # the repo we use for binder (scikit-optimize/scikit-optimize) is not the repo of the |
| 39 | # generated doc (scikit-optimize/scikit-optimize.github.io) |
| 40 | mkdir notebooks |
| 41 | ln -s ../$GENERATED_NOTEBOOKS_DIR notebooks/auto_examples |