Gentoo Archives: gentoo-python

From: Brian Harring <ferringb@×××××.com>
To: Micha?? G??rny <mgorny@g.o>
Cc: Mike Gilbert <floppym@g.o>, gentoo-python@l.g.o
Subject: Re: [gentoo-python] Re: [PATCH eselect-python 1/2] Store per-version interpreter preference in a file as well.
Date: Thu, 01 Nov 2012 22:42:29
Message-Id: 20121101224242.GE3299@localhost
In Reply to: Re: [gentoo-python] Re: [PATCH eselect-python 1/2] Store per-version interpreter preference in a file as well. by "Michał Górny"
1 On Thu, Nov 01, 2012 at 10:27:19PM +0100, Micha?? G??rny wrote:
2 > On Thu, 1 Nov 2012 14:48:55 -0400
3 > Mike Gilbert <floppym@g.o> wrote:
4 >
5 > > On Thu, Nov 1, 2012 at 11:44 AM, Mike Gilbert <floppymaster@×××××.com> wrote:
6 > > > On Thu, Nov 1, 2012 at 7:54 AM, Micha?? G??rny <mgorny@g.o> wrote:
7 > > >> The idea is very simple: /etc/env.d/python/python[23] with a one-line
8 > > >> value similar to the main interpreter /config file.
9 > > >>
10 > > >> That should be simpler & more reliable than reading a symlink. And at
11 > > >> some point we can replace the symlink with an $EPYTHON-aware wrapper
12 > > >> as well.
13 > > >
14 > > > I don't understand the point of this. Do we have some need to enable
15 > > > EPYTHON usages for scripts that have a python2 or python3 shebang?
16 > > >
17 > > > I also don't understand how a text file is more reliable than a
18 > > > symlink; they are basically the same thing, but the symlink has a
19 > > > different file mode.
20 >
21 > Ah, and I'd forget. I have the following dream:
22 >
23 > /etc/env.d/python/python2
24 > /etc/env.d/python/python3
25 > /etc/env.d/python/config -> python2
26 >
27 > So, python{2,3} keep the per-version interpreters, and config is just
28 > a symlink to one of them. Two bird with one stone -- readlink to get
29 > which group is enabled, cat to get the exact interpreter. I'm proud
30 > of myself!
31
32 I too have a dream; git://pkgcore.org/eslect-python .
33
34 That's a shebang based version of what I proposed a while back. It
35 works now and has tests. It's written to be basically a drop in for
36 existing python.eclass generation of shebangs, w/ the
37 hardlinking/de-duplication/farking-fast/fix python3.2
38 /usr/bin/sphinx-build scenario.
39
40 The remaining work for that is thus:
41
42 1) If the EPYTHON targets aren't given via shebang arg, then it needs
43 to fallback to grabbing the targets from the file (easy enough).
44
45 2) Add a few helpers/wrappers to make it easier to do the
46 deduplication/shebang rewriting.
47
48 Frankly, you should be looking at this imo, rather than trying
49 standalone files. Yes, files is simpler- but you'll wind up sooner or
50 later rebuilding it into what I already built out here.
51
52 Either way, will let the commit message speak for it:
53
54 """
55 Add a python-shebang utility, slave python-wrapper to it.
56
57 Going forward, the intent is to push the PYTHON_ABIs of a given
58 script down into it's shebang, pointing the shebang at python-shebang.
59
60 In this way, all known/supported abi's are available at the time of
61 execution; further, if the target is told to respect-EPYTHON (meaning
62 no searching for something to execute, either active python version or
63 EPYTHON var), we can push this down into that list and have that code
64 handle it.
65
66 Using sphinx-build as an example, we go from the current setup of:
67 echo > sphinx-build-2.7 <<EOF
68 #!/usr/bin/python2.7
69 <code>
70 EOF
71
72 echo > sphinx-build-3.2 <<EOF
73 #!/usr/bin/python3.2
74 <code>
75 EOF
76
77 echo > sphinx-build << EOF
78 #!/usr/bin/env python
79 <python wrapper code to decide which of the above to execute>
80 EOF
81
82 to the simpler form of:
83 for x in sphinx{,-{2.7,3.2}}; do echo > $x <<EOF
84 #!/usr/bin/python-shebang python2.7,python3.2
85 <code>
86 EOF
87 done
88
89 The gains of this are thus:
90
91 1) This simplifies the pypy EPYTHON->script_name parsing code; since
92 we have the list of PYTHON_ABIs available at the script level, we
93 can use that info to map it directly (thus we don't have to update
94 that code till pypy changes their interp name).
95
96 2) Measurably faster implementation; minimally, via moving this to
97 c we're not paying the VM overhead that the current wrapper solution
98 requires; further, via accessing the underlying python config file,
99 we can get the active version without spawning bash (the python.eclass
100 wrapper solution semi-validly doesn't do this since the given wrapper
101 isn't part of eselect-python; python-shebang is, thus we can do the
102 faster path). The code will still fallback to eselect python show as
103 a protective measure, but that pathway should never be executed
104 realistically.
105
106 3) Via this approach, we can do de-duplication of the versioned
107 scripts; since each (including the versioned forms) carry the
108 python ABIs as an argument, their content is identical- so we can just
109 hardlink them together (which the code looks for and exploits to avoid
110 a double exec, instead exec'ing directly to the target).
111
112 4) The underlying python-wrapper in turn, just becomes a dumb re-exec
113 to `python-shebang ACTIVE_PYTHON`- a special mode of python-shebang,
114 which is essentially respect-EPYTHON, while defaulting EPYTHON to
115 the active python version. Single implementation basically.
116
117 5) java-config-2's jython cycle can be explicitly broken by the script itself
118 now; since the script now specifies the ABIs it targets, java-config-2's shebang
119 just would drop jython2.5 from the list of targets. Via this, on a system that
120 has jython2.5 as the active interp, when it goes to invoke java-config-2 (a necessary
121 step to actually start the jython interp itself) it would use an implementation other
122 than jython2.5- no fork bomb/exec cycle.
123
124 6) python3.2 sphinx-build now does the correct thing- execute sphinx-build-3.2, even
125 if the active is python2.7.
126 """

Replies