Look for pycodestyle, and use it to check all the Python sources (tests
and auxiliary scripts included) of the Python bindings.
---
config.sh.in | 1 +
m4/guestfs-python.m4 | 3 +++
python/Makefile.am | 5 +++++
python/test-pycodestyle.sh | 30 ++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+)
create mode 100755 python/test-pycodestyle.sh
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 f0a4b55bd..7286ac906 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
@@ -117,6 +118,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..2a5bf3fac
--- /dev/null
+++ b/python/test-pycodestyle.sh
@@ -0,0 +1,30 @@
+#!/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)"
+
+# Ignore:
+# E501 line too long (95 > 79 characters)
+$PYCODESTYLE --ignore=E501 $files
--
2.24.1