#!/bin/bash
set -e

echo "= pycodestyle ="

command -v pycodestyle >/dev/null 2>&1 || {
  echo >&2 "I require pycodestyle but it's not installed.  Aborting.";
  echo >&2 "$ virtualenv -p python3 venv";
  echo >&2 "$ . venv/bin/activate";
  echo >&2 "$ pip install pycodestyle";
  exit 1;
}
for i in $(find . -not -path "./.pc/*" -not -path "./debian/patches/*" -type f -exec grep -l "env python3" {} \;); do
    if [[ $i != *pep8 && $i != *meson* && $i != *venv* ]]; then
        echo "checking $i"
        pycodestyle --ignore W191 --ignore E402 $i
    fi
done

for i in $(find . -not -path "./.pc/*" -not -path "./debian/patches/*" -type f -iname '*.py'); do
    if [[ $i != *venv* ]]; then
        echo "checking $i:"
        pycodestyle --ignore W191 --ignore E402 $i
    fi
done
