diff --git a/.binder/postBuild b/.binder/postBuild new file mode 100755 index 000000000..9b7b26cc7 --- /dev/null +++ b/.binder/postBuild @@ -0,0 +1,43 @@ +#!/bin/bash + +# Adapted from scikit-learn +# https://github.com/scikit-learn/scikit-learn/blob/main/.binder/ + +set -e + +# This script is called in a binder context. When this script is called, we are +# inside a git checkout of the nilearn/nilearn repo. This script is +# generating notebooks from the nilearn python examples. + +if [[ -z "${REPO_DIR}" ]]; then + echo "This script was written for repo2docker and the REPO_DIR environment variable is supposed to be set." + echo "Exiting because this script can delete data if run outside of a repo2docker context." + exit 1 +fi + +# Back up content we need from the nilearn repo +TMP_CONTENT_DIR=/tmp/hidimstat +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=.generated-notebooks +cp -r $TMP_CONTENT_DIR/examples $GENERATED_NOTEBOOKS_DIR + +find $GENERATED_NOTEBOOKS_DIR -name '*.py' -exec sphinx_gallery_py2jupyter '{}' + +NON_NOTEBOOKS=$(find $GENERATED_NOTEBOOKS_DIR -type f | grep -v '\.ipynb') +rm -f $NON_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 + +# This is for compatibility with binder sphinx-gallery integration: this makes +# sure that the binder links generated by sphinx-gallery are correct even tough +# the repo we use for binder (nilearn/nilearn) is not the repo of the +# generated doc (nilearn/nilearn.github.io) +mkdir notebooks +ln -s ../$GENERATED_NOTEBOOKS_DIR notebooks/auto_examples diff --git a/.binder/requirements.txt b/.binder/requirements.txt new file mode 100644 index 000000000..81f914faf --- /dev/null +++ b/.binder/requirements.txt @@ -0,0 +1,2 @@ +.[example] +sphinx-gallery diff --git a/.binder/runtime.txt b/.binder/runtime.txt new file mode 100644 index 000000000..62bcfd2a1 --- /dev/null +++ b/.binder/runtime.txt @@ -0,0 +1 @@ +python - 3.12 diff --git a/docs/src/binder/requirements.txt b/docs/src/binder/requirements.txt new file mode 100644 index 000000000..92bee596d --- /dev/null +++ b/docs/src/binder/requirements.txt @@ -0,0 +1,5 @@ +# A binder requirement file is required by sphinx-gallery. +# We don't really need one since our binder requirement file lives in the +# .binder directory. +# This file can be removed if 'dependencies' is made an optional key for +# binder in sphinx-gallery. diff --git a/docs/tools/conf.py b/docs/tools/conf.py index 9369a4553..eeadce3ab 100644 --- a/docs/tools/conf.py +++ b/docs/tools/conf.py @@ -124,6 +124,9 @@ "show-inheritance": True, } +# -- Options for binder ---------------------------------------------------- +binder_branch = "main" if "dev" in __version__ else __version__ + # -- Options for gallery ---------------------------------------------------- # Generate the plots for the gallery @@ -146,6 +149,14 @@ # We don't specify the other modules as we use the intershpinx ext. # See https://sphinx-gallery.github.io/stable/configuration.html#link-to-documentation # noqa }, + "binder": { + "org": "mind-inria", + "repo": "hidimstat", + "binderhub_url": "https://mybinder.org", + "branch": binder_branch, + "dependencies": "./binder/requirements.txt", + "use_jupyter_lab": True, + }, }