← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-rebuild-virtualenv into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-rebuild-virtualenv into launchpad:master.

Commit message:
Rebuild virtualenv if $(PYTHON) changes

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/400975

On production, we build the tree on a central system, rsync it out, and then run "make compile" on each target (or "make build" in the case of frontends that need to ship CSS/JS).  This speeds up deployments: the target systems *can* build the tree from scratch if need be, but they normally don't have to.  However, when deploying some targets on Python 2 and some on Python 3, this doesn't quite work, because "make compile" fails to rebuild the virtualenv on systems where we're asking for `PYTHON=python3`.

To fix this, rebuild the virtualenv if `$(PYTHON)` doesn't match the version of Python that was used to build the current virtualenv.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-rebuild-virtualenv into launchpad:master.
diff --git a/Makefile b/Makefile
index 49ced64..5466ef7 100644
--- a/Makefile
+++ b/Makefile
@@ -28,8 +28,10 @@ PIP_ENV += PIP_FIND_LINKS="file://$(WD)/wheels/ file://$(WD)/download-cache/dist
 VIRTUALENV := $(PIP_ENV) virtualenv
 PIP := PYTHONPATH= $(PIP_ENV) env/bin/pip --cache-dir=$(WD)/download-cache/
 
+VENV_PYTHON := env/bin/$(PYTHON)
+
 SITE_PACKAGES := \
-	$$(env/bin/python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
+	$$($(VENV_PYTHON) -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
 
 TESTFLAGS=-p $(VERBOSITY)
 TESTOPTS=
@@ -73,6 +75,7 @@ API_INDEX = $(APIDOC_DIR)/index.html
 # NB: It's important PIP_BIN only mentions things genuinely produced by pip.
 PIP_BIN = \
     $(PY) \
+    $(VENV_PYTHON) \
     bin/bingtestservice \
     bin/build-twisted-plugin-cache \
     bin/harness \
@@ -277,8 +280,8 @@ build_eggs: build_wheels
 #
 # If we listed every target on the left-hand side, a parallel make would try
 # multiple copies of this rule to build them all.  Instead, we nominally build
-# just $(PY), and everything else is implicitly updated by that.
-$(PY): download-cache requirements/combined.txt setup.py
+# just $(VENV_PYTHON), and everything else is implicitly updated by that.
+$(VENV_PYTHON): download-cache requirements/combined.txt setup.py
 	rm -rf env
 	mkdir -p env
 	$(VIRTUALENV) \
@@ -294,11 +297,11 @@ $(PY): download-cache requirements/combined.txt setup.py
 		|| { code=$$?; rm -f $@; exit $$code; }
 	touch $@
 
-$(subst $(PY),,$(PIP_BIN)): $(PY)
+$(subst $(VENV_PYTHON),,$(PIP_BIN)): $(VENV_PYTHON)
 
 # Explicitly update version-info.py rather than declaring $(VERSION_INFO) as
 # a prerequisite, to make sure it's up to date when doing deployments.
-compile: $(PY)
+compile: $(VENV_PYTHON)
 	${SHHH} utilities/relocate-virtualenv env
 	$(PYTHON) utilities/link-system-packages.py \
 		"$(SITE_PACKAGES)" system-packages.txt