unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Hartmut Goebel <h.goebel@crazy-compilers.com>
To: guix-devel@gnu.org
Subject: Re: avoid wrapper scripts when possible
Date: Sat, 4 Nov 2017 11:12:30 +0100	[thread overview]
Message-ID: <9ccb6232-ded3-9399-9314-91644db7d89e@crazy-compilers.com> (raw)
In-Reply-To: <87mv44gyfv.fsf@elephly.net>

Hallo Ricardo,

Am 02.11.2017 um 22:31 schrieb Ricardo Wurmus:
> This made me wonder if we could avoid shell wrappers in more cases.

This is an interesting challenge :-)

> If
> the target script is a Python script we could set the environment
> variables right after the Python shebang with Python code.  If the
> target script is a shell script we can set environment variables right
> there after the shebang.

Basically thsi would be a good solution IMO. But I'm afraid it might be
complicated to insert the code "right after the […] shebang". For
example Python has "doc-strings" [1], this is: if the first statement of
the script is a string (expression statement), this string is put into
the variable __doc__. So for at least for Python we might need a
language-aware scanner to insert the code at the correct position. We
might need similar tor other languages.

But taking your challenge :-) I had another idea which should work for
all script languages:

The real script's she-bang delegates to the wrapper (instead of
/bin/sh), which execs "interpreter $0". Here is a proof on concept:

....8<------- real.py
#!/tmp/wrapper.sh
print("This is real")
import sys, os
print("sys.path[:2]", sys.path[:2])
print("argumentes:", sys.argv)
print("ppid", os.getppid())
....8<-------

....8<-------  wrapper.sh
#!/bin/sh
echo "This is the wrapper"
echo "arguments in wrapper:" "$@"
echo "ppid:" $PPID
export PYTHONPATH=/foo/bar
exec python3 /tmp/real.py "${@:2}" # <- replace first argument by full path
....8<-------

I have to admit that this still adds another script and is less elegant,
but should be easier to implement.

[]1] https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |

  parent reply	other threads:[~2017-11-04 10:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 21:31 avoid wrapper scripts when possible Ricardo Wurmus
2017-11-03 18:54 ` Christopher Baines
2017-11-03 19:22   ` Jan Nieuwenhuizen
2017-11-03 21:17   ` Ricardo Wurmus
     [not found]     ` <874lqbghlz.fsf@elephly.net>
2017-11-03 22:41       ` Ricardo Wurmus
2017-11-05 11:10     ` Hartmut Goebel
2017-11-04 21:42   ` Eric Bavier
2017-11-04 10:12 ` Hartmut Goebel [this message]
     [not found]   ` <87tvy9ptge.fsf@elephly.net>
2017-11-05 11:00     ` Hartmut Goebel
2017-11-05 17:06       ` Ludovic Courtès
2017-11-06 15:53 ` Dave Love
  -- strict thread matches above, loose matches on Subject: below --
2021-09-07 18:52 Attila Lendvai
2021-09-07 20:41 ` Maxime Devos
2021-09-08  9:20   ` Attila Lendvai
2021-09-08 10:39     ` Maxime Devos
2021-09-24 21:38 John Kehayias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ccb6232-ded3-9399-9314-91644db7d89e@crazy-compilers.com \
    --to=h.goebel@crazy-compilers.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).