From a42b60538e9eb50edd7cc4ac3ffb148a32e6b4aa Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Fri, 26 Sep 2025 10:09:05 +0200 Subject: [PATCH 1/3] [DOC] add binder --- .binder/postBuild | 43 ++++++++++++++++++++++++++++++ .binder/requirements.txt | 2 ++ .binder/runtime.txt | 1 + docs/tools/binder/requirements.txt | 5 ++++ docs/tools/conf.py | 11 ++++++++ 5 files changed, 62 insertions(+) create mode 100755 .binder/postBuild create mode 100644 .binder/requirements.txt create mode 100644 .binder/runtime.txt create mode 100644 docs/tools/binder/requirements.txt 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..1f03d1ad3 --- /dev/null +++ b/.binder/runtime.txt @@ -0,0 +1 @@ +python - 3.10 diff --git a/docs/tools/binder/requirements.txt b/docs/tools/binder/requirements.txt new file mode 100644 index 000000000..92bee596d --- /dev/null +++ b/docs/tools/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, + }, } From daa7c33a58c3c34e40e84a009ab2ee403cb9142f Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Fri, 26 Sep 2025 10:26:38 +0200 Subject: [PATCH 2/3] mv --- docs/{tools => src}/binder/requirements.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{tools => src}/binder/requirements.txt (100%) diff --git a/docs/tools/binder/requirements.txt b/docs/src/binder/requirements.txt similarity index 100% rename from docs/tools/binder/requirements.txt rename to docs/src/binder/requirements.txt From 405906649c65f5e118096b741b26815c0b5fbead Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Thu, 2 Oct 2025 10:18:37 +0200 Subject: [PATCH 3/3] Update .binder/runtime.txt Co-authored-by: lionel kusch --- .binder/runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.binder/runtime.txt b/.binder/runtime.txt index 1f03d1ad3..62bcfd2a1 100644 --- a/.binder/runtime.txt +++ b/.binder/runtime.txt @@ -1 +1 @@ -python - 3.10 +python - 3.12