Skip to content

Run notebooks in CI #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test notebooks

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ["3.11"]

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install pip dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test notebooks
env:
MPLBACKEND: agg
PLATFORM: ${{ matrix.os }}
DISPLAY: :42
run: |
tox -e examples-docs
64 changes: 64 additions & 0 deletions .run_notebooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Check if the base directory is provided as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <base_notebook_directory>"
exit 1
fi

# Base directory for notebooks
base_dir=$1

# Define notebook directories or patterns
declare -a notebooks=(
"$base_dir/examples/tools/*.ipynb"
"$base_dir/examples/plotting/*.ipynb"
"$base_dir/examples/image/*.ipynb"
"$base_dir/examples/graph/*.ipynb"
# "$base_dir/tutorials/*.ipynb" don't include because it contains many external modules
)

# Initialize an array to hold valid notebook paths
declare -a valid_notebooks

# Gather all valid notebook files from the patterns
echo "Gathering notebooks..."
for pattern in "${notebooks[@]}"; do
for nb in $pattern; do
if [[ -f "$nb" ]]; then # Check if the file exists
valid_notebooks+=("$nb") # Add to the list of valid notebooks
fi
done
done

# Check if we have any notebooks to run
if [ ${#valid_notebooks[@]} -eq 0 ]; then
echo "No notebooks found to run."
exit 1
fi

# Echo the notebooks that will be run for clarity
echo "Preparing to run the following notebooks:"
for nb in "${valid_notebooks[@]}"; do
echo "$nb"
done

# Initialize a flag to track the success of all commands
all_success=true

# Execute all valid notebooks
for nb in "${valid_notebooks[@]}"; do
echo "Running $nb"
jupytext -k squidpy --execute "$nb" || {
echo "Failed to run $nb"
all_success=false
}
done

# Check if any executions failed
if [ "$all_success" = false ]; then
echo "One or more notebooks failed to execute."
exit 1
fi

echo "All notebooks executed successfully."
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,22 @@ description = Download and cache data.
skip_install = false
deps =
commands = python ./.scripts/ci/download_data.py {posargs}



[testenv:examples-docs]
allowlist_externals = bash
description = Run the notebooks.
use_develop = true
deps =
ipykernel
jupytext
nbconvert
leidenalg
watermark
napari-spatialdata
extras = docs,neural
changedir = {tox_root}{/}docs
commands =
python -m ipykernel install --user --name=squidpy
bash {tox_root}/.run_notebooks.sh {tox_root}{/}docs/notebooks
Loading