Skip to contentSkip to conversation

configure: automatically pick python3 is available

PATCH In review Daniel P. Berrangé 2 participants 3 messages Mar 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: automatically pick python3 is available

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.

---
 configure | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
configure +18 -3
index 540bee19ba..ef2e5bf9f5 100755
@@ -902,7 +902,10 @@ 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=${PYTHON-python3 python python2}}
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1797,8 +1800,20 @@ EOF
 exit 0
 fi
 
-if ! has $python; then
-  error_exit "Python not found. Use --python=/path/to/python"
+try_python="$python"
+python=
+for binary in $try_python
+do
+    if has $binary
+    then
+       python=$binary
+       break
+    fi
+done
+
+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
Signature · 1 line
2.20.1
#1 lore raw
Quoted 18 lines · Daniel P. Berrangé

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.

---
 configure | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
configure +0 -0
index 540bee19ba..ef2e5bf9f5 100755

configure fi · line 908

Quoted 8 lines
configure +4 -1
@@ -902,7 +902,10 @@ 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=${PYTHON-python3 python python2}}

If I run with PYTHON='/path with spaces/to/mypython',

configure EOF · line 1805

Quoted 12 lines
configure +3 -2
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1797,8 +1800,20 @@ EOF
 exit 0
 fi
 
-if ! has $python; then
-  error_exit "Python not found. Use --python=/path/to/python"
+try_python="$python"
+python=
+for binary in $try_python

then this ignores my request (trying '/path', 'with', and 'spaces/to/mypython', none of which works).

I think a better approach would be:

python=
for binary in "${PYTHON-python3}" python python2

configure EOF · line 1807

Quoted 2 lines
configure +2 -0
+do
+    if has $binary

if has "$binary"

Quoted 13 lines
configure +9 -0
+    then
+       python=$binary
+       break
+    fi
+done
+
+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
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 20 lines · Eric Blake
Quoted 19 lines · Daniel P. Berrangé

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.

---
 configure | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
configure +0 -0
index 540bee19ba..ef2e5bf9f5 100755
@@ -902,7 +902,10 @@ fi
 
Quoted 9 lines

configure fi · line 908

Quoted 7 lines
configure +4 -1
 : ${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=${PYTHON-python3 python python2}}

If I run with PYTHON='/path with spaces/to/mypython',

People who do that are super annoying ;-P

Quoted 17 lines

configure EOF · line 1805

Quoted 13 lines
configure +3 -2
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1797,8 +1800,20 @@ EOF
 exit 0
 fi
 
-if ! has $python; then
-  error_exit "Python not found. Use --python=/path/to/python"
+try_python="$python"
+python=
+for binary in $try_python

then this ignores my request (trying '/path', 'with', and 'spaces/to/mypython', none of which works).

Quoted 4 lines

I think a better approach would be:

python=
for binary in "${PYTHON-python3}" python python2

Yeah, that's a nice idea

Quoted 17 lines

configure EOF · line 1807

Quoted 3 lines
configure +2 -0
+do
+    if has $binary

if has "$binary"

Quoted 11 lines
configure +9 -0
+    then
+       python=$binary
+       break
+    fi
+done
+
+if test -z "$python"
+then
+    error_exit "Python not found. Use --python=/path/to/python"
 fi
 
Quoted 7 lines
Quoted 2 lines
configure +0 -0
 # Note that if the Python conditional here evaluates True we will exit
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|