diff --git a/.run_notebooks.sh b/.run_notebooks.sh new file mode 100644 index 000000000..4db60efb9 --- /dev/null +++ b/.run_notebooks.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Check if the base directory is provided as an argument +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Base directory for notebooks +base_dir=$1 + +# Define notebook directories or patterns +declare -a notebooks=( + "$base_dir/examples/plotting/*.ipynb" + "$base_dir/examples/problems/*.ipynb" + "$base_dir/examples/solvers/*.ipynb" +) + +# 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 moscot --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." diff --git a/pyproject.toml b/pyproject.toml index 84f8a9ccb..2622a31bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -306,8 +306,7 @@ extras = docs changedir = {tox_root}{/}docs commands = python -m ipykernel install --user --name=moscot - bash -c "for nb in notebooks/examples/plotting/*.ipynb notebooks/examples/problems/*ipynb notebooks/examples/solvers/*ipynb; do echo Running $nb; jupytext -k moscot --execute $nb; done" - + bash {tox_root}/.run_notebooks.sh {tox_root}{/}docs/notebooks [testenv:clean-docs] description = Remove the documentation.