Skip to content

Commit

Permalink
Merge pull request #713 from theislab/fix/ci_examples_error
Browse files Browse the repository at this point in the history
Fix: CI examples not throwing error from some commands
  • Loading branch information
selmanozleyen authored Jun 17, 2024
2 parents 1277665 + f77fff8 commit 6d16acf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
62 changes: 62 additions & 0 deletions .run_notebooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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/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."
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6d16acf

Please sign in to comment.