← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:py3-on-bionic into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:py3-on-bionic into launchpad-buildd:master.

Commit message:
Run on Python 3 when built for >= bionic

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/383615
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:py3-on-bionic into launchpad-buildd:master.
diff --git a/bin/buildrecipe b/bin/buildrecipe
index d20820a..f3034e7 100755
--- a/bin/buildrecipe
+++ b/bin/buildrecipe
@@ -1,4 +1,4 @@
-#!/usr/bin/python -u
+#!/usr/bin/python3 -u
 # Copyright 2010-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
diff --git a/bin/check-implicit-pointer-functions b/bin/check-implicit-pointer-functions
index 6e20f3f..7ff5389 100755
--- a/bin/check-implicit-pointer-functions
+++ b/bin/check-implicit-pointer-functions
@@ -1,4 +1,4 @@
-#! /usr/bin/python -u
+#! /usr/bin/python3 -u
 #
 # Copyright 2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
diff --git a/bin/in-target b/bin/in-target
index 73db48a..da0303d 100755
--- a/bin/in-target
+++ b/bin/in-target
@@ -1,4 +1,4 @@
-#! /usr/bin/python -u
+#! /usr/bin/python3 -u
 #
 # Copyright 2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
diff --git a/bin/test_buildd_generatetranslationtemplates b/bin/test_buildd_generatetranslationtemplates
index 5bfaae0..85ddc2e 100755
--- a/bin/test_buildd_generatetranslationtemplates
+++ b/bin/test_buildd_generatetranslationtemplates
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 # Copyright 2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 #
diff --git a/bin/test_buildd_recipe b/bin/test_buildd_recipe
index aa4c2bb..849b28b 100755
--- a/bin/test_buildd_recipe
+++ b/bin/test_buildd_recipe
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 # Copyright 2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 #
diff --git a/buildd-genconfig b/buildd-genconfig
index c1f61ec..467dee4 100755
--- a/buildd-genconfig
+++ b/buildd-genconfig
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
diff --git a/debian/changelog b/debian/changelog
index 006223d..91b8886 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -24,6 +24,7 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
   * Add a proper wrapper for check-implicit-pointer-functions.
   * Add a python3-lpbuildd binary package.
   * Fix LXD.run to not default to universal_newlines=True.
+  * Run on Python 3 when built for >= bionic.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 28 Apr 2020 10:19:27 +0100
 
diff --git a/debian/check-python3-twisted b/debian/check-python3-twisted
new file mode 100755
index 0000000..21331e8
--- /dev/null
+++ b/debian/check-python3-twisted
@@ -0,0 +1,9 @@
+#! /usr/bin/python3
+
+import sys
+
+import twisted
+
+
+ok = (twisted.version.major, twisted.version.minor) >= (16, 4)
+sys.exit(0 if ok else 1)
diff --git a/debian/control b/debian/control
index 273fd20..88f2dd8 100644
--- a/debian/control
+++ b/debian/control
@@ -66,9 +66,9 @@ Depends: adduser,
          lxd,
          ntpdate,
          pristine-tar,
-         python,
-         python-apt,
-         python-lpbuildd (=${source:Version}),
+         ${lpbuildd-python-prefix},
+         ${lpbuildd-python-prefix}-apt,
+         ${lpbuildd-python-prefix}-lpbuildd (= ${source:Version}),
          sbuild,
          schroot,
          sudo,
diff --git a/debian/launchpad-buildd.init b/debian/launchpad-buildd.init
index 13ab745..4952893 100755
--- a/debian/launchpad-buildd.init
+++ b/debian/launchpad-buildd.init
@@ -79,7 +79,7 @@ d_start() {
     # Useful for certain kinds of image builds.
     modprobe nbd || true
 
-    su - buildd -c "BUILDD_SLAVE_CONFIG=$CONFROOT/$CONF twistd --no_save --pidfile $PIDFILE --python $TACFILE --logfile $LOGFILE --umask 022"
+    su - buildd -c "BUILDD_SLAVE_CONFIG=$CONFROOT/$CONF twistd3 --no_save --pidfile $PIDFILE --python $TACFILE --logfile $LOGFILE --umask 022"
 }
 
 #
diff --git a/debian/rules b/debian/rules
index 07aee67..2746afa 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,16 +7,37 @@
 
 export PYBUILD_NAME := lpbuildd
 
-export LIBDIR := $(shell python -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())')
+ifeq (ok,$(shell debian/check-python3-twisted && echo ok))
+    export LPBUILDD_PYTHON_PREFIX := python3
+    export LIBDIR := $(shell python3 -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())')
+else
+    export LPBUILDD_PYTHON_PREFIX := python
+    export LIBDIR := $(shell python2 -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())')
+endif
 
 %:
 	dh $@ --with=python2,python3 --buildsystem=pybuild
 
 override_dh_auto_build:
 	dh_auto_build
-	python buildd-genconfig --template=template-buildd-slave.conf \
+	python3 buildd-genconfig --template=template-buildd-slave.conf \
 	--arch=i386 --port=8221 --name=default --host=buildd.buildd \
 		> buildd-slave-example.conf
 
+ifeq ($(LPBUILDD_PYTHON_PREFIX),python)
+override_dh_install:
+	dh_install
+	find debian/launchpad-buildd -type f | xargs grep -l '#!.*python3' | \
+		xargs -r sed -i 's/\(#!.*\)python3/\1python2/'
+
+override_dh_installinit:
+	dh_installinit
+	sed -i 's/twistd3/twistd/' \
+		debian/launchpad-buildd/etc/init.d/launchpad-buildd
+endif
+
+override_dh_gencontrol:
+	dh_gencontrol -- -Vlpbuildd-python-prefix=$(LPBUILDD_PYTHON_PREFIX)
+
 override_dh_builddeb:
 	dh_builddeb -- -Zgzip
diff --git a/debian/upgrade-config b/debian/upgrade-config
index 6f1ac77..3c7b9d4 100755
--- a/debian/upgrade-config
+++ b/debian/upgrade-config
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
diff --git a/lpbuildd/check_implicit_pointer_functions.py b/lpbuildd/check_implicit_pointer_functions.py
index 26372ae..9b8b191 100755
--- a/lpbuildd/check_implicit_pointer_functions.py
+++ b/lpbuildd/check_implicit_pointer_functions.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 #
 # Copyright (c) 2004 Hewlett-Packard Development Company, L.P.
diff --git a/setup.py b/setup.py
index 82ae655..32e4498 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 # Copyright 2015-2019 Canonical Ltd.  All rights reserved.
 #