Gentoo Archives: gentoo-python

From: Mike Gilbert <floppym@g.o>
To: gentoo-python@l.g.o
Subject: [gentoo-python] Re: [PATCH] Support converting python[23] shebangs.
Date: Tue, 01 Jan 2013 19:13:47
Message-Id: CAJ0EP40PRNvVMcxb4B2Qe3FQToGThJV56m=L+R8rZgP8fnSpkg@mail.gmail.com
In Reply to: [gentoo-python] [PATCH] Support converting python[23] shebangs. by "Michał Górny"
1 On Tue, Jan 1, 2013 at 1:47 PM, Michał Górny <mgorny@g.o> wrote:
2 > For now, I assume that python2 can be converted to Python2 impls
3 > implementations only, and python3 to Python3 impls.
4 >
5 > Fixes: https://bugs.gentoo.org/show_bug.cgi?id=449674
6 > ---
7 > gx86/eclass/python-utils-r1.eclass | 20 ++++++++++++++++++--
8 > 1 file changed, 18 insertions(+), 2 deletions(-)
9 >
10 > diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
11 > index fe7a3e4..165a383 100644
12 > --- a/gx86/eclass/python-utils-r1.eclass
13 > +++ b/gx86/eclass/python-utils-r1.eclass
14 > @@ -319,17 +319,33 @@ _python_rewrite_shebang() {
15 > local f
16 > for f; do
17 > local shebang=$(head -n 1 "${f}")
18 > + local from
19 > debug-print "${FUNCNAME}: path = ${f}"
20 > debug-print "${FUNCNAME}: shebang = ${shebang}"
21 >
22 > - if [[ "${shebang} " != *'python '* ]]; then
23 > + if [[ "${shebang} " == *'python '* ]]; then
24 > + from=python
25 > + elif [[ "${shebang} " == *'python2 '* ]]; then
26 > + from=python2
27 > + elif [[ "${shebang} " == *'python3 '* ]]; then
28 > + from=python3
29 > + else
30 > eerror "A file does not seem to have a supported shebang:"
31 > eerror " file: ${f}"
32 > eerror " shebang: ${shebang}"
33 > die "${FUNCNAME}: ${f} does not seem to have a valid shebang"
34 > fi
35 >
36 > - sed -i -e "1s:python:${impl}:" "${f}" || die
37 > + if [[ ${from} == python2 && ${impl} == python3*
38 > + || ${from} == python3 && ${impl} != python3* ]]; then
39 > + eerror "A file does have shebang not supporting requested impl:"
40 > + eerror " file: ${f}"
41 > + eerror " shebang: ${shebang}"
42 > + eerror " impl: ${impl}"
43 > + die "${FUNCNAME}: ${f} does have shebang not supporting ${EPYTHON}"
44 > + fi
45 > +
46 > + sed -i -e "1s:${from}:${impl}:" "${f}" || die
47 > done
48 > }
49 >
50 > --
51 > 1.8.0.2
52 >
53
54 Looks ok.