From cde171af0f277cfe82ee57cbb71a2e958975d2e0 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 17 Nov 2017 17:19:06 +0100 Subject: [PATCH 1/2] travis: add flake8 dependency --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index df87e00dd4..52f1bb7a6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ dist: trusty before_install: - - sudo apt-get install coreutils realpath doxygen graphviz python-lesscpy cppcheck coccinelle pcregrep + - sudo apt-get install coreutils realpath doxygen graphviz python-lesscpy cppcheck coccinelle pcregrep python3-flake8 script: - make static-test From 035bdf7dcb8ce36baf843f1ab83b972a5749ba52 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 14 Nov 2017 16:57:11 +0100 Subject: [PATCH 2/2] dist/tools: add PEP8 check to static tests --- dist/tools/ci/build_and_test.sh | 1 + dist/tools/flake8/check.sh | 38 +++++++++++++++++++++++++++++++++ dist/tools/flake8/flake8.cfg | 3 +++ 3 files changed, 42 insertions(+) create mode 100755 dist/tools/flake8/check.sh create mode 100644 dist/tools/flake8/flake8.cfg diff --git a/dist/tools/ci/build_and_test.sh b/dist/tools/ci/build_and_test.sh index c69f6e5e85..9c376320d6 100755 --- a/dist/tools/ci/build_and_test.sh +++ b/dist/tools/ci/build_and_test.sh @@ -91,6 +91,7 @@ then run ./dist/tools/cppcheck/check.sh run ./dist/tools/pr_check/pr_check.sh ${CI_BASE_BRANCH} run ./dist/tools/coccinelle/check.sh + run ./dist/tools/flake8/check.sh QUIET=1 run ./dist/tools/headerguards/check.sh exit $RESULT fi diff --git a/dist/tools/flake8/check.sh b/dist/tools/flake8/check.sh new file mode 100755 index 0000000000..46edc4a1f0 --- /dev/null +++ b/dist/tools/flake8/check.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2017 Alexandre Abadie +# +# 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. +# + +if tput colors &> /dev/null && [ $(tput colors) -ge 8 ]; then + CERROR="\e[1;31m" + CRESET="\e[0m" +else + CERROR= + CRESET= +fi + +DIST_TOOLS=${RIOTBASE:-.}/dist/tools + +. ${DIST_TOOLS}/ci/changed_files.sh + +FILES=$(FILEREGEX='*.py$' changed_files) + +if [ -z "${FILES}" ] +then + exit 0 +fi + +ERRORS=$(flake8 --config=${DIST_TOOLS}/flake8/flake8.cfg ${FILES}) + +if [ -n "${ERRORS}" ] +then + printf "${CERROR}There are style issues in the following Python scripts:${CRESET}\n\n" + printf "${ERRORS}\n" + exit 1 +else + exit 0 +fi diff --git a/dist/tools/flake8/flake8.cfg b/dist/tools/flake8/flake8.cfg new file mode 100644 index 0000000000..478a0be8ff --- /dev/null +++ b/dist/tools/flake8/flake8.cfg @@ -0,0 +1,3 @@ +[flake8] +# Allow 119 characters width per line to simplify test output parsing +max-line-length = 119