From 853d10830faccd9a8d37780d2f957aaba40105d5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 22 May 2012 10:17:00 -0700 Subject: [PATCH] Use PYTHONDONTWRITEBYTECODE=yes for invoking Python for build or test. An upcoming commit will break the ovs.vlog module into an ovs.vlog package with submodules. This commit makes switching between trees with the old structure and those with the new structure much easier. This commit works by setting PYTHONDONTWRITEBYTECODE=yes in Python invocations from the build system and testing. This keeps Python 2.6+ from creating .pyc and .pyo files. Creating .py[co] works OK for any given version of Open vSwitch, but it causes trouble if you switch from a version with foo/__init__.py into an (older) version with plain foo.py, since foo/__init__.pyc will cause Python to ignore foo.py. Signed-off-by: Ben Pfaff --- Makefile.am | 10 ++++++++++ include/openflow/automake.mk | 2 +- lib/automake.mk | 2 +- python/automake.mk | 2 -- tests/atlocal.in | 11 +++++++++++ tests/automake.mk | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index c0c100e7..4b6156d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,16 @@ AM_CPPFLAGS += -DNDEBUG AM_CFLAGS += -fomit-frame-pointer endif +# PYTHONDONTWRITEBYTECODE=yes keeps Python from creating .pyc and .pyo +# files. Creating .py[co] works OK for any given version of Open +# vSwitch, but it causes trouble if you switch from a version with +# foo/__init__.py into an (older) version with plain foo.py, since +# foo/__init__.pyc will cause Python to ignore foo.py. +run_python = \ + PYTHONDONTWRITEBYTECODE=yes \ + PYTHONPATH=$(top_srcdir)/python:$$PYTHONPATH \ + $(PYTHON) + ALL_LOCAL = BUILT_SOURCES = CLEANFILES = diff --git a/include/openflow/automake.mk b/include/openflow/automake.mk index 4b7bc07f..38e8eefd 100644 --- a/include/openflow/automake.mk +++ b/include/openflow/automake.mk @@ -10,7 +10,7 @@ if HAVE_PYTHON SUFFIXES += .h .hstamp .h.hstamp: - $(PYTHON) $(srcdir)/build-aux/check-structs -I$(srcdir)/include $< + $(run_python) $(srcdir)/build-aux/check-structs -I$(srcdir)/include $< touch $@ HSTAMP_FILES = \ diff --git a/lib/automake.mk b/lib/automake.mk index 62175268..52e112bc 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -298,7 +298,7 @@ lib/dirs.c: lib/dirs.c.in Makefile $(srcdir)/lib/ofp-errors.inc: \ lib/ofp-errors.h $(srcdir)/build-aux/extract-ofp-errors - $(PYTHON) $(srcdir)/build-aux/extract-ofp-errors \ + $(run_python) $(srcdir)/build-aux/extract-ofp-errors \ $(srcdir)/lib/ofp-errors.h > $@.tmp && mv $@.tmp $@ $(srcdir)/lib/ofp-errors.c: $(srcdir)/lib/ofp-errors.inc EXTRA_DIST += build-aux/extract-ofp-errors lib/ofp-errors.inc diff --git a/python/automake.mk b/python/automake.mk index a50a7628..4c0e78b4 100644 --- a/python/automake.mk +++ b/python/automake.mk @@ -1,5 +1,3 @@ -run_python = PYTHONPATH=$(top_srcdir)/python:$$PYTHONPATH $(PYTHON) - ovstest_pyfiles = \ python/ovstest/__init__.py \ python/ovstest/args.py \ diff --git a/tests/atlocal.in b/tests/atlocal.in index 1d37b59a..53602258 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -13,6 +13,17 @@ export PYTHONPATH PYTHONIOENCODING=utf_8 export PYTHONIOENCODING +# PYTHONDONTWRITEBYTECODE=yes keeps Python 2.6+ from creating .pyc and .pyo +# files. Creating .py[co] works OK for any given version of Open +# vSwitch, but it causes trouble if you switch from a version with +# foo/__init__.py into an (older) version with plain foo.py, since +# foo/__init__.pyc will cause Python to ignore foo.py. +# +# Python before version 2.6 always creates .pyc files, so if you develop +# with such an older version then you're out of luck. +PYTHONDONTWRITEBYTECODE=yes +export PYTHONDONTWRITEBYTECODE + if test $HAVE_PYTHON = yes; then if python -m argparse 2>/dev/null; then : diff --git a/tests/automake.mk b/tests/automake.mk index 784ae9ce..b7e1b94e 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -74,7 +74,7 @@ check-local: tests/atconfig tests/atlocal $(TESTSUITE) COVERAGE = coverage COVERAGE_FILE='$(abs_srcdir)/.coverage' check-pycov: all tests/atconfig tests/atlocal $(TESTSUITE) clean-pycov - COVERAGE_FILE=$(COVERAGE_FILE) PYTHON='$(COVERAGE) run -p' $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH) $(TESTSUITEFLAGS) + PYTHONDONTWRITEBYTECODE=yes COVERAGE_FILE=$(COVERAGE_FILE) PYTHON='$(COVERAGE) run -p' $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH) $(TESTSUITEFLAGS) @cd $(srcdir) && $(COVERAGE) combine && COVERAGE_FILE=$(COVERAGE_FILE) $(COVERAGE) annotate @echo @echo '----------------------------------------------------------------------' -- 2.30.2