|
a |
|
b/.run_notebooks.sh |
|
|
1 |
#!/bin/bash |
|
|
2 |
|
|
|
3 |
# Check if the base directory is provided as an argument |
|
|
4 |
if [ "$#" -ne 1 ]; then |
|
|
5 |
echo "Usage: $0 <base_notebook_directory>" |
|
|
6 |
exit 1 |
|
|
7 |
fi |
|
|
8 |
|
|
|
9 |
# Base directory for notebooks |
|
|
10 |
base_dir=$1 |
|
|
11 |
|
|
|
12 |
# Define notebook directories or patterns |
|
|
13 |
declare -a notebooks=( |
|
|
14 |
"$base_dir/examples/plotting/*.ipynb" |
|
|
15 |
"$base_dir/examples/problems/*.ipynb" |
|
|
16 |
"$base_dir/examples/solvers/*.ipynb" |
|
|
17 |
) |
|
|
18 |
|
|
|
19 |
# Initialize an array to hold valid notebook paths |
|
|
20 |
declare -a valid_notebooks |
|
|
21 |
|
|
|
22 |
# Gather all valid notebook files from the patterns |
|
|
23 |
echo "Gathering notebooks..." |
|
|
24 |
for pattern in "${notebooks[@]}"; do |
|
|
25 |
for nb in $pattern; do |
|
|
26 |
if [[ -f "$nb" ]]; then # Check if the file exists |
|
|
27 |
valid_notebooks+=("$nb") # Add to the list of valid notebooks |
|
|
28 |
fi |
|
|
29 |
done |
|
|
30 |
done |
|
|
31 |
|
|
|
32 |
# Check if we have any notebooks to run |
|
|
33 |
if [ ${#valid_notebooks[@]} -eq 0 ]; then |
|
|
34 |
echo "No notebooks found to run." |
|
|
35 |
exit 1 |
|
|
36 |
fi |
|
|
37 |
|
|
|
38 |
# Echo the notebooks that will be run for clarity |
|
|
39 |
echo "Preparing to run the following notebooks:" |
|
|
40 |
for nb in "${valid_notebooks[@]}"; do |
|
|
41 |
echo "$nb" |
|
|
42 |
done |
|
|
43 |
|
|
|
44 |
# Initialize a flag to track the success of all commands |
|
|
45 |
all_success=true |
|
|
46 |
|
|
|
47 |
# Execute all valid notebooks |
|
|
48 |
for nb in "${valid_notebooks[@]}"; do |
|
|
49 |
echo "Running $nb" |
|
|
50 |
jupytext -k moscot --execute "$nb" || { |
|
|
51 |
echo "Failed to run $nb" |
|
|
52 |
all_success=false |
|
|
53 |
} |
|
|
54 |
done |
|
|
55 |
|
|
|
56 |
# Check if any executions failed |
|
|
57 |
if [ "$all_success" = false ]; then |
|
|
58 |
echo "One or more notebooks failed to execute." |
|
|
59 |
exit 1 |
|
|
60 |
fi |
|
|
61 |
|
|
|
62 |
echo "All notebooks executed successfully." |