[Qemu-devel] [PATCH v2] configure: automatically pick python3 is available

Daniel P. Berrangé posted 1 patch 5 years, 1 month ago
Test docker-clang@ubuntu passed
Test asan passed
Test checkpatch passed
Test docker-mingw@fedora passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190319110208.4944-1-berrange@redhat.com
There is a newer version of this series
configure | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
[Qemu-devel] [PATCH v2] configure: automatically pick python3 is available
Posted by Daniel P. Berrangé 5 years, 1 month ago
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 v2:

 - Rewrote to follow Eric's suggested approach

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

diff --git a/configure b/configure
index 7071f52584..028453a5a6 100755
--- a/configure
+++ b/configure
@@ -901,7 +901,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
@@ -1797,8 +1808,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
-- 
2.20.1


Re: [Qemu-devel] [PATCH v2] configure: automatically pick python3 is available
Posted by Daniel P. Berrangé 5 years, 1 month ago
ping

On Tue, Mar 19, 2019 at 11:02:08AM +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>
> ---
> 
> Changed in v2:
> 
>  - Rewrote to follow Eric's suggested approach
> 
>  configure | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 7071f52584..028453a5a6 100755
> --- a/configure
> +++ b/configure
> @@ -901,7 +901,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
> @@ -1797,8 +1808,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
> -- 
> 2.20.1
> 

Regards,
Daniel
-- 
|: 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 :|

Re: [Qemu-devel] [PATCH v2] configure: automatically pick python3 is available
Posted by Eric Blake 5 years, 1 month ago
On 3/19/19 6:02 AM, 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>
> ---
> 

Reviewed-by: Eric Blake <eblake@redhat.com>


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH v2] configure: automatically pick python3 is available
Posted by Eduardo Habkost 5 years, 1 month ago
On Tue, Mar 19, 2019 at 11:02:08AM +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>
> ---
> 
> Changed in v2:
> 
>  - Rewrote to follow Eric's suggested approach
> 
>  configure | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 7071f52584..028453a5a6 100755
> --- a/configure
> +++ b/configure
> @@ -901,7 +901,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

I wouldn't like configure to try any other python binary if one
was explicitly specified using "--python=".  It might make
packaging mistakes go completely undetected.


> +do
> +    if has "$binary"
> +    then
> +	python="$binary"
> +	break

Tabs/spaces mix up here.  (I thought Patchew/checkpatch.pl would
detect this?)

> +    fi
> +done
>  : ${smbd=${SMBD-/usr/sbin/smbd}}
>  
>  # Default objcc to clang if available, otherwise use CC
> @@ -1797,8 +1808,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
> -- 
> 2.20.1
> 
> 

-- 
Eduardo

Re: [Qemu-devel] [PATCH v2] configure: automatically pick python3 is available
Posted by Daniel P. Berrangé 5 years, 1 month ago
On Wed, Mar 27, 2019 at 01:38:07PM -0300, Eduardo Habkost wrote:
> On Tue, Mar 19, 2019 at 11:02:08AM +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>
> > ---
> > 
> > Changed in v2:
> > 
> >  - Rewrote to follow Eric's suggested approach
> > 
> >  configure | 18 +++++++++++++++---
> >  1 file changed, 15 insertions(+), 3 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index 7071f52584..028453a5a6 100755
> > --- a/configure
> > +++ b/configure
> > @@ -901,7 +901,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
> 
> I wouldn't like configure to try any other python binary if one
> was explicitly specified using "--python=".  It might make
> packaging mistakes go completely undetected.

This code runs long before --python arg is parsed. It is just
setting up the default value for the $python  env in configure.

Later code will replace this default if --python is given, so
we still honour --python to same extent as before this patch.

> 
> 
> > +do
> > +    if has "$binary"
> > +    then
> > +	python="$binary"
> > +	break
> 
> Tabs/spaces mix up here.  (I thought Patchew/checkpatch.pl would
> detect this?)

Opps. Perhaps not for the configire script.

> 
> > +    fi
> > +done
> >  : ${smbd=${SMBD-/usr/sbin/smbd}}
> >  
> >  # Default objcc to clang if available, otherwise use CC
> > @@ -1797,8 +1808,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
> > -- 
> > 2.20.1
> > 
> > 
> 
> -- 
> Eduardo

Regards,
Daniel
-- 
|: 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 :|