Gentoo Archives: gentoo-commits

From: "Michal Gorny (mgorny)" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: python-r1.eclass ChangeLog
Date: Mon, 29 Oct 2012 09:46:14
Message-Id: 20121029094603.D213B21600@flycatcher.gentoo.org
1 mgorny 12/10/29 09:46:03
2
3 Modified: python-r1.eclass ChangeLog
4 Log:
5 Introduce python_replicate_script(), to create copies of a Python script for all installed implementations.
6
7 Revision Changes Path
8 1.11 eclass/python-r1.eclass
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?rev=1.11&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?rev=1.11&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?r1=1.10&r2=1.11
13
14 Index: python-r1.eclass
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v
17 retrieving revision 1.10
18 retrieving revision 1.11
19 diff -u -r1.10 -r1.11
20 --- python-r1.eclass 29 Oct 2012 09:25:04 -0000 1.10
21 +++ python-r1.eclass 29 Oct 2012 09:46:03 -0000 1.11
22 @@ -1,6 +1,6 @@
23 # Copyright 1999-2012 Gentoo Foundation
24 # Distributed under the terms of the GNU General Public License v2
25 -# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.10 2012/10/29 09:25:04 mgorny Exp $
26 +# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.11 2012/10/29 09:46:03 mgorny Exp $
27
28 # @ECLASS: python-r1
29 # @MAINTAINER:
30 @@ -412,3 +412,129 @@
31 debug-print "${FUNCNAME}: Best implementation is: ${impl}"
32 python_export "${impl}" "${@}"
33 }
34 +
35 +# @FUNCTION: _python_rewrite_shebang
36 +# @INTERNAL
37 +# @USAGE: [<EPYTHON>] <path>...
38 +# @DESCRIPTION:
39 +# Replaces 'python' executable in the shebang with the executable name
40 +# of the specified interpreter. If no EPYTHON value (implementation) is
41 +# used, the current ${EPYTHON} will be used.
42 +#
43 +# All specified files must start with a 'python' shebang. A file not
44 +# having a matching shebang will be refused. The exact shebang style
45 +# will be preserved in order not to break anything.
46 +#
47 +# Example conversions:
48 +# @CODE
49 +# From: #!/usr/bin/python -R
50 +# To: #!/usr/bin/python2.7 -R
51 +#
52 +# From: #!/usr/bin/env FOO=bar python
53 +# To: #!/usr/bin/env FOO=bar python2.7
54 +# @CODE
55 +_python_rewrite_shebang() {
56 + debug-print-function ${FUNCNAME} "${@}"
57 +
58 + local impl
59 + case "${1}" in
60 + python*|jython*|pypy-c*)
61 + impl=${1}
62 + shift
63 + ;;
64 + *)
65 + impl=${EPYTHON}
66 + [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
67 + ;;
68 + esac
69 + debug-print "${FUNCNAME}: implementation: ${impl}"
70 +
71 + local f
72 + for f; do
73 + local shebang=$(head -n 1 "${f}")
74 + debug-print "${FUNCNAME}: path = ${f}"
75 + debug-print "${FUNCNAME}: shebang = ${shebang}"
76 +
77 + if [[ "${shebang} " != *'python '* ]]; then
78 + eerror "A file does not seem to have a supported shebang:"
79 + eerror " file: ${f}"
80 + eerror " shebang: ${shebang}"
81 + die "${FUNCNAME}: ${f} does not seem to have a valid shebang"
82 + fi
83 +
84 + sed -i -e "s:python:${impl}:" "${f}" || die
85 + done
86 +}
87 +
88 +# @FUNCTION: _python_ln_rel
89 +# @USAGE: <from> <to>
90 +# @DESCRIPTION:
91 +# Create a relative symlink.
92 +_python_ln_rel() {
93 + debug-print-function ${FUNCNAME} "${@}"
94 +
95 + local from=${1}
96 + local to=${2}
97 +
98 + local frpath=${from%/*}/
99 + local topath=${to%/*}/
100 + local rel_path=
101 +
102 + # remove double slashes
103 + frpath=${frpath/\/\///}
104 + topath=${topath/\/\///}
105 +
106 + while [[ ${topath} ]]; do
107 + local frseg=${frpath%%/*}
108 + local toseg=${topath%%/*}
109 +
110 + if [[ ${frseg} != ${toseg} ]]; then
111 + rel_path=../${rel_path}${frseg:+${frseg}/}
112 + fi
113 +
114 + frpath=${frpath#${frseg}/}
115 + topath=${topath#${toseg}/}
116 + done
117 + rel_path+=${frpath}${1##*/}
118 +
119 + debug-print "${FUNCNAME}: ${from} -> ${to}"
120 + debug-print "${FUNCNAME}: rel_path = ${rel_path}"
121 +
122 + ln -fs "${rel_path}" "${to}"
123 +}
124 +
125 +# @FUNCTION: python_replicate_script
126 +# @USAGE: <path>...
127 +# @DESCRIPTION:
128 +# Copy the given script to variants for all enabled Python
129 +# implementations, then replace it with a symlink to the wrapper.
130 +#
131 +# All specified files must start with a 'python' shebang. A file not
132 +# having a matching shebang will be refused.
133 +python_replicate_script() {
134 + debug-print-function ${FUNCNAME} "${@}"
135 +
136 + local suffixes=()
137 +
138 + _add_suffix() {
139 + suffixes+=( "${EPYTHON}" )
140 + }
141 + python_foreach_impl _add_suffix
142 + debug-print "${FUNCNAME}: suffixes = ( ${suffixes[@]} )"
143 +
144 + local f suffix
145 + for suffix in "${suffixes[@]}"; do
146 + for f; do
147 + local newf=${f}-${suffix}
148 +
149 + debug-print "${FUNCNAME}: ${f} -> ${newf}"
150 + cp "${f}" "${newf}" || die
151 + done
152 +
153 + _python_rewrite_shebang "${suffix}" "${@/%/-${suffix}}"
154 + done
155 +
156 + for f; do
157 + _python_ln_rel "${ED}"/usr/bin/python-exec "${f}" || die
158 + done
159 +}
160
161
162
163 1.477 eclass/ChangeLog
164
165 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.477&view=markup
166 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.477&content-type=text/plain
167 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?r1=1.476&r2=1.477
168
169 Index: ChangeLog
170 ===================================================================
171 RCS file: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v
172 retrieving revision 1.476
173 retrieving revision 1.477
174 diff -u -r1.476 -r1.477
175 --- ChangeLog 29 Oct 2012 09:25:04 -0000 1.476
176 +++ ChangeLog 29 Oct 2012 09:46:03 -0000 1.477
177 @@ -1,6 +1,10 @@
178 # ChangeLog for eclass directory
179 # Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2
180 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.476 2012/10/29 09:25:04 mgorny Exp $
181 +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.477 2012/10/29 09:46:03 mgorny Exp $
182 +
183 + 29 Oct 2012; Michał Górny <mgorny@g.o> python-r1.eclass:
184 + Introduce python_replicate_script(), to create copies of a Python script for
185 + all installed implementations.
186
187 29 Oct 2012; Michał Górny <mgorny@g.o> python-r1.eclass:
188 Introduce python_export_best() to obtain variables for the most preferred