1 |
mgorny 14/05/26 16:13:35 |
2 |
|
3 |
Modified: ChangeLog python-r1.eclass python-single-r1.eclass |
4 |
python-utils-r1.eclass |
5 |
Log: |
6 |
Move python_fix_shebang into python-utils-r1, therefore making it a part of public API for all eclasses. |
7 |
|
8 |
Revision Changes Path |
9 |
1.1274 eclass/ChangeLog |
10 |
|
11 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1274&view=markup |
12 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1274&content-type=text/plain |
13 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?r1=1.1273&r2=1.1274 |
14 |
|
15 |
Index: ChangeLog |
16 |
=================================================================== |
17 |
RCS file: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v |
18 |
retrieving revision 1.1273 |
19 |
retrieving revision 1.1274 |
20 |
diff -u -r1.1273 -r1.1274 |
21 |
--- ChangeLog 24 May 2014 08:48:40 -0000 1.1273 |
22 |
+++ ChangeLog 26 May 2014 16:13:35 -0000 1.1274 |
23 |
@@ -1,6 +1,11 @@ |
24 |
# ChangeLog for eclass directory |
25 |
# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 |
26 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1273 2014/05/24 08:48:40 ulm Exp $ |
27 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1274 2014/05/26 16:13:35 mgorny Exp $ |
28 |
+ |
29 |
+ 26 May 2014; Michał Górny <mgorny@g.o> python-r1.eclass, |
30 |
+ python-single-r1.eclass, python-utils-r1.eclass: |
31 |
+ Move python_fix_shebang into python-utils-r1, therefore making it a part of |
32 |
+ public API for all eclasses. |
33 |
|
34 |
24 May 2014; Ulrich Müller <ulm@g.o> elisp-common.eclass: |
35 |
elisp-site-regen: Look for site-init files only in site-gentoo.d |
36 |
|
37 |
|
38 |
|
39 |
1.73 eclass/python-r1.eclass |
40 |
|
41 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?rev=1.73&view=markup |
42 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?rev=1.73&content-type=text/plain |
43 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-r1.eclass?r1=1.72&r2=1.73 |
44 |
|
45 |
Index: python-r1.eclass |
46 |
=================================================================== |
47 |
RCS file: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v |
48 |
retrieving revision 1.72 |
49 |
retrieving revision 1.73 |
50 |
diff -u -r1.72 -r1.73 |
51 |
--- python-r1.eclass 19 Apr 2014 10:29:06 -0000 1.72 |
52 |
+++ python-r1.eclass 26 May 2014 16:13:35 -0000 1.73 |
53 |
@@ -1,6 +1,6 @@ |
54 |
# Copyright 1999-2014 Gentoo Foundation |
55 |
# Distributed under the terms of the GNU General Public License v2 |
56 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.72 2014/04/19 10:29:06 mgorny Exp $ |
57 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.73 2014/05/26 16:13:35 mgorny Exp $ |
58 |
|
59 |
# @ECLASS: python-r1 |
60 |
# @MAINTAINER: |
61 |
@@ -783,6 +783,8 @@ |
62 |
debug-print-function ${FUNCNAME} "${@}" |
63 |
|
64 |
_python_replicate_script() { |
65 |
+ local _PYTHON_FIX_SHEBANG_QUIET=1 |
66 |
+ |
67 |
if _python_want_python_exec2; then |
68 |
local PYTHON_SCRIPTDIR |
69 |
python_export PYTHON_SCRIPTDIR |
70 |
@@ -792,7 +794,7 @@ |
71 |
doexe "${files[@]}" |
72 |
) |
73 |
|
74 |
- _python_rewrite_shebang "${EPYTHON}" \ |
75 |
+ python_fix_shebang \ |
76 |
"${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}" |
77 |
else |
78 |
local f |
79 |
@@ -800,7 +802,7 @@ |
80 |
cp -p "${f}" "${f}-${EPYTHON}" || die |
81 |
done |
82 |
|
83 |
- _python_rewrite_shebang "${EPYTHON}" \ |
84 |
+ python_fix_shebang \ |
85 |
"${files[@]/%/-${EPYTHON}}" |
86 |
fi |
87 |
} |
88 |
|
89 |
|
90 |
|
91 |
1.26 eclass/python-single-r1.eclass |
92 |
|
93 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-single-r1.eclass?rev=1.26&view=markup |
94 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-single-r1.eclass?rev=1.26&content-type=text/plain |
95 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-single-r1.eclass?r1=1.25&r2=1.26 |
96 |
|
97 |
Index: python-single-r1.eclass |
98 |
=================================================================== |
99 |
RCS file: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v |
100 |
retrieving revision 1.25 |
101 |
retrieving revision 1.26 |
102 |
diff -u -r1.25 -r1.26 |
103 |
--- python-single-r1.eclass 30 Nov 2013 17:57:11 -0000 1.25 |
104 |
+++ python-single-r1.eclass 26 May 2014 16:13:35 -0000 1.26 |
105 |
@@ -1,6 +1,6 @@ |
106 |
-# Copyright 1999-2013 Gentoo Foundation |
107 |
+# Copyright 1999-2014 Gentoo Foundation |
108 |
# Distributed under the terms of the GNU General Public License v2 |
109 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.25 2013/11/30 17:57:11 floppym Exp $ |
110 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.26 2014/05/26 16:13:35 mgorny Exp $ |
111 |
|
112 |
# @ECLASS: python-single-r1 |
113 |
# @MAINTAINER: |
114 |
@@ -261,49 +261,5 @@ |
115 |
python_setup |
116 |
} |
117 |
|
118 |
-# @FUNCTION: python_fix_shebang |
119 |
-# @USAGE: <path>... |
120 |
-# @DESCRIPTION: |
121 |
-# Replace the shebang in Python scripts with the current Python |
122 |
-# implementation (EPYTHON). If a directory is passed, works recursively |
123 |
-# on all Python scripts. |
124 |
-# |
125 |
-# Only files having a 'python' shebang will be modified; other files |
126 |
-# will be skipped. If a script has a complete shebang matching |
127 |
-# the chosen interpreter version, it is left unmodified. If a script has |
128 |
-# a complete shebang matching other version, the command dies. |
129 |
-python_fix_shebang() { |
130 |
- debug-print-function ${FUNCNAME} "${@}" |
131 |
- |
132 |
- [[ ${1} ]] || die "${FUNCNAME}: no paths given" |
133 |
- [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)" |
134 |
- |
135 |
- local path f |
136 |
- for path; do |
137 |
- while IFS= read -r -d '' f; do |
138 |
- local shebang=$(head -n 1 "${f}") |
139 |
- |
140 |
- case "${shebang}" in |
141 |
- '#!'*${EPYTHON}*) |
142 |
- debug-print "${FUNCNAME}: in file ${f#${D}}" |
143 |
- debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}" |
144 |
- ;; |
145 |
- '#!'*python[23].[0123456789]*|'#!'*pypy-c*|'#!'*jython*) |
146 |
- debug-print "${FUNCNAME}: in file ${f#${D}}" |
147 |
- debug-print "${FUNCNAME}: incorrect specific shebang: ${shebang}" |
148 |
- |
149 |
- die "${f#${D}} has a specific Python shebang not matching EPYTHON" |
150 |
- ;; |
151 |
- '#!'*python*) |
152 |
- debug-print "${FUNCNAME}: in file ${f#${D}}" |
153 |
- debug-print "${FUNCNAME}: rewriting shebang: ${shebang}" |
154 |
- |
155 |
- einfo "Fixing shebang in ${f#${D}}" |
156 |
- _python_rewrite_shebang "${f}" |
157 |
- esac |
158 |
- done < <(find "${path}" -type f -print0) |
159 |
- done |
160 |
-} |
161 |
- |
162 |
_PYTHON_SINGLE_R1=1 |
163 |
fi |
164 |
|
165 |
|
166 |
|
167 |
1.56 eclass/python-utils-r1.eclass |
168 |
|
169 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-utils-r1.eclass?rev=1.56&view=markup |
170 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-utils-r1.eclass?rev=1.56&content-type=text/plain |
171 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python-utils-r1.eclass?r1=1.55&r2=1.56 |
172 |
|
173 |
Index: python-utils-r1.eclass |
174 |
=================================================================== |
175 |
RCS file: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v |
176 |
retrieving revision 1.55 |
177 |
retrieving revision 1.56 |
178 |
diff -u -r1.55 -r1.56 |
179 |
--- python-utils-r1.eclass 16 May 2014 07:54:40 -0000 1.55 |
180 |
+++ python-utils-r1.eclass 26 May 2014 16:13:35 -0000 1.56 |
181 |
@@ -1,6 +1,6 @@ |
182 |
# Copyright 1999-2014 Gentoo Foundation |
183 |
# Distributed under the terms of the GNU General Public License v2 |
184 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v 1.55 2014/05/16 07:54:40 mgorny Exp $ |
185 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v 1.56 2014/05/26 16:13:35 mgorny Exp $ |
186 |
|
187 |
# @ECLASS: python-utils-r1 |
188 |
# @MAINTAINER: |
189 |
@@ -478,79 +478,6 @@ |
190 |
echo "${PYTHON_SCRIPTDIR}" |
191 |
} |
192 |
|
193 |
-# @FUNCTION: _python_rewrite_shebang |
194 |
-# @USAGE: [<EPYTHON>] <path>... |
195 |
-# @INTERNAL |
196 |
-# @DESCRIPTION: |
197 |
-# Replaces 'python' executable in the shebang with the executable name |
198 |
-# of the specified interpreter. If no EPYTHON value (implementation) is |
199 |
-# used, the current ${EPYTHON} will be used. |
200 |
-# |
201 |
-# All specified files must start with a 'python' shebang. A file not |
202 |
-# having a matching shebang will be refused. The exact shebang style |
203 |
-# will be preserved in order not to break anything. |
204 |
-# |
205 |
-# Example conversions: |
206 |
-# @CODE |
207 |
-# From: #!/usr/bin/python -R |
208 |
-# To: #!/usr/bin/python2.7 -R |
209 |
-# |
210 |
-# From: #!/usr/bin/env FOO=bar python |
211 |
-# To: #!/usr/bin/env FOO=bar python2.7 |
212 |
-# @CODE |
213 |
-_python_rewrite_shebang() { |
214 |
- debug-print-function ${FUNCNAME} "${@}" |
215 |
- |
216 |
- local impl |
217 |
- case "${1}" in |
218 |
- python*|jython*|pypy*) |
219 |
- impl=${1} |
220 |
- shift |
221 |
- ;; |
222 |
- *) |
223 |
- impl=${EPYTHON} |
224 |
- [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON" |
225 |
- ;; |
226 |
- esac |
227 |
- debug-print "${FUNCNAME}: implementation: ${impl}" |
228 |
- |
229 |
- local f |
230 |
- for f; do |
231 |
- local from shebang |
232 |
- read -r shebang < "${f}" |
233 |
- shebang=${shebang%$'\r'} |
234 |
- debug-print "${FUNCNAME}: path = ${f}" |
235 |
- debug-print "${FUNCNAME}: shebang = ${shebang}" |
236 |
- |
237 |
- if [[ "${shebang} " == *"${impl} "* ]]; then |
238 |
- # skip files with correct impl |
239 |
- continue |
240 |
- elif [[ "${shebang} " == *'python '* ]]; then |
241 |
- from=python |
242 |
- elif [[ "${shebang} " == *'python2 '* ]]; then |
243 |
- from=python2 |
244 |
- elif [[ "${shebang} " == *'python3 '* ]]; then |
245 |
- from=python3 |
246 |
- else |
247 |
- eerror "A file does not seem to have a supported shebang:" |
248 |
- eerror " file: ${f}" |
249 |
- eerror " shebang: ${shebang}" |
250 |
- die "${FUNCNAME}: ${f} does not seem to have a valid shebang" |
251 |
- fi |
252 |
- |
253 |
- if { [[ ${from} == python2 ]] && python_is_python3 "${impl}"; } \ |
254 |
- || { [[ ${from} == python3 ]] && ! python_is_python3 "${impl}"; } then |
255 |
- eerror "A file does have shebang not supporting requested impl:" |
256 |
- eerror " file: ${f}" |
257 |
- eerror " shebang: ${shebang}" |
258 |
- eerror " impl: ${impl}" |
259 |
- die "${FUNCNAME}: ${f} does have shebang not supporting ${EPYTHON}" |
260 |
- fi |
261 |
- |
262 |
- sed -i -e "1s:${from}:${impl}:" "${f}" || die |
263 |
- done |
264 |
-} |
265 |
- |
266 |
# @FUNCTION: _python_ln_rel |
267 |
# @USAGE: <from> <to> |
268 |
# @INTERNAL |
269 |
@@ -743,7 +670,8 @@ |
270 |
|
271 |
# don't use this at home, just call python_doscript() instead |
272 |
if [[ ${_PYTHON_REWRITE_SHEBANG} ]]; then |
273 |
- _python_rewrite_shebang "${ED%/}/${d}/${newfn}" |
274 |
+ local _PYTHON_FIX_SHEBANG_QUIET=1 |
275 |
+ python_fix_shebang "${ED%/}/${d}/${newfn}" |
276 |
fi |
277 |
} |
278 |
|
279 |
@@ -1006,6 +934,100 @@ |
280 |
[[ ${impl} == python3* ]] |
281 |
} |
282 |
|
283 |
+# @FUNCTION: python_fix_shebang |
284 |
+# @USAGE: <path>... |
285 |
+# @DESCRIPTION: |
286 |
+# Replace the shebang in Python scripts with the current Python |
287 |
+# implementation (EPYTHON). If a directory is passed, works recursively |
288 |
+# on all Python scripts. |
289 |
+# |
290 |
+# Only files having a 'python*' shebang will be modified. Files with |
291 |
+# other shebang will either be skipped when working recursively |
292 |
+# on a directory or treated as error when specified explicitly. |
293 |
+# |
294 |
+# Shebangs matching explicitly current Python version will be left |
295 |
+# unmodified. Shebangs requesting another Python version will be treated |
296 |
+# as fatal error. |
297 |
+python_fix_shebang() { |
298 |
+ debug-print-function ${FUNCNAME} "${@}" |
299 |
+ |
300 |
+ [[ ${1} ]] || die "${FUNCNAME}: no paths given" |
301 |
+ [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)" |
302 |
+ |
303 |
+ local path f |
304 |
+ for path; do |
305 |
+ local any_correct any_fixed is_recursive |
306 |
+ |
307 |
+ [[ -d ${path} ]] && is_recursive=1 |
308 |
+ |
309 |
+ while IFS= read -r -d '' f; do |
310 |
+ local shebang=$(head -n 1 "${f}") |
311 |
+ local error |
312 |
+ |
313 |
+ case "${shebang} " in |
314 |
+ '#!'*"${EPYTHON} "*) |
315 |
+ debug-print "${FUNCNAME}: in file ${f#${D}}" |
316 |
+ debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}" |
317 |
+ |
318 |
+ # Nothing to do, move along. |
319 |
+ any_correct=1 |
320 |
+ ;; |
321 |
+ '#!'*python" "*|'#!'*python[23]" "*) |
322 |
+ debug-print "${FUNCNAME}: in file ${f#${D}}" |
323 |
+ debug-print "${FUNCNAME}: rewriting shebang: ${shebang}" |
324 |
+ |
325 |
+ # Note: for internal use. |
326 |
+ if [[ ! ${_PYTHON_FIX_SHEBANG_QUIET} ]]; then |
327 |
+ einfo "Fixing shebang in ${f#${D}}." |
328 |
+ fi |
329 |
+ |
330 |
+ local from |
331 |
+ if [[ "${shebang} " == *'python2 '* ]]; then |
332 |
+ from=python2 |
333 |
+ python_is_python3 "${EPYTHON}" && error=1 |
334 |
+ elif [[ "${shebang} " == *'python3 '* ]]; then |
335 |
+ from=python3 |
336 |
+ python_is_python3 "${EPYTHON}" || error=1 |
337 |
+ else |
338 |
+ from=python |
339 |
+ fi |
340 |
+ |
341 |
+ if [[ ! ${error} ]]; then |
342 |
+ sed -i -e "1s:${from}:${EPYTHON}:" "${f}" || die |
343 |
+ any_fixed=1 |
344 |
+ fi |
345 |
+ ;; |
346 |
+ '#!'*python[23].[0123456789]" "*|'#!'*pypy" "*|'#!'*jython[23].[0123456789]" "*) |
347 |
+ # Explicit mismatch. |
348 |
+ error=1 |
349 |
+ ;; |
350 |
+ *) |
351 |
+ # Non-Python shebang. Allowed in recursive mode, |
352 |
+ # disallowed when specifying file explicitly. |
353 |
+ [[ ${is_recursive} ]] || error=1 |
354 |
+ ;; |
355 |
+ esac |
356 |
+ |
357 |
+ if [[ ${error} ]]; then |
358 |
+ eerror "The file has incompatible shebang:" |
359 |
+ eerror " file: ${f#${D}}" |
360 |
+ eerror " current shebang: ${shebang}" |
361 |
+ eerror " requested impl: ${EPYTHON}" |
362 |
+ die "${FUNCNAME}: conversion of incompatible shebang requested" |
363 |
+ fi |
364 |
+ done < <(find "${path}" -type f -print0) |
365 |
+ |
366 |
+ if [[ ! ${any_fixed} ]]; then |
367 |
+ eqawarn "QA warning: ${FUNCNAME}, ${path#${D}} did not match any fixable files." |
368 |
+ if [[ ${any_correct} ]]; then |
369 |
+ eqawarn "All files have ${EPYTHON} shebang already." |
370 |
+ else |
371 |
+ eqawarn "There are no Python files in specified directory." |
372 |
+ fi |
373 |
+ fi |
374 |
+ done |
375 |
+} |
376 |
+ |
377 |
# @FUNCTION: _python_want_python_exec2 |
378 |
# @INTERNAL |
379 |
# @DESCRIPTION: |