-
Notifications
You must be signed in to change notification settings - Fork 9
/
.run_notebooks.sh
62 lines (51 loc) · 1.5 KB
/
.run_notebooks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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."