[petsc-dev] Configure won't find python

Satish Balay balay at mcs.anl.gov
Sat Apr 18 14:30:42 CDT 2020


Ok - this code looks simple enough - so I'm fine with it.

Satish

On Sat, 18 Apr 2020, Satish Balay via petsc-dev wrote:

> Well I prefer different scripts.
> 
> We used to have patch files encoded in python [it was bad].
> 
> We still make syntax and shell syntax encoded in python - and that has its own quirks.. [wrt extra care when editing etc :(]
> 
> Satish
> 
> On Sat, 18 Apr 2020, Jed Brown wrote:
> 
> > Who says configure can't be both a shell script and a Python script?
> > 
> > 
> > diff --git i/configure w/configure
> > index 4538314871..969a9c0a36 100755
> > --- i/configure
> > +++ w/configure
> > @@ -1,4 +1,11 @@
> > -#!/usr/bin/env python
> > +#!/bin/sh
> > +
> > +"true" '''\'
> > +for pyimpl in python3 python python2; do
> > +  command -v $pyimpl > /dev/null && echo "Using $pyimpl for Python" && exec $pyimpl "$0" "$@"
> > +done
> > +exit 127
> > +'''
> >  
> >  import sys, os
> >  
> > 
> > 
> > https://rosettacode.org/wiki/Multiline_shebang#Python
> > 
> > 
> > Satish Balay via petsc-dev <petsc-dev at mcs.anl.gov> writes:
> > 
> > > I guess this is an alternate way to implement this logic..
> > >
> > > diff --git a/configure b/configure
> > > index 4538314871..8dddfed05d 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -1,4 +1,4 @@
> > > -#!/usr/bin/env python
> > > +#!./python-detect
> > >  
> > >  import sys, os
> > >  
> > > diff --git a/python-detect b/python-detect
> > > new file mode 100755
> > > index 0000000000..1fdfe795c8
> > > --- /dev/null
> > > +++ b/python-detect
> > > @@ -0,0 +1,6 @@
> > > +#!/bin/sh
> > > +for pyimpl in python3 python2 python ; do
> > > +   command -v $pyimpls > /dev/null && echo Using: $pyimpl && exec $pyimpl "$@"
> > > +done
> > > +echo “Could not locate python! Please have python3 python2 or python in PATH
> > > +exit 2
> > >
> > >
> > > Satish
> > >
> > > On Fri, 17 Apr 2020, Jacob Faibussowitsch wrote:
> > >
> > >> Hello All,
> > >> 
> > >> I use an Ubuntu docker image based on jedbrown/mpich-ccache and ran into the following error (Dockerfile attached as well).
> > >> 
> > >> If in a user only has python3 installed and not python2 then /usr/bin/python doesn’t exist. Given that python2 has gone the way of the dodo perhaps petsc should be looking for python3 over python2. This is a somewhat funky but functioning implementation that replaces the shebang line in configure that I have been using to default to python3. I don’t know how portable it is however, I believe “command" is not universally available in every shell?
> > >> 
> > >> #!/bin/sh
> > >> 
> > >> # “”” is comment in python, and : is noop in shell so this configure can be run as ./configure and python2.7 ./configure
> > >> """:"
> > >> 
> > >> # Find the right python implementation, check by sending it on over to dave
> > >> for pyimpls in python3 python2 python /usr/bin/python /usr/bin/env python ; do
> > >>    command -v > /dev/null $pyimpls && exec $pyimpls $0 "$@“
> > >> done
> > >> 
> > >> # Error code in case things go awry
> > >> 
> > >> Echo “PYTHON NOT FOUND” >2
> > >> 
> > >> exit 2
> > >> 
> > >> ":"""
> > >> 
> > >> if sys.version_info < (2,6) or (sys.version_info >= (3,0) and sys.version_info < (3,4)):
> > >>   print('************************************************************************')
> > >>   print('*      Python version 2.6+ or 3.4+ is required to run ./configure      *')
> > >>   print('*         Try: "python2.7 ./configure" or "python3 ./configure"        *')
> > >>   print('************************************************************************')
> > >>   sys.exit(4)
> > >> 
> > >> sys.path.insert(0, os.path.abspath('config'))
> > >> import configure
> > >> configure.petsc_configure([])
> > >> 
> > >> 
> > >> Best regards,
> > >> 
> > >> Jacob Faibussowitsch
> > >> (Jacob Fai - booss - oh - vitch)
> > >> Cell: (312) 694-3391
> > >> 
> > >> 
> > 
> 


More information about the petsc-dev mailing list