#!/bin/sh
# run static code checks like pyflakes and pep8
set -eu

if ! which pyflakes >/dev/null 2>&1; then
    echo "1..1"
    echo "ok 1 # SKIP pyflakes not installed"
    exit 0
fi

echo "1..2"

cd "${srcdir:-.}"

#
# pyflakes
#

pyflakes pkg/docker/cockpit-atomic-storage tools/build-debian-copyright
echo "ok 1 pkg/docker/cockpit-atomic-storage tools/build-debian-copyright"

# we don't dist bots, so only check it when running in git
[ -d bots ] &&  BOTS="bots/" || BOTS=

# TODO: there are currently a lot of pyflakes errors like
#   'parent' imported but unused
#   'from testlib import *' used; unable to detect undefined names
# Filter these out until these get fixed properly.
out=$(pyflakes $BOTS test/ test/verify/check-* 2>&1 | grep -Ev "(unable to detect undefined names|defined from star imports|'parent' imported but unused)") || true
if [ -n "$out" ]; then
    echo "ERROR: pyflakes"
    echo "$out"
    exit 1
fi
echo "ok 2 pyflakes"
