[v3] configure: automatically pick python3 is available
diff mbox series

Message ID 20190327170701.23798-1-berrange@redhat.com
State New
Headers show
Series
  • [v3] configure: automatically pick python3 is available
Related show

Commit Message

Daniel P. Berrangé March 27, 2019, 5:07 p.m. UTC
Unless overridden via an env var or configure arg, QEMU will only look
for the 'python' binary in $PATH. This is unhelpful on distros which
are only shipping Python 3.x (eg Fedora) in their default install as,
if they comply with PEP 394, the bare 'python' binary won't exist.

This changes configure so that by default it will search for all three
common python binaries, preferring to find Python 3.x versions.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---

Changed in v3:

 - 100% fewer tabs

 configure | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Eduardo Habkost March 27, 2019, 5:13 p.m. UTC | #1
On Wed, Mar 27, 2019 at 05:07:01PM +0000, Daniel P. Berrangé wrote:
> Unless overridden via an env var or configure arg, QEMU will only look
> for the 'python' binary in $PATH. This is unhelpful on distros which
> are only shipping Python 3.x (eg Fedora) in their default install as,
> if they comply with PEP 394, the bare 'python' binary won't exist.
> 
> This changes configure so that by default it will search for all three
> common python binaries, preferring to find Python 3.x versions.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Queued for 4.1.  Thanks, and sorry for taking so long to handle it.

Patch
diff mbox series

diff --git a/configure b/configure
index 1c563a7027..8fb323c320 100755
--- a/configure
+++ b/configure
@@ -902,7 +902,18 @@  fi
 
 : ${make=${MAKE-make}}
 : ${install=${INSTALL-install}}
-: ${python=${PYTHON-python}}
+# We prefer python 3.x. A bare 'python' is traditionally
+# python 2.x, but some distros have it as python 3.x, so
+# we check that before python2
+python=
+for binary in "${PYTHON-python3}" python python2
+do
+    if has "$binary"
+    then
+        python="$binary"
+        break
+    fi
+done
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1824,8 +1835,9 @@  EOF
 exit 0
 fi
 
-if ! has $python; then
-  error_exit "Python not found. Use --python=/path/to/python"
+if test -z "$python"
+then
+    error_exit "Python not found. Use --python=/path/to/python"
 fi
 
 # Note that if the Python conditional here evaluates True we will exit