77 lines
1.6 KiB
Bash
Executable file
77 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
QUIET_ARG=""
|
|
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
|
|
;;
|
|
*)
|
|
usage "Unkown parameter '$OPT'"
|
|
esac
|
|
let idx=idx+1
|
|
done
|
|
[ "$1" == "--quiet" ] && QUIET_ARG="--quiet"
|
|
|
|
# Enter source directory
|
|
cd $( dirname $0 )
|
|
|
|
TEMP_VENV=0
|
|
VENV=""
|
|
if [ $NO_VENV -eq 1 ]
|
|
then
|
|
echo "Run tests in system environment..."
|
|
elif [ -d venv ]
|
|
then
|
|
VENV=$( realpath venv )
|
|
echo "Using existing virtualenv ($VENV)..."
|
|
else
|
|
# Create a temporary venv
|
|
VENV=$(mktemp -d)
|
|
echo "Create a temporary virtualenv in $VENV..."
|
|
TEMP_VENV=1
|
|
python3 -m venv $VENV
|
|
fi
|
|
|
|
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
|
|
|
|
# Run pre-commit
|
|
RES=0
|
|
echo "Run pre-commit..."
|
|
pre-commit run --all-files
|
|
[ $? -ne 0 ] && RES=1
|
|
|
|
# Clean temporary venv
|
|
[ $TEMP_VENV -eq 1 ] && rm -fr $VENV
|
|
|
|
exit $RES
|