Gentoo Archives: gentoo-dev

From: Brian Harring <ferringb@×××××.com>
To: Mike Gilbert <floppym@g.o>
Cc: gentoo-dev@l.g.o, python@g.o
Subject: [gentoo-dev] Re: reworking python-wrapper and wrapper scripts.
Date: Thu, 18 Oct 2012 22:37:30
Message-Id: 20121018223713.GE2692@localhost.corp.google.com
In Reply to: [gentoo-dev] Re: reworking python-wrapper and wrapper scripts. by Mike Gilbert
1 On Thu, Oct 18, 2012 at 04:50:04PM -0400, Mike Gilbert wrote:
2 > On Thu, Oct 18, 2012 at 3:29 PM, Brian Harring <ferringb@×××××.com> wrote:
3 > > On Thu, Oct 18, 2012 at 11:28:59AM -0400, Mike Gilbert wrote:
4 > >> Regarding your /usr/bin/python3.2 /usr/bin/sphinx-build example:
5 > >> invoking python on a binary (or a symlink to a binary) isn't going to
6 > >> work at all. So I don't see how you've solved that issue.
7 > >
8 > > Kindly provide reasoning/justification for such a claim in the future-
9 > > saves a round of email ping/ponging, and saves me getting pissy
10 > > towards people if they persist in it. :)
11 > >
12 > > Lecture aside, "nuh uh, it does work!" is appropriate. I already
13 > > hacked up a prototype locally that works fine and does this via an
14 > > env passing hack- w/ what was proposed, this can be done w/out those
15 > > hacks, and would be faster.
16 > >
17 >
18 > When you invoke a command like:
19 >
20 > /usr/bin/python3.2 /usr/bin/somebinary
21 >
22 > The python3.2 program assumes somebinary is a python script and tries
23 > to parse it. Since somebinary is actually an ELF object, python bombs
24 > out immediately.
25 >
26 > Am I missing something fundamental here?
27
28 Nope, you've got me embarassingly, absolutely fricking dead to rights
29 on that one; I overlooked at the prototype I did was a python script
30 for 'somebinary', which worked via the env passing.
31
32 Would've spotted it upon implementing it in c to say the least, but
33 still, *cough*. ;)
34
35 As you mentioned in a separate email; if we stick a wrapper in front
36 of the python binaries, that would fly; I don't much like that
37 however.
38
39 Offhand... and this makes it a bit more complex, but still tenuable
40 imo, but we could get around this via shoving the symlink pathway into
41 the shebang itself.
42
43 scenario 1:
44 Script gets installed for 2.7, 3.1, 3.2; ignoring the shebang, it's
45 exactly the same md5 (meaning we can dedup it). The shebang instead
46 of being /usr/bin/python-whatever, instead is the symlink pathway I'd
47 referenced. Meaning it would be
48 /usr/libexec/python/2.7/3.1/3.2/wrapper . If that script was
49 sphinx-build, this means that sphinx-build{,-{2.7,3.1,3.2}} are all
50 valid python scripts- they can be invoked either via /path/to/script
51 or ${python} /path/to/script. There's a few details to sort there,
52 but nothing egregious best I can tell- implicit in this proposal is
53 that the wrapper would be smart enough to tell in which context it's
54 being invoked (sphinx-build vs sphinx-build-2.7).
55
56 Scenario 2:
57 2.7, 3.1, 3.2 are in play; they do /not/ dedupe to the same content,
58 meaning we actually need indirection in 'sphinx-build' (but not
59 sphinx-build-{2.7,3.1,3.2} although we would dedupe where possible
60 mind you).
61
62 In that case, to support python3.2 sphinx-build, we'd need a python
63 script that does the searching/re-exec for the wrapper. This can be
64 standardized- just have it search for sphinx-build-${PYTHON_ABIS} to
65 identify the installed versions, then do the usual active
66 version/epython trick to decide which to use. This honestly isn't too
67 far off from what we have now.
68
69 We can however optimize that; same trick, for the wrapper the shebang
70 isn't /usr/bin/python; it's just a c version of the python script,
71 done in c for speed.
72
73 So... caveats. If we screw w/ the shebang like this, file isn't going
74 to like it- it'll fail to identify certain scripts as python. That
75 said, it's worth keeping in mind that if we use the symlink route, a
76 file /usr/bin/sphinx-build would result in ELF, vs file
77 /usr/bin/sphinx-build-2.7 being python.
78
79 This can be fixed via an additional rule added to the magic db.
80 Pretty straight forward, and eselect-python (once it gets these
81 wrappers) could level an appropriate dep to ensure that's sorted.
82
83 So... my preference is shebang; it's basically an extension of the
84 symlink trick I'd originally mentioned, just cleaner imo.
85
86 What are folks thoughts on that?
87 ~harring

Replies

Subject Author
Re: [gentoo-dev] Re: reworking python-wrapper and wrapper scripts. "Michał Górny" <mgorny@g.o>