| 1 | #!/bin/bashscip-shell filesystem . . `/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 | echoscip-shell system . . echo. "This script was written for repo2docker and is supposed to run inside a docker container." |
| 11 | echoscip-shell system . . 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-learnscip-shell filesystem . . `/tmp/scikit-learn`. |
| 17 | mkdirscip-shell system . . mkdir. -p $TMP_CONTENT_DIR |
| 18 | cpscip-shell system . . cp. -r examples .binder $TMP_CONTENT_DIR |
| 19 | # delete everything in current directory including dot files and dot folders |
| 20 | findscip-shell system . . find. . -delete |
| 21 | |
| 22 | # Generate notebooks and remove other files from examples folder |
| 23 | GENERATED_NOTEBOOKS_DIR=.generated-notebooks |
| 24 | cpscip-shell system . . cp. -r $TMP_CONTENT_DIR/examples $GENERATED_NOTEBOOKS_DIR |
| 25 | rmscip-shell system . . rm. $GENERATED_NOTEBOOKS_DIR/utils.py |
| 26 | |
| 27 | findscip-shell system . . find. $GENERATED_NOTEBOOKS_DIR -name '*.py' -exec sphx_glr_python_to_jupyter.py '{}' + |
| 28 | NON_NOTEBOOKS=$(findscip-shell system . . find. $GENERATED_NOTEBOOKS_DIR -type f | grepscip-shell system . . grep. -v '\.ipynb') |
| 29 | rmscip-shell system . . rm. -f $NON_NOTEBOOKS |
| 30 | |
| 31 | # Put the .binder folder back (may be useful for debugging purposes) |
| 32 | mvscip-shell system . . mv. $TMP_CONTENT_DIR/.binder . |
| 33 | # Final clean up |
| 34 | rmscip-shell system . . 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 | mkdirscip-shell system . . mkdir. notebooks |
| 41 | lnscip-shell system . . ln. -s ../$GENERATED_NOTEBOOKS_DIR notebooks/auto_examples |