diff --git a/.binder/apt.txt b/.binder/apt.txt new file mode 100644 index 000000000..f0a795a24 --- /dev/null +++ b/.binder/apt.txt @@ -0,0 +1,2 @@ +build-essential +swig \ No newline at end of file diff --git a/.binder/postBuild b/.binder/postBuild new file mode 100644 index 000000000..311cee591 --- /dev/null +++ b/.binder/postBuild @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +python -m pip install -e .[dev] + +# Taken from https://github.com/scikit-learn/scikit-learn/blob/22cd233e1932457947e9994285dc7fd4e93881e4/.binder/postBuild +# under BSD3 license, copyright the scikit-learn contributors + +# This script is called in a binder context. When this script is called, we are +# inside a git checkout of the automl/SMAC3 repo. This script +# generates notebooks from the SMAC3 python examples. + +if [[ ! -f /.dockerenv ]]; then + echo "This script was written for repo2docker and is supposed to run inside a docker container." + echo "Exiting because this script can delete data if run outside of a docker container." + exit 1 +fi + +# Copy content we need from the SMAC3 repo +TMP_CONTENT_DIR=/tmp/SMAC3 +mkdir -p $TMP_CONTENT_DIR +cp -r examples .binder $TMP_CONTENT_DIR +# delete everything in current directory including dot files and dot folders +find . -delete + +# Generate notebooks and remove other files from examples folder +GENERATED_NOTEBOOKS_DIR=examples +cp -r $TMP_CONTENT_DIR/examples $GENERATED_NOTEBOOKS_DIR + +find $GENERATED_NOTEBOOKS_DIR -name 'example_*.py' -exec sphx_glr_python_to_jupyter.py '{}' + +# Keep __init__.py and custom_metrics.py +NON_NOTEBOOKS=$(find $GENERATED_NOTEBOOKS_DIR -type f | grep -v '\.ipynb' | grep -v 'init' | grep -v 'custom_metrics') +rm -f $NON_NOTEBOOKS + +# Modify path to be consistent by the path given by sphinx-gallery +mkdir notebooks +mv $GENERATED_NOTEBOOKS_DIR notebooks/ + +# Put the .binder folder back (may be useful for debugging purposes) +mv $TMP_CONTENT_DIR/.binder . +# Final clean up +rm -rf $TMP_CONTENT_DIR diff --git a/.binder/requirements.txt b/.binder/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/docs/conf.py b/docs/conf.py index 3d57d1546..a849c7f56 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,6 +27,19 @@ "plot_gallery": True, "within_subsection_order": FileNameSortKey, "filename_pattern": "/", # We want to execute all files in `examples` + "binder": { + # Required keys + "org": "automl", + "repo": "SMAC3", + "branch": "main", + "binderhub_url": "https://mybinder.org", + "dependencies": ["../.binder/apt.txt", "../.binder/requirements.txt"], + # "filepath_prefix": "" # A prefix to prepend to any filepaths in Binder links. + # Jupyter notebooks for Binder will be copied to this directory (relative to built documentation root). + "notebooks_dir": "notebooks/", + "use_jupyter_lab": True, + # Whether Binder links should start Jupyter Lab instead of the Jupyter Notebook interface. + }, "ignore_pattern": ".*7_parallelization_cluster.py$", }, }