-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun-examples
executable file
·67 lines (48 loc) · 1.53 KB
/
run-examples
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
63
64
65
66
#!/usr/bin/env bash
# Runs all Python examples in `examples/` directory
# Dependencies:
# sudo apt-get install parallel
# pip3 install biopython matplotlib numpy pandas pygments scipy
set -euo pipefail
trap 'echo 🟦 Cancelled; exit 0' INT
SKIP_SLOW=0
case "${1:-}" in
"--skip-slow")
shift
SKIP_SLOW=1
;;
esac
export SKIP_SLOW
function run_example() {
set -euo pipefail
example=$(basename -- "${1}")
# List of examples that are slow to run. We skip them in CI.
slow_examples=( \
"benefits_of_sex.py" \
"genealogies_with_selection.py" \
"measuring_fixation_probabilities.py" \
"multi_sample_adaptive.py" \
"mutation_selection_balance_highd.py" \
"neutral_LD_highd.py" \
"speed_highd.py" \
"speed_lowd.py" \
)
printf '%s\n' '--------------------------------------------------------'
printf '\n⬜ BEGIN "%s"\n' "${example}"
if [ "${SKIP_SLOW}" == "1" ] && [[ " ${slow_examples[*]} " =~ ${example} ]]; then
echo "Skipping slow example '${example}' due to '--skip-slow' argument"
return 0
fi
pushd "examples/" >/dev/null
if (python3 "${example}" 2>&1 1>/dev/null | pygmentize -l pytb -O style=material); then
printf '🟩 SUCCESS "%s"\n\n\n' "${example}"
return 0
else
printf '\n🟥 FAILURE "%s"\n\n\n' "${example}"
return 1
fi
popd >/dev/null
}
export -f run_example
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
find "examples/" -maxdepth 1 -type f -iname '*.py' | sort | parallel -j "${JOBS}" run_example