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-06-05 17:06:11 +02:00
|
|
|
: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
|
|
|
|
cd $RIOTBASE
|
|
|
|
|
|
|
|
: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
|
2018-03-22 17:21:09 +01:00
|
|
|
. "${RIOTTOOLS}"/ci/changed_files.sh
|
2017-11-14 16:57:11 +01:00
|
|
|
|
2019-07-02 13:37:00 +02:00
|
|
|
EXCLUDE="^(.+/vendor/\
|
|
|
|
|dist/tools/cc2538-bsl\
|
|
|
|
|dist/tools/mcuboot\
|
|
|
|
|dist/tools/uhcpd\
|
|
|
|
|dist/tools/stm32loader\
|
2020-06-29 15:42:47 +02:00
|
|
|
|dist/tools/suit/suit-manifest-generator)\
|
2019-10-25 11:47:30 +02:00
|
|
|
|dist/tools/esptool"
|
2018-06-05 15:21:26 +02:00
|
|
|
FILEREGEX='(\.py$|pyterm$)'
|
2018-06-05 15:22:07 +02:00
|
|
|
FILES=$(FILEREGEX=${FILEREGEX} EXCLUDE=${EXCLUDE} 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
|