Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 559578 - python_fix_shebang doesn't handle insane locations or EPREFIX
Summary: python_fix_shebang doesn't handle insane locations or EPREFIX
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-04 09:06 UTC by Justin Lecher
Modified: 2018-09-11 20:29 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Lecher 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?