diff --git a/config.sh.in b/config.sh.in index c777f096c..02100f703 100644 --- a/config.sh.in +++ b/config.sh.in @@ -20,3 +20,4 @@ # mostly used in other shell scripts. export XMLLINT="@XMLLINT@" +export PYCODESTYLE="@PYCODESTYLE@" diff --git a/m4/guestfs-python.m4 b/m4/guestfs-python.m4 index ac857915f..505eba5df 100644 --- a/m4/guestfs-python.m4 +++ b/m4/guestfs-python.m4 @@ -86,6 +86,9 @@ AS_IF([test "x$enable_python" != "xno"],[ PYTHON_EXT_SUFFIX=$python_ext_suffix fi AC_MSG_RESULT([$PYTHON_EXT_SUFFIX]) + + AC_CHECK_PROGS([PYCODESTYLE],[pycodestyle],[no]) + AM_CONDITIONAL([HAVE_PYCODESTYLE], [test "x$PYCODESTYLE" != "xno"]) fi AC_SUBST(PYTHON_PREFIX) diff --git a/python/Makefile.am b/python/Makefile.am index b470d2df2..207f6d90c 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -38,6 +38,7 @@ EXTRA_DIST = \ setup.py.in \ run-bindtests \ run-python-tests \ + test-pycodestyle.sh \ t/__init__.py \ t/README \ t/test[0-9]*.py @@ -121,6 +122,10 @@ if ENABLE_APPLIANCE TESTS += run-python-tests endif ENABLE_APPLIANCE +if HAVE_PYCODESTYLE +TESTS += test-pycodestyle.sh +endif + endif HAVE_PYTHON # Extra clean. diff --git a/python/test-pycodestyle.sh b/python/test-pycodestyle.sh new file mode 100755 index 000000000..63b453170 --- /dev/null +++ b/python/test-pycodestyle.sh @@ -0,0 +1,28 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped + +# Gather the list of Python sources. +# (-u is passed to to sort to avoid duplicates in case builddir==srcdir) +files="$(find "$srcdir" . -name '*.py' | sort -u)" + +$PYCODESTYLE $files