Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 559578

Summary: python_fix_shebang doesn't handle insane locations or EPREFIX
Product: Gentoo Linux Reporter: Justin Lecher (RETIRED) <jlec>
Component: Current packagesAssignee: Python Gentoo Team <python>
Status: RESOLVED OBSOLETE    
Severity: normal CC: chewi, prefix
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Justin Lecher (RETIRED) gentoo-dev 2015-09-04 09:06:57 UTC
When changing shebang following sed call is run

+ [[ #!/usr/bin/python2 == *python2\ * ]]
+ sed -i -e '1s:python2$:python2.7:' .........
+ any_fixed=1

Two Problematic cases here:

in case of Gentoo Prefix this result of the correction is

#!/usr/bin/python2.7

but it should be

#!${EPREFIX}/usr/bin/python2.7


Second case:

original the shebang wasn't sane

+ [[ #!/foo/bar/python2 == *python2\ * ]]
+ sed -i -e '1s:python2$:python2.7:' ...............
+ any_fixed=1
+ set +x

resulting in

#!/foo/bar/python2.7

We need to exchange it to the full "${PYTHON}"
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-09-25 16:35:16 UTC
(In reply to Justin Lecher from comment #0)
> When changing shebang following sed call is run
> 
> + [[ #!/usr/bin/python2 == *python2\ * ]]
> + sed -i -e '1s:python2$:python2.7:' .........
> + any_fixed=1
> 
> Two Problematic cases here:
> 
> in case of Gentoo Prefix this result of the correction is
> 
> #!/usr/bin/python2.7
> 
> but it should be
> 
> #!${EPREFIX}/usr/bin/python2.7

EPREFIX being insane would break the shebang. You should really use '/usr/bin/env python...' here.

> 
> 
> Second case:
> 
> original the shebang wasn't sane
> 
> + [[ #!/foo/bar/python2 == *python2\ * ]]
> + sed -i -e '1s:python2$:python2.7:' ...............
> + any_fixed=1
> + set +x
> 
> resulting in
> 
> #!/foo/bar/python2.7
> 
> We need to exchange it to the full "${PYTHON}"

You need to manually sed insane stuff. Guessing is unsafe.
Comment 2 Fabian Groffen gentoo-dev 2015-09-26 08:39:20 UTC
(In reply to Michał Górny from comment #1)
> (In reply to Justin Lecher from comment #0)
> > When changing shebang following sed call is run
> > 
> > + [[ #!/usr/bin/python2 == *python2\ * ]]
> > + sed -i -e '1s:python2$:python2.7:' .........
> > + any_fixed=1
> > 
> > Two Problematic cases here:
> > 
> > in case of Gentoo Prefix this result of the correction is
> > 
> > #!/usr/bin/python2.7
> > 
> > but it should be
> > 
> > #!${EPREFIX}/usr/bin/python2.7
> 
> EPREFIX being insane would break the shebang. You should really use
> '/usr/bin/env python...' here.

/usr/bin/env python would work for us, but sometimes that's not possible, since you cannot pass any arguments to the python binary that way.  Also, that usage is up to $UPSTREAM and $MAINTAINER?

In our case we can assume $EPREFIX to be sane.  If it isn't, then Portage is broken and you've got issues way before this.  I personally like it over /usr/bin/env, for it eliminates the surprise factor in case $PATH isn't what it is supposed to be.

> > Second case:
> > 
> > original the shebang wasn't sane
> > 
> > + [[ #!/foo/bar/python2 == *python2\ * ]]
> > + sed -i -e '1s:python2$:python2.7:' ...............
> > + any_fixed=1
> > + set +x
> > 
> > resulting in
> > 
> > #!/foo/bar/python2.7
> > 
> > We need to exchange it to the full "${PYTHON}"
> 
> You need to manually sed insane stuff. Guessing is unsafe.

That would be a $MAINTAINER problem, not Prefix specific then, am I right?
Comment 3 Fabian Groffen gentoo-dev 2020-12-13 17:08:09 UTC
I don't think this is an issue we like to persue any more.
Comment 4 James Le Cuirot gentoo-dev 2020-12-13 19:06:32 UTC
(In reply to Fabian Groffen from comment #3)
> I don't think this is an issue we like to persue any more.

Since there was a slight overlap here with how I was trying to handle cross-compiling of Python modules (long story), I'd like to know more about why you came to this decision.