Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-17 Thread Michał Górny
On Wed, 2020-06-17 at 10:18 +0200, Ulrich Mueller wrote:
> > > > > > On Tue, 16 Jun 2020, Michał Górny wrote:
> > '/usr/bin/env python' (with no extra options) is the portable shebang.
> 
> I still think this is a gross hack. You want your script to use the
> correct interpreter (which is in /usr/bin, or the path substituted for
> it at install time), not some random binary which happens to be found
> in the user's ${PATH}.
> 

How do you presume what the correct interpreter is, and why do you
presume that users put 'random binaries' in their PATH?  What if
the user needs to override 'correct interpreter'?  Requiring people to
overwrite executables in /usr/bin sounds like a 'gross hack'.

-- 
Best regards,
Michał Górny



signature.asc
Description: This is a digitally signed message part


Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-17 Thread Ulrich Mueller
> On Tue, 16 Jun 2020, Michał Górny wrote:

> '/usr/bin/env python' (with no extra options) is the portable shebang.

I still think this is a gross hack. You want your script to use the
correct interpreter (which is in /usr/bin, or the path substituted for
it at install time), not some random binary which happens to be found
in the user's ${PATH}.

Ulrich


signature.asc
Description: PGP signature


Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-17 Thread Fabian Groffen
On 16-06-2020 23:10:28 -0500, Sid Spry wrote:
> On Tue, Jun 16, 2020, at 3:57 PM, Michał Górny wrote:
> > '/usr/bin/env python' (with no extra options) is the portable shebang.
> > 
> 
> I added `-S` to preserve the options passed via the shebang line. It seems 
> they can be left off, does anyone know otherwise?

-S is not supported on some platforms.

In any case, I think this patch is wrong.  In the Prefix case, the
shebangs are set during install, in the non-Prefix case I think there is
machinery in place to replace the shebangs during install.

It seems the problem is already solved, why do you need these shebangs
changed?

Thanks,
Fabian

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Sid Spry
On Tue, Jun 16, 2020, at 3:57 PM, Michał Górny wrote:
> On Tue, 2020-06-16 at 15:19 -0400, Mike Gilbert wrote:
> > On Tue, Jun 16, 2020 at 1:55 PM Zac Medico  wrote:
> > > On 6/16/20 10:46 AM, Mike Gilbert wrote:
> > > > On Tue, Jun 16, 2020 at 1:45 PM Mike Gilbert  wrote:
> > > > > On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
> > > > > > On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
> > > > > > > But we know that it is in /usr/bin, so why add yet another 
> > > > > > > indirection?
> > > > > > > 
> > > > > > > Attachments:
> > > > > > > * signature.asc
> > > > > > 
> > > > > > Ah, sorry -- I forgot to note this here. If you wish to support 
> > > > > > prefix it is possible it may not be in /usr/bin. Granted I am not 
> > > > > > sure if the prefix stage3 I was using is old enough to be broken in 
> > > > > > some way, but adding this would prevent future breakage.
> > > > > 
> > > > > The portage ebuild and the python distutils module already take care
> > > > > of updating shebangs at install time.
> > > > 
> > > > I suppose your patch might be useful if you are trying to run portage
> > > > from a git checkout on a prefix system.
> > > > 
> > > 
> > > So, given that the ebuild updates shebangs automatically, should't we
> > > optimize the default shebangs to be as flexible as possible?
> > 
> > Yes, that makes sense.
> > 
> > However, we should test to make sure that distutils is smart enough to
> > parse that "/usr/bin/env -S python" string and replace it with
> > version-specific python shebang.
> > 
> 
> '/usr/bin/env python' (with no extra options) is the portable shebang.
> 

I added `-S` to preserve the options passed via the shebang line. It seems they 
can be left off, does anyone know otherwise?



Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Michał Górny
On Tue, 2020-06-16 at 15:19 -0400, Mike Gilbert wrote:
> On Tue, Jun 16, 2020 at 1:55 PM Zac Medico  wrote:
> > On 6/16/20 10:46 AM, Mike Gilbert wrote:
> > > On Tue, Jun 16, 2020 at 1:45 PM Mike Gilbert  wrote:
> > > > On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
> > > > > On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
> > > > > > But we know that it is in /usr/bin, so why add yet another 
> > > > > > indirection?
> > > > > > 
> > > > > > Attachments:
> > > > > > * signature.asc
> > > > > 
> > > > > Ah, sorry -- I forgot to note this here. If you wish to support 
> > > > > prefix it is possible it may not be in /usr/bin. Granted I am not 
> > > > > sure if the prefix stage3 I was using is old enough to be broken in 
> > > > > some way, but adding this would prevent future breakage.
> > > > 
> > > > The portage ebuild and the python distutils module already take care
> > > > of updating shebangs at install time.
> > > 
> > > I suppose your patch might be useful if you are trying to run portage
> > > from a git checkout on a prefix system.
> > > 
> > 
> > So, given that the ebuild updates shebangs automatically, should't we
> > optimize the default shebangs to be as flexible as possible?
> 
> Yes, that makes sense.
> 
> However, we should test to make sure that distutils is smart enough to
> parse that "/usr/bin/env -S python" string and replace it with
> version-specific python shebang.
> 

'/usr/bin/env python' (with no extra options) is the portable shebang.

-- 
Best regards,
Michał Górny



signature.asc
Description: This is a digitally signed message part


Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Mike Gilbert
On Tue, Jun 16, 2020 at 1:55 PM Zac Medico  wrote:
>
> On 6/16/20 10:46 AM, Mike Gilbert wrote:
> > On Tue, Jun 16, 2020 at 1:45 PM Mike Gilbert  wrote:
> >>
> >> On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
> >>>
> >>> On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
>  But we know that it is in /usr/bin, so why add yet another indirection?
> 
>  Attachments:
>  * signature.asc
> >>>
> >>> Ah, sorry -- I forgot to note this here. If you wish to support prefix it 
> >>> is possible it may not be in /usr/bin. Granted I am not sure if the 
> >>> prefix stage3 I was using is old enough to be broken in some way, but 
> >>> adding this would prevent future breakage.
> >>
> >> The portage ebuild and the python distutils module already take care
> >> of updating shebangs at install time.
> >
> > I suppose your patch might be useful if you are trying to run portage
> > from a git checkout on a prefix system.
> >
>
> So, given that the ebuild updates shebangs automatically, should't we
> optimize the default shebangs to be as flexible as possible?

Yes, that makes sense.

However, we should test to make sure that distutils is smart enough to
parse that "/usr/bin/env -S python" string and replace it with
version-specific python shebang.



Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Zac Medico
On 6/16/20 10:46 AM, Mike Gilbert wrote:
> On Tue, Jun 16, 2020 at 1:45 PM Mike Gilbert  wrote:
>>
>> On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
>>>
>>> On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
 But we know that it is in /usr/bin, so why add yet another indirection?

 Attachments:
 * signature.asc
>>>
>>> Ah, sorry -- I forgot to note this here. If you wish to support prefix it 
>>> is possible it may not be in /usr/bin. Granted I am not sure if the prefix 
>>> stage3 I was using is old enough to be broken in some way, but adding this 
>>> would prevent future breakage.
>>
>> The portage ebuild and the python distutils module already take care
>> of updating shebangs at install time.
> 
> I suppose your patch might be useful if you are trying to run portage
> from a git checkout on a prefix system.
> 

So, given that the ebuild updates shebangs automatically, should't we
optimize the default shebangs to be as flexible as possible?
-- 
Thanks,
Zac



signature.asc
Description: OpenPGP digital signature


Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Mike Gilbert
On Tue, Jun 16, 2020 at 1:45 PM Mike Gilbert  wrote:
>
> On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
> >
> > On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
> > > But we know that it is in /usr/bin, so why add yet another indirection?
> > >
> > > Attachments:
> > > * signature.asc
> >
> > Ah, sorry -- I forgot to note this here. If you wish to support prefix it 
> > is possible it may not be in /usr/bin. Granted I am not sure if the prefix 
> > stage3 I was using is old enough to be broken in some way, but adding this 
> > would prevent future breakage.
>
> The portage ebuild and the python distutils module already take care
> of updating shebangs at install time.

I suppose your patch might be useful if you are trying to run portage
from a git checkout on a prefix system.



Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-16 Thread Mike Gilbert
On Mon, Jun 15, 2020 at 9:39 AM Sid Spry  wrote:
>
> On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
> > But we know that it is in /usr/bin, so why add yet another indirection?
> >
> > Attachments:
> > * signature.asc
>
> Ah, sorry -- I forgot to note this here. If you wish to support prefix it is 
> possible it may not be in /usr/bin. Granted I am not sure if the prefix 
> stage3 I was using is old enough to be broken in some way, but adding this 
> would prevent future breakage.

The portage ebuild and the python distutils module already take care
of updating shebangs at install time.



Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-15 Thread Sid Spry
On Mon, Jun 15, 2020, at 2:36 AM, Ulrich Mueller wrote:
> But we know that it is in /usr/bin, so why add yet another indirection?
> 
> Attachments:
> * signature.asc

Ah, sorry -- I forgot to note this here. If you wish to support prefix it is 
possible it may not be in /usr/bin. Granted I am not sure if the prefix stage3 
I was using is old enough to be broken in some way, but adding this would 
prevent future breakage.

I understand your concern but are these really in a hot path? Whatever the 
scripts are doing will beat the time it takes to invoke env by orders of 
magnitude. I can run benchmarks if you'd like, would the tests serve as such?



Re: [gentoo-portage-dev] [PATCH] Use env to find python

2020-06-15 Thread Ulrich Mueller
But we know that it is in /usr/bin, so why add yet another indirection?


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] Use env to find python

2020-06-14 Thread Sid Spry
>From b3854bd9791bb21d7284ef6284a3fb7d4b585412 Mon Sep 17 00:00:00 2001
From: Sid Spry 
Date: Sun, 14 Jun 2020 23:29:46 -0500
Subject: [PATCH] Use env to find python
To: gentoo-portage-dev@lists.gentoo.org

---
bin/archive-conf | 2 +-
bin/binhost-snapshot | 2 +-
bin/check-implicit-pointer-usage.py | 2 +-
bin/chmod-lite.py | 2 +-
bin/chpathtool.py | 2 +-
bin/clean_locks | 2 +-
bin/dispatch-conf | 2 +-
bin/dohtml.py | 2 +-
bin/doins.py | 2 +-
bin/ebuild | 2 +-
bin/ebuild-ipc.py | 2 +-
bin/egencache | 2 +-
bin/emaint | 2 +-
bin/emerge | 2 +-
bin/emirrordist | 2 +-
bin/env-update | 2 +-
bin/filter-bash-environment.py | 2 +-
bin/fixpackages | 2 +-
bin/glsa-check | 2 +-
bin/install.py | 2 +-
bin/lock-helper.py | 2 +-
bin/portageq | 2 +-
bin/quickpkg | 2 +-
bin/regenworld | 2 +-
bin/xattr-helper.py | 2 +-
bin/xpak-helper.py | 2 +-
lib/portage/tests/runTests.py | 2 +-
lib/portage/util/changelog.py | 2 +-
runtests | 2 +-
tabcheck.py | 2 +-
30 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/bin/archive-conf b/bin/archive-conf
index 8341ffe73..36a4da07a 100755
--- a/bin/archive-conf
+++ b/bin/archive-conf
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/binhost-snapshot b/bin/binhost-snapshot
index d677e7568..3726bb20a 100755
--- a/bin/binhost-snapshot
+++ b/bin/binhost-snapshot
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2010-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/check-implicit-pointer-usage.py 
b/bin/check-implicit-pointer-usage.py
index a49db8107..5b3cec019 100755
--- a/bin/check-implicit-pointer-usage.py
+++ b/bin/check-implicit-pointer-usage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b

# Ripped from HP and updated from Debian
# Update by Gentoo to support unicode output
diff --git a/bin/chmod-lite.py b/bin/chmod-lite.py
index 177be7eab..c34c68912 100755
--- a/bin/chmod-lite.py
+++ b/bin/chmod-lite.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/chpathtool.py b/bin/chpathtool.py
index fbd18b987..fb438e5ba 100755
--- a/bin/chpathtool.py
+++ b/bin/chpathtool.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2011-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/clean_locks b/bin/clean_locks
index 94ba4c606..c62d10b94 100755
--- a/bin/clean_locks
+++ b/bin/clean_locks
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index 62ab3f6cc..9d22aae72 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/dohtml.py b/bin/dohtml.py
index dfcaa6026..8505134c5 100755
--- a/bin/dohtml.py
+++ b/bin/dohtml.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/doins.py b/bin/doins.py
index 6bc30c90b..8de480e81 100644
--- a/bin/doins.py
+++ b/bin/doins.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
diff --git a/bin/ebuild b/bin/ebuild
index 460aa0fd1..fbc6ad177 100755
--- a/bin/ebuild
+++ b/bin/ebuild
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py
index d68d3f05e..02b59f5ef 100755
--- a/bin/ebuild-ipc.py
+++ b/bin/ebuild-ipc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2010-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
diff --git a/bin/egencache b/bin/egencache
index d172319f8..6fb2fe0fe 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2009-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/emaint b/bin/emaint
index df904f7c0..d07e0d022 100755
--- a/bin/emaint
+++ b/bin/emaint
@@ -1,4 +1,4 @@
-#!/usr/bin/python -b
+#!/usr/bin/env -S python -b
# Copyright 2005-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

diff --git a/bin/emerge b/bin/emerge
index e372f5e9e..08f92b