2017-11-14 16:57:11 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
#
|
|
|
|
# This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
# General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
# directory for more details.
|
|
|
|
#
|
|
|
|
|
2018-04-05 09:40:31 +02:00
|
|
|
FLAKE8_CMD="python3 -m flake8"
|
|
|
|
|
2018-05-01 11:40:24 +02:00
|
|
|
if tput colors &> /dev/null && [ "$(tput colors)" -ge 8 ]; then
|
|
|
|
CERROR=$'\033[1;31m'
|
|
|
|
CRESET=$'\033[0m'
|
2017-11-14 16:57:11 +01:00
|
|
|
else
|
|
|
|
CERROR=
|
|
|
|
CRESET=
|
|
|
|
fi
|
|
|
|
|
2018-03-22 17:21:09 +01:00
|
|
|
: "${RIOTTOOLS:=${PWD}/dist/tools}"
|
|
|
|
. "${RIOTTOOLS}"/ci/changed_files.sh
|
2017-11-14 16:57:11 +01:00
|
|
|
|
2017-12-20 14:00:39 +01:00
|
|
|
FILES=$(FILEREGEX='(?=*.py$|pyterm$)' changed_files)
|
2017-11-14 16:57:11 +01:00
|
|
|
|
|
|
|
if [ -z "${FILES}" ]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-04-05 09:40:31 +02:00
|
|
|
${FLAKE8_CMD} --version &> /dev/null || {
|
2018-05-01 11:40:24 +02:00
|
|
|
printf "%s%s: cannot execute \"%s\"!%s\n" "${CERROR}" "$0" "${FLAKE8_CMD}" "${CRESET}"
|
2018-04-05 09:40:31 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:21:09 +01:00
|
|
|
ERRORS=$(${FLAKE8_CMD} --config="${RIOTTOOLS}"/flake8/flake8.cfg ${FILES})
|
2017-11-14 16:57:11 +01:00
|
|
|
|
|
|
|
if [ -n "${ERRORS}" ]
|
|
|
|
then
|
2018-05-01 11:40:24 +02:00
|
|
|
printf "%sThere are style issues in the following Python scripts:%s\n\n" "${CERROR}" "${CRESET}"
|
|
|
|
printf "%s\n" "${ERRORS}"
|
2017-11-14 16:57:11 +01:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|