[ci] Check python files with flake8
# Author: Samuel Riedel, ETH Zurich
+# Execute from git's root dir
+cd $(git rev-parse --show-toplevel 2>/dev/null)
if [[ -n "$CI_MERGE_REQUEST_ID" ]]; then
# Make sure we have the latest version of the target branch
@@ -35,13 +37,14 @@ EXIT_STATUS=0
# Only check files that still exist
files=$(echo "$files" | xargs ls -d 2>/dev/null)
+# Remove files from dependencies
+files=$(echo "$files" | grep -vP "hardware/deps/")
+files=$(echo "$files" | grep -vP "toolchain/")
+files=$(echo "$files" | grep -vP "be/")
+
# Only check C and C++ files for clang-format compatibility
echo "Checking C/C++ files for clang-format compliance"
clang_files=$(echo "$files" | grep -P "(?<!\.ld)\.(h|c|cpp)\b")
-# Remove files from dependencies
-clang_files=$(echo "$clang_files" | grep -vP "hardware/deps/")
-clang_files=$(echo "$clang_files" | grep -vP "toolchain/")
-clang_files=$(echo "$clang_files" | grep -vP "be/")
for file in $clang_files; do
echo $file
./.gitlab-ci.d/run_clang_format.py \
@@ -49,6 +52,21 @@ for file in $clang_files; do
$file || EXIT_STATUS=$?
done
+# Only check python files for flake8 compatibility
+if [[ -n "$GITLAB_CI" ]]; then
+ # Special case for gitlab ci, since it has an old default python
+ python3=$(command -v python3.6) || EXIT_STATUS=$?
+else
+ python3=$(command -v python3) || EXIT_STATUS=$?
+fi
+
+echo "Checking python files for flake8 compliance"
+py_files=$(echo "$files" | grep -P "\.(py)\b")
+for file in $py_files; do
+ echo $file
+ $python3 -m flake8 $file || EXIT_STATUS=$?
+done
+
# Check for trailing whitespaces and tabs
echo "Checking for trailing whitespaces and tabs"
git diff --check $base HEAD -- \
