qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] configure: automatically pick python3 is available
@ 2019-03-01 16:33 Daniel P. Berrangé
  2019-03-01 16:48 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel P. Berrangé @ 2019-03-01 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Eduardo Habkost, 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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 configure | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 540bee19ba..ef2e5bf9f5 100755
--- a/configure
+++ b/configure
@@ -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
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] configure: automatically pick python3 is available
  2019-03-01 16:33 [Qemu-devel] [PATCH] configure: automatically pick python3 is available Daniel P. Berrangé
@ 2019-03-01 16:48 ` Eric Blake
  2019-03-01 16:50   ` Daniel P. Berrangé
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2019-03-01 16:48 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: Eduardo Habkost

On 3/1/19 10:33 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>
> ---
>  configure | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 540bee19ba..ef2e5bf9f5 100755
> --- a/configure
> +++ b/configure
> @@ -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',

>  : ${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

> +do
> +    if has $binary

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
> 

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] configure: automatically pick python3 is available
  2019-03-01 16:48 ` Eric Blake
@ 2019-03-01 16:50   ` Daniel P. Berrangé
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2019-03-01 16:50 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, Eduardo Habkost

On Fri, Mar 01, 2019 at 10:48:04AM -0600, Eric Blake wrote:
> On 3/1/19 10:33 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>
> > ---
> >  configure | 21 ++++++++++++++++++---
> >  1 file changed, 18 insertions(+), 3 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index 540bee19ba..ef2e5bf9f5 100755
> > --- a/configure
> > +++ b/configure
> > @@ -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',

People who do that are super annoying ;-P

> 
> >  : ${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

Yeah, that's a nice idea

> 
> > +do
> > +    if has $binary
> 
> 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
> > 
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3226
> Virtualization:  qemu.org | libvirt.org

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 :|

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-01 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-01 16:33 [Qemu-devel] [PATCH] configure: automatically pick python3 is available Daniel P. Berrangé
2019-03-01 16:48 ` Eric Blake
2019-03-01 16:50   ` Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).