Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .binder/postBuild
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.[example]
sphinx-gallery
1 change: 1 addition & 0 deletions .binder/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python - 3.10
5 changes: 5 additions & 0 deletions docs/src/binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions docs/tools/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
}


Expand Down
Loading