python: Run flake8 at build time.
authorRussell Bryant <russell@ovn.org>
Tue, 22 Dec 2015 01:24:34 +0000 (20:24 -0500)
committerRussell Bryant <russell@ovn.org>
Tue, 5 Jan 2016 23:13:46 +0000 (18:13 -0500)
If flake8 is installed, run it at build time.  Similar to most Makefile
targets, run it once and then only run again if the files change.

flake8 is set to ignore all error and warning types that currently occur.
Future patches will remove items from the ignore list as they are
resolved.

Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
INSTALL.md
Makefile.am
configure.ac
debian/automake.mk
m4/openvswitch.m4
ofproto/automake.mk
python/automake.mk
tests/automake.mk
utilities/automake.mk
vtep/automake.mk
xenserver/automake.mk

index 906825a..bf756f2 100644 (file)
@@ -129,6 +129,8 @@ installing the following to obtain better warnings:
 
   - clang, version 3.4 or later
 
+  - flake8 (for Python code)
+
 Also, you may find the ovs-dev script found in utilities/ovs-dev.py useful.
 
 Installation Requirements
index 946e1c2..52db244 100644 (file)
@@ -141,6 +141,7 @@ SUFFIXES =
 check_DATA =
 check_SCRIPTS =
 pkgconfig_DATA =
+FLAKE8_PYFILES =
 
 scriptsdir = $(pkgdatadir)/scripts
 completiondir = $(sysconfdir)/bash_completion.d
@@ -339,6 +340,12 @@ manpage-check: $(man_MANS) $(dist_man_MANS) $(noinst_man_MANS)
 CLEANFILES += manpage-check
 endif
 
+if HAVE_FLAKE8
+ALL_LOCAL += flake8-check
+flake8-check: $(FLAKE8_PYFILES)
+       $(AM_V_GEN) if flake8 $^ --ignore=E111,E112,E113,E123,E126,E127,E128,E129,E131,E201,E203,E222,E225,E226,E231,E241,E251,E261,E262,E265,E271,E302,E303,E501,E502,E703,E711,E713,E721,F401,F811,F821,F841,W601 ${FLAKE8_FLAGS}; then touch $@; else exit 1; fi
+endif
+
 include $(srcdir)/manpages.mk
 $(srcdir)/manpages.mk: $(MAN_ROOTS) build-aux/sodepends.pl
        @$(PERL) $(srcdir)/build-aux/sodepends.pl -I. -I$(srcdir) $(MAN_ROOTS) >$(@F).tmp
index 8418aea..49aa182 100644 (file)
@@ -95,6 +95,7 @@ OVS_CHECK_OPENSSL
 OVS_CHECK_LIBCAPNG
 OVS_CHECK_LOGDIR
 OVS_CHECK_PYTHON
+OVS_CHECK_FLAKE8
 OVS_CHECK_DOT
 OVS_CHECK_IF_PACKET
 OVS_CHECK_IF_DL
index daaf327..de2350c 100644 (file)
@@ -75,6 +75,9 @@ EXTRA_DIST += \
        debian/ifupdown.sh \
        debian/source/format
 
+FLAKE8_PYFILES += \
+       debian/ovs-monitor-ipsec
+
 check-debian-changelog-version:
        @DEB_VERSION=`echo '$(VERSION)' | sed 's/pre/~pre/'`;                \
        if $(FGREP) '($(DEB_VERSION)' $(srcdir)/debian/changelog >/dev/null; \
index 0cfaae6..6d4e5da 100644 (file)
@@ -352,6 +352,18 @@ else:
    fi
    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
 
+dnl Checks for dot.
+AC_DEFUN([OVS_CHECK_FLAKE8],
+  [AC_CACHE_CHECK(
+    [for flake8],
+    [ovs_cv_flake8],
+    [if flake8 --version >/dev/null 2>&1; then
+       ovs_cv_flake8=yes
+     else
+       ovs_cv_flake8=no
+     fi])
+   AM_CONDITIONAL([HAVE_FLAKE8], [test "$ovs_cv_flake8" = yes])])
+
 dnl Checks for dot.
 AC_DEFUN([OVS_CHECK_DOT],
   [AC_CACHE_CHECK(
index 0058ff3..50e7507 100644 (file)
@@ -82,3 +82,5 @@ ofproto/ipfix-entities.def: ofproto/ipfix.xml ofproto/ipfix-gen-entities
 
 # IPFIX enterprise entity definition macros.
 EXTRA_DIST += ofproto/ipfix-enterprise-entities.def
+
+FLAKE8_PYFILES += ofproto/ipfix-gen-entities
index 42b428a..dc62422 100644 (file)
@@ -50,6 +50,13 @@ PYFILES = $(ovs_pyfiles) python/ovs/dirs.py $(ovstest_pyfiles)
 EXTRA_DIST += $(PYFILES)
 PYCOV_CLEAN_FILES += $(PYFILES:.py=.py,cover)
 
+FLAKE8_PYFILES += \
+       $(filter-out python/ovs/dirs.py,$(PYFILES)) \
+       python/setup.py \
+       python/build/__init__.py \
+       python/build/nroff.py \
+       python/ovs/dirs.py.template
+
 if HAVE_PYTHON
 nobase_pkgdata_DATA = $(ovs_pyfiles) $(ovstest_pyfiles)
 ovs-install-data-local:
index 6ce503f..28078c0 100644 (file)
@@ -354,6 +354,8 @@ CHECK_PYFILES = \
 EXTRA_DIST += $(CHECK_PYFILES)
 PYCOV_CLEAN_FILES += $(CHECK_PYFILES:.py=.py,cover) .coverage
 
+FLAKE8_PYFILES += $(CHECK_PYFILES)
+
 if HAVE_OPENSSL
 TESTPKI_FILES = \
        tests/testpki-cacert.pem \
index d5d1c33..d08347e 100644 (file)
@@ -153,4 +153,6 @@ bin_PROGRAMS += utilities/ovs-benchmark
 utilities_ovs_benchmark_SOURCES = utilities/ovs-benchmark.c
 utilities_ovs_benchmark_LDADD = lib/libopenvswitch.la
 
+FLAKE8_PYFILES += utilities/ovs-pcap.in
+
 include utilities/bugtool/automake.mk
index de028b6..2645f30 100644 (file)
@@ -43,6 +43,8 @@ scripts_SCRIPTS += \
 docs += vtep/README.ovs-vtep.md
 EXTRA_DIST += vtep/ovs-vtep
 
+FLAKE8_PYFILES += vtep/ovs-vtep
+
 # VTEP schema and IDL
 EXTRA_DIST += vtep/vtep.ovsschema
 pkgdata_DATA += vtep/vtep.ovsschema
index 816b1b5..1f75e3a 100644 (file)
@@ -26,6 +26,9 @@ EXTRA_DIST += \
        xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
        xenserver/usr_share_openvswitch_scripts_sysconfig.template
 
+FLAKE8_PYFILES += \
+       xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
+
 $(srcdir)/xenserver/openvswitch-xen.spec: xenserver/openvswitch-xen.spec.in $(top_builddir)/config.status
        $(AM_V_GEN)($(ro_shell) && sed -e 's,[@]VERSION[@],$(VERSION),g') \
                < $(srcdir)/xenserver/$(@F).in > $(@F).tmp || exit 1; \