Use PYTHONDONTWRITEBYTECODE=yes for invoking Python for build or test.
authorBen Pfaff <blp@nicira.com>
Tue, 22 May 2012 17:17:00 +0000 (10:17 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 22 May 2012 17:17:00 +0000 (10:17 -0700)
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 <blp@nicira.com>
Makefile.am
include/openflow/automake.mk
lib/automake.mk
python/automake.mk
tests/atlocal.in
tests/automake.mk

index c0c100e..4b6156d 100644 (file)
@@ -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 =
index 4b7bc07..38e8eef 100644 (file)
@@ -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 = \
index 6217526..52e112b 100644 (file)
@@ -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
index a50a762..4c0e78b 100644 (file)
@@ -1,5 +1,3 @@
-run_python = PYTHONPATH=$(top_srcdir)/python:$$PYTHONPATH $(PYTHON)
-
 ovstest_pyfiles = \
        python/ovstest/__init__.py \
        python/ovstest/args.py \
index 1d37b59..5360225 100644 (file)
@@ -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
         :
index 784ae9c..b7e1b94 100644 (file)
@@ -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 '----------------------------------------------------------------------'