Gentoo Archives: gentoo-python

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

Replies