2022-04-27 18:02:54 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
QUIET_ARG=""
|
2023-01-16 13:24:19 +01:00
|
|
|
NO_VENV=0
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
[ -n "$1" ] && echo -e "$1\n" > /dev/stderr
|
|
|
|
echo "Usage: $0 [-x] [-q|--quiet] [--no-venv]"
|
|
|
|
echo " -h/--help Show usage message"
|
|
|
|
echo " -q/--quiet Enable quiet mode"
|
|
|
|
echo " -n/--no-venv Disable venv creation and run tests on system environment"
|
|
|
|
echo " -x Enable debug mode"
|
|
|
|
[ -n "$1" ] && exit 1
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
idx=1
|
|
|
|
while [ $idx -le $# ]
|
|
|
|
do
|
|
|
|
OPT=${!idx}
|
|
|
|
case $OPT in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
-q|--quiet)
|
|
|
|
QUIET_ARG="--quiet"
|
|
|
|
;;
|
|
|
|
-n|--no-venv)
|
|
|
|
NO_VENV=1
|
|
|
|
;;
|
|
|
|
-x)
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
*)
|
2024-03-15 09:52:23 +01:00
|
|
|
usage "Unknown parameter '$OPT'"
|
2023-01-16 13:24:19 +01:00
|
|
|
esac
|
|
|
|
let idx=idx+1
|
|
|
|
done
|
2022-04-27 18:56:03 +02:00
|
|
|
[ "$1" == "--quiet" ] && QUIET_ARG="--quiet"
|
|
|
|
|
2022-04-27 18:02:54 +02:00
|
|
|
# Enter source directory
|
|
|
|
cd $( dirname $0 )
|
|
|
|
|
2023-01-16 13:24:19 +01:00
|
|
|
TEMP_VENV=0
|
|
|
|
VENV=""
|
|
|
|
if [ $NO_VENV -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "Run tests in system environment..."
|
|
|
|
elif [ -d venv ]
|
2022-04-27 18:02:54 +02:00
|
|
|
then
|
2023-01-16 13:24:19 +01:00
|
|
|
VENV=$( realpath venv )
|
|
|
|
echo "Using existing virtualenv ($VENV)..."
|
2022-04-27 18:02:54 +02:00
|
|
|
else
|
2023-01-16 13:24:19 +01:00
|
|
|
# Create a temporary venv
|
|
|
|
VENV=$(mktemp -d)
|
|
|
|
echo "Create a temporary virtualenv in $VENV..."
|
|
|
|
TEMP_VENV=1
|
|
|
|
python3 -m venv $VENV
|
2022-04-27 18:02:54 +02:00
|
|
|
fi
|
|
|
|
|
2023-01-16 13:24:19 +01:00
|
|
|
if [ -n "$VENV" ]
|
|
|
|
then
|
|
|
|
echo "Install package with dev dependencies using pip in virtualenv..."
|
|
|
|
$VENV/bin/python3 -m pip install -e ".[dev]" $QUIET_ARG
|
|
|
|
source $VENV/bin/activate
|
|
|
|
fi
|
2023-01-06 22:18:46 +01:00
|
|
|
|
2023-01-16 12:56:12 +01:00
|
|
|
# Run pre-commit
|
2023-01-16 13:37:53 +01:00
|
|
|
RES=0
|
2023-01-16 12:56:12 +01:00
|
|
|
echo "Run pre-commit..."
|
|
|
|
pre-commit run --all-files
|
2023-01-06 22:18:46 +01:00
|
|
|
[ $? -ne 0 ] && RES=1
|
2022-04-27 18:02:54 +02:00
|
|
|
|
|
|
|
# Clean temporary venv
|
|
|
|
[ $TEMP_VENV -eq 1 ] && rm -fr $VENV
|
|
|
|
|
|
|
|
exit $RES
|