From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hartmut Goebel Subject: Re: avoid wrapper scripts when possible Date: Sun, 5 Nov 2017 12:10:42 +0100 Message-ID: References: <87mv44gyfv.fsf@elephly.net> <20171103185416.0ffc4065@cbaines.net> <8760argizk.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------631FF527D0DE5A20F220722F" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBIpE-0000EG-R5 for guix-devel@gnu.org; Sun, 05 Nov 2017 06:10:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBIpB-0005NX-Ho for guix-devel@gnu.org; Sun, 05 Nov 2017 06:10:48 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:59886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBIpB-0005Mw-7c for guix-devel@gnu.org; Sun, 05 Nov 2017 06:10:45 -0500 In-Reply-To: <8760argizk.fsf@elephly.net> Content-Language: en-US List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org This is a multi-part message in MIME format. --------------631FF527D0DE5A20F220722F Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Ricado proposed a new and better solution already. Nevertheless I want to comment on this proposal, sint it includes a pitfall and would not wor= k: Am 03.11.2017 um 22:17 schrieb Ricardo Wurmus: > exec /home/rekado/.guix-profile/bin/python <(/run/current-system/profil= e/bin/tail -n +4 "$0") [...] > This seems to work just fine and off the top of my head I can=E2=80=99t= think of > a situation where this would fail =E2=80=94 unless the wrapped script p= erformed > the same kind of trick of reading its contents through $0. (How likely > is that?) Indeed for Python programs it is quite common to revert to the filename using the variable "__file__". And if feeding in the script from stdin would set __file__ to "". Using __file__ is more often used in package modules than in scripts (which could use $0 (sys.argv[0]). Anyway this is a pitfall we should avoid. Please not that Ricardo's new solution, based on guile and execl does not suffer from this problem (I verified). --=20 Regards Hartmut Goebel | Hartmut Goebel | h.goebel@crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | --------------631FF527D0DE5A20F220722F Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi,

Ricado proposed a new and better solution already. Nevertheless I want to comment on this proposal, sint it includes a pitfall and would not work:

Am 03.11.2017 um 22:17 schrieb Ricardo Wurmus:
exec /home/rekado/.guix-=
profile/bin/python <(/run/current-system/profile/bin/tail -n +4 "$0")<=
/pre>
    
[...]
This seems to work just fine and off the top of my h=
ead I can=E2=80=99t think of
a situation where this would fail =E2=80=94 unless the wrapped script per=
formed
the same kind of trick of reading its contents through $0.  (How likely
is that?)

Indeed for Python programs it is quite common to revert to the filename using the variable "__file__". And if feeding in the script from stdin would set __file__ to "<stdin>". Using __file__ is more often used in package modules than in scripts (which could use $0 (sys.argv[0]). Anyway this is a pitfall we should avoid.

Please not that Ricardo's new solution, based on guile and execl does not suffer from this problem (I verified).
--=20
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com   =
            |
| www.crazy-compilers.com | compilers which you thought are impo=
ssible |
--------------631FF527D0DE5A20F220722F--