efbfbf: upgrade to Bugs Everywhere Directory v1.5
[sawsim.git] / misc / hooks / pre-commit-pysawsim-check
1 #!/bin/sh
2
3 # Detect number of cores with Python >= 2.6.
4 # For Python 2.5, you'll have to hard-code the value (or sed /proc/cpuinfo ;).
5 CORES=$(python -c 'from multiprocessing import cpu_count; print cpu_count()' \
6     || exit 1)
7 #CORES=1
8
9 NOSE="nosetests -vv --with-doctest --doctest-tests --processes $CORES"
10
11 HAS_MPD=$(which mpdallexit 2>/dev/null)
12
13 if [ -n "$HAS_MPD" ]; then
14     echo "Running nosetests with $CORES processes via MPI."
15
16     LOCAL_MPD=''
17
18     mpdtrace >/dev/null 2>&1
19     if [ "$?" -ne 0 ]; then
20         LOCAL_MPD='1'
21         mpd &    # start an mpd instance
22         sleep 1  # give mpd some time to start up
23     fi           # otherwise there is an mpd instance already running
24
25     mpiexec -n 1 $NOSE pysawsim
26     RESULT="$?"
27
28     if [ -n "$LOCAL_MPD" ]; then
29         mpdallexit
30     fi
31
32     if [ "$RESULT" -ne 0 ]; then
33         exit 1;
34     fi
35
36 else  # no MPD
37     echo "Running nosetests with $CORES processes without MPI."
38
39     $NOSE pysawsim || exit 1
40
41 fi