1 |
arfrever 10/02/28 11:48:41 |
2 |
|
3 |
Modified: python.eclass |
4 |
Log: |
5 |
Define phase functions always in packages supporting installation for multiple versions of Python. Export phase functions when PYTHON_DEFINE_DEFAULT_FUNCTIONS is defined. |
6 |
Extract sanity checks from validate_PYTHON_ABIS() to _python_initial_sanity_checks() and _python_final_sanity_checks(). |
7 |
Support --final-ABI option of python_execute_function(). |
8 |
Extract setting of color variables to _python_set_color_variables(). |
9 |
Simplify python_copy_sources() by not supporting --no-link option and always creating real copies of files. |
10 |
Call _python_initial_sanity_checks() and _python_final_sanity_checks() in python_set_active_version(). |
11 |
Simplify PYTHON() by not supporting --active option. |
12 |
Deprecate python_tkinter_exists(). |
13 |
|
14 |
Revision Changes Path |
15 |
1.90 eclass/python.eclass |
16 |
|
17 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.90&view=markup |
18 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.90&content-type=text/plain |
19 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?r1=1.89&r2=1.90 |
20 |
|
21 |
Index: python.eclass |
22 |
=================================================================== |
23 |
RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v |
24 |
retrieving revision 1.89 |
25 |
retrieving revision 1.90 |
26 |
diff -u -r1.89 -r1.90 |
27 |
--- python.eclass 14 Feb 2010 18:53:11 -0000 1.89 |
28 |
+++ python.eclass 28 Feb 2010 11:48:40 -0000 1.90 |
29 |
@@ -1,6 +1,6 @@ |
30 |
# Copyright 1999-2010 Gentoo Foundation |
31 |
# Distributed under the terms of the GNU General Public License v2 |
32 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.89 2010/02/14 18:53:11 arfrever Exp $ |
33 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.90 2010/02/28 11:48:40 arfrever Exp $ |
34 |
|
35 |
# @ECLASS: python.eclass |
36 |
# @MAINTAINER: |
37 |
@@ -263,11 +263,11 @@ |
38 |
# Set this in EAPI <= 4 to indicate that current package supports installation for |
39 |
# multiple versions of Python. |
40 |
|
41 |
-# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
42 |
+# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS |
43 |
# @DESCRIPTION: |
44 |
-# Set this to define default functions for the following ebuild phases: |
45 |
+# Set this to export phase functions for the following ebuild phases: |
46 |
# src_prepare, src_configure, src_compile, src_test, src_install. |
47 |
-if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
48 |
+if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
49 |
python_src_prepare() { |
50 |
python_copy_sources |
51 |
} |
52 |
@@ -277,11 +277,12 @@ |
53 |
done |
54 |
unset python_default_function |
55 |
|
56 |
- EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
57 |
+ if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
58 |
+ EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
59 |
+ fi |
60 |
fi |
61 |
|
62 |
unset PYTHON_ABIS |
63 |
-unset PYTHON_ABIS_SANITY_CHECKS |
64 |
|
65 |
# @FUNCTION: validate_PYTHON_ABIS |
66 |
# @DESCRIPTION: |
67 |
@@ -293,17 +294,7 @@ |
68 |
die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
69 |
fi |
70 |
|
71 |
- # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
72 |
- if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
73 |
- eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
74 |
- eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
75 |
- die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
76 |
- fi |
77 |
- if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
78 |
- eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
79 |
- eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
80 |
- die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
81 |
- fi |
82 |
+ _python_initial_sanity_checks |
83 |
|
84 |
# USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. |
85 |
if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
86 |
@@ -428,36 +419,18 @@ |
87 |
fi |
88 |
fi |
89 |
|
90 |
- if ! _python_implementation && [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then |
91 |
- local PYTHON_ABI |
92 |
- for PYTHON_ABI in ${PYTHON_ABIS}; do |
93 |
- # Ensure that appropriate version of Python is installed. |
94 |
- if ! has_version "$(python_get_implementational_package)"; then |
95 |
- die "$(python_get_implementational_package) is not installed" |
96 |
- fi |
97 |
- |
98 |
- # Ensure that EPYTHON variable is respected. |
99 |
- if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
100 |
- eerror "python: '$(type -p python)'" |
101 |
- eerror "ABI: '${ABI}'" |
102 |
- eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
103 |
- eerror "EPYTHON: '$(PYTHON)'" |
104 |
- eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
105 |
- eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
106 |
- die "'python' does not respect EPYTHON variable" |
107 |
- fi |
108 |
- done |
109 |
- PYTHON_ABIS_SANITY_CHECKS="1" |
110 |
- fi |
111 |
+ _python_final_sanity_checks |
112 |
} |
113 |
|
114 |
# @FUNCTION: python_execute_function |
115 |
-# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
116 |
+# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
117 |
# @DESCRIPTION: |
118 |
# Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
119 |
# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
120 |
python_execute_function() { |
121 |
- local action action_message action_message_template= default_function="0" failure_message failure_message_template= function i nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= |
122 |
+ _python_set_color_variables |
123 |
+ |
124 |
+ local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= |
125 |
|
126 |
while (($#)); do |
127 |
case "$1" in |
128 |
@@ -472,6 +445,9 @@ |
129 |
failure_message_template="$2" |
130 |
shift |
131 |
;; |
132 |
+ -f|--final-ABI) |
133 |
+ final_ABI="1" |
134 |
+ ;; |
135 |
--nonfatal) |
136 |
nonfatal="1" |
137 |
;; |
138 |
@@ -573,28 +549,20 @@ |
139 |
[[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
140 |
fi |
141 |
|
142 |
- local RED GREEN BLUE NORMAL |
143 |
- if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
144 |
- RED=$'\e[1;31m' |
145 |
- GREEN=$'\e[1;32m' |
146 |
- BLUE=$'\e[1;34m' |
147 |
- NORMAL=$'\e[0m' |
148 |
+ validate_PYTHON_ABIS |
149 |
+ if [[ "${final_ABI}" == "1" ]]; then |
150 |
+ iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
151 |
else |
152 |
- RED= |
153 |
- GREEN= |
154 |
- BLUE= |
155 |
- NORMAL= |
156 |
+ iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
157 |
fi |
158 |
- |
159 |
- validate_PYTHON_ABIS |
160 |
- for PYTHON_ABI in ${PYTHON_ABIS}; do |
161 |
+ for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
162 |
if [[ "${quiet}" == "0" ]]; then |
163 |
if [[ -n "${action_message_template}" ]]; then |
164 |
action_message="$(eval echo -n "${action_message_template}")" |
165 |
else |
166 |
action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." |
167 |
fi |
168 |
- echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
169 |
+ echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" |
170 |
fi |
171 |
|
172 |
if [[ "${separate_build_dirs}" == "1" ]]; then |
173 |
@@ -627,9 +595,9 @@ |
174 |
|
175 |
if [[ "${nonfatal}" == "1" ]]; then |
176 |
if [[ "${quiet}" == "0" ]]; then |
177 |
- ewarn "${RED}${failure_message}${NORMAL}" |
178 |
+ ewarn "${_RED}${failure_message}${_NORMAL}" |
179 |
fi |
180 |
- elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
181 |
+ elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
182 |
if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then |
183 |
local enabled_PYTHON_ABIS= other_PYTHON_ABI |
184 |
for other_PYTHON_ABI in ${PYTHON_ABIS}; do |
185 |
@@ -638,7 +606,7 @@ |
186 |
export PYTHON_ABIS="${enabled_PYTHON_ABIS}" |
187 |
fi |
188 |
if [[ "${quiet}" == "0" ]]; then |
189 |
- ewarn "${RED}${failure_message}${NORMAL}" |
190 |
+ ewarn "${_RED}${failure_message}${_NORMAL}" |
191 |
fi |
192 |
if [[ -z "${PYTHON_ABIS}" ]]; then |
193 |
die "${function}() function failed with all enabled versions of Python" |
194 |
@@ -681,54 +649,31 @@ |
195 |
} |
196 |
|
197 |
# @FUNCTION: python_copy_sources |
198 |
-# @USAGE: [--no-link] [--] [directory] |
199 |
+# @USAGE: <directory="${S}"> [directory] |
200 |
# @DESCRIPTION: |
201 |
# Copy unpacked sources of current package to separate build directory for each Python ABI. |
202 |
python_copy_sources() { |
203 |
- local dir dirs=() no_link="0" PYTHON_ABI |
204 |
- |
205 |
- while (($#)); do |
206 |
- case "$1" in |
207 |
- --no-link) |
208 |
- no_link="1" |
209 |
- ;; |
210 |
- --) |
211 |
- shift |
212 |
- break |
213 |
- ;; |
214 |
- -*) |
215 |
- die "${FUNCNAME}(): Unrecognized option '$1'" |
216 |
- ;; |
217 |
- *) |
218 |
- break |
219 |
- ;; |
220 |
- esac |
221 |
- shift |
222 |
- done |
223 |
+ local dir dirs=() PYTHON_ABI |
224 |
|
225 |
if [[ "$#" -eq 0 ]]; then |
226 |
if [[ "${WORKDIR}" == "${S}" ]]; then |
227 |
die "${FUNCNAME}() cannot be used" |
228 |
fi |
229 |
- dirs="${S}" |
230 |
+ dirs=("${S}") |
231 |
else |
232 |
- dirs="$@" |
233 |
+ dirs=("$@") |
234 |
fi |
235 |
|
236 |
validate_PYTHON_ABIS |
237 |
for PYTHON_ABI in ${PYTHON_ABIS}; do |
238 |
for dir in "${dirs[@]}"; do |
239 |
- if [[ "${no_link}" == "1" ]]; then |
240 |
- cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
241 |
- else |
242 |
- cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
243 |
- fi |
244 |
+ cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
245 |
done |
246 |
done |
247 |
} |
248 |
|
249 |
# @FUNCTION: python_set_build_dir_symlink |
250 |
-# @USAGE: [directory="build"] |
251 |
+# @USAGE: <directory="build"> |
252 |
# @DESCRIPTION: |
253 |
# Create build directory symlink. |
254 |
python_set_build_dir_symlink() { |
255 |
@@ -922,6 +867,8 @@ |
256 |
die "${FUNCNAME}() requires 1 argument" |
257 |
fi |
258 |
|
259 |
+ _python_initial_sanity_checks |
260 |
+ |
261 |
if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
262 |
if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
263 |
die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" |
264 |
@@ -946,6 +893,8 @@ |
265 |
PYTHON_ABI="${EPYTHON#python}" |
266 |
PYTHON_ABI="${PYTHON_ABI%%-*}" |
267 |
|
268 |
+ _python_final_sanity_checks |
269 |
+ |
270 |
# python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
271 |
PYTHON_REQUESTED_ACTIVE_VERSION="$1" |
272 |
} |
273 |
@@ -954,7 +903,11 @@ |
274 |
# @DESCRIPTION: Mark current package for rebuilding by python-updater after |
275 |
# switching of active version of Python. |
276 |
python_need_rebuild() { |
277 |
- export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)" |
278 |
+ if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
279 |
+ die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
280 |
+ fi |
281 |
+ |
282 |
+ export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" |
283 |
} |
284 |
|
285 |
# ================================================================================================ |
286 |
@@ -982,22 +935,20 @@ |
287 |
} |
288 |
|
289 |
# @FUNCTION: PYTHON |
290 |
-# @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
291 |
+# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
292 |
# @DESCRIPTION: |
293 |
# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument |
294 |
# is ommitted, then PYTHON_ABI environment variable must be set and is used. |
295 |
# If -2 option is specified, then active version of Python 2 is used. |
296 |
# If -3 option is specified, then active version of Python 3 is used. |
297 |
-# If --active option is specified, then active version of Python is used. |
298 |
-# Active version of Python can be set by python_set_active_version(). |
299 |
# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
300 |
-# -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
301 |
+# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
302 |
# If --ABI option is specified, then only specified Python ABI is printed instead of |
303 |
# filename of Python interpreter. |
304 |
# If --absolute-path option is specified, then absolute path to Python interpreter is printed. |
305 |
# --ABI and --absolute-path options cannot be specified simultaneously. |
306 |
PYTHON() { |
307 |
- local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" |
308 |
+ local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" |
309 |
|
310 |
while (($#)); do |
311 |
case "$1" in |
312 |
@@ -1010,9 +961,6 @@ |
313 |
--ABI) |
314 |
ABI_output="1" |
315 |
;; |
316 |
- -A|--active) |
317 |
- active="1" |
318 |
- ;; |
319 |
-a|--absolute-path) |
320 |
absolute_path_output="1" |
321 |
;; |
322 |
@@ -1037,17 +985,12 @@ |
323 |
die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" |
324 |
fi |
325 |
|
326 |
- if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then |
327 |
- die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously" |
328 |
+ if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then |
329 |
+ die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" |
330 |
fi |
331 |
|
332 |
if [[ "$#" -eq 0 ]]; then |
333 |
- if [[ "${active}" == "1" ]]; then |
334 |
- if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
335 |
- die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
336 |
- fi |
337 |
- PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
338 |
- elif [[ "${final_ABI}" == "1" ]]; then |
339 |
+ if [[ "${final_ABI}" == "1" ]]; then |
340 |
if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
341 |
die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" |
342 |
fi |
343 |
@@ -1067,13 +1010,12 @@ |
344 |
elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
345 |
die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
346 |
fi |
347 |
+ elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
348 |
+ PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
349 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
350 |
die "${FUNCNAME}(): Invalid usage: Python ABI not specified" |
351 |
fi |
352 |
elif [[ "$#" -eq 1 ]]; then |
353 |
- if [[ "${active}" == "1" ]]; then |
354 |
- die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously" |
355 |
- fi |
356 |
if [[ "${final_ABI}" == "1" ]]; then |
357 |
die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" |
358 |
fi |
359 |
@@ -1136,7 +1078,7 @@ |
360 |
if [[ "${final_ABI}" == "1" ]]; then |
361 |
PYTHON_ABI="$(PYTHON -f --ABI)" |
362 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
363 |
- PYTHON_ABI="$(PYTHON -A --ABI)" |
364 |
+ PYTHON_ABI="$(PYTHON --ABI)" |
365 |
fi |
366 |
|
367 |
echo "$(_python_get_implementation "${PYTHON_ABI}")" |
368 |
@@ -1168,7 +1110,7 @@ |
369 |
if [[ "${final_ABI}" == "1" ]]; then |
370 |
PYTHON_ABI="$(PYTHON -f --ABI)" |
371 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
372 |
- PYTHON_ABI="$(PYTHON -A --ABI)" |
373 |
+ PYTHON_ABI="$(PYTHON --ABI)" |
374 |
fi |
375 |
|
376 |
if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
377 |
@@ -1204,7 +1146,7 @@ |
378 |
if [[ "${final_ABI}" == "1" ]]; then |
379 |
PYTHON_ABI="$(PYTHON -f --ABI)" |
380 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
381 |
- PYTHON_ABI="$(PYTHON -A --ABI)" |
382 |
+ PYTHON_ABI="$(PYTHON --ABI)" |
383 |
fi |
384 |
|
385 |
if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
386 |
@@ -1240,7 +1182,7 @@ |
387 |
if [[ "${final_ABI}" == "1" ]]; then |
388 |
PYTHON_ABI="$(PYTHON -f --ABI)" |
389 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
390 |
- PYTHON_ABI="$(PYTHON -A --ABI)" |
391 |
+ PYTHON_ABI="$(PYTHON --ABI)" |
392 |
fi |
393 |
|
394 |
if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
395 |
@@ -1306,7 +1248,7 @@ |
396 |
if [[ "${final_ABI}" == "1" ]]; then |
397 |
PYTHON_ABI="$(PYTHON -f --ABI)" |
398 |
elif [[ -z "${PYTHON_ABI}" ]]; then |
399 |
- PYTHON_ABI="$(PYTHON -A --ABI)" |
400 |
+ PYTHON_ABI="$(PYTHON --ABI)" |
401 |
fi |
402 |
|
403 |
if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
404 |
@@ -1371,7 +1313,7 @@ |
405 |
if [[ "${final_ABI}" == "1" ]]; then |
406 |
"$(PYTHON -f)" -c "${python_command}" |
407 |
else |
408 |
- "$(PYTHON "${PYTHON_ABI--A}")" -c "${python_command}" |
409 |
+ "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
410 |
fi |
411 |
} |
412 |
|
413 |
@@ -1400,6 +1342,66 @@ |
414 |
fi |
415 |
} |
416 |
|
417 |
+unset PYTHON_SANITY_CHECKS |
418 |
+ |
419 |
+_python_initial_sanity_checks() { |
420 |
+ if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
421 |
+ # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
422 |
+ if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
423 |
+ eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
424 |
+ eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
425 |
+ die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
426 |
+ fi |
427 |
+ if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
428 |
+ eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
429 |
+ eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
430 |
+ die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
431 |
+ fi |
432 |
+ fi |
433 |
+} |
434 |
+ |
435 |
+_python_final_sanity_checks() { |
436 |
+ if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
437 |
+ local PYTHON_ABI="${PYTHON_ABI}" |
438 |
+ for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do |
439 |
+ # Ensure that appropriate version of Python is installed. |
440 |
+ if ! has_version "$(python_get_implementational_package)"; then |
441 |
+ die "$(python_get_implementational_package) is not installed" |
442 |
+ fi |
443 |
+ |
444 |
+ # Ensure that EPYTHON variable is respected. |
445 |
+ if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
446 |
+ eerror "python: '$(type -p python)'" |
447 |
+ eerror "ABI: '${ABI}'" |
448 |
+ eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
449 |
+ eerror "EPYTHON: '$(PYTHON)'" |
450 |
+ eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
451 |
+ eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
452 |
+ die "'python' does not respect EPYTHON variable" |
453 |
+ fi |
454 |
+ done |
455 |
+ fi |
456 |
+ PYTHON_SANITY_CHECKS="1" |
457 |
+} |
458 |
+ |
459 |
+_python_set_color_variables() { |
460 |
+ if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
461 |
+ _BOLD=$'\e[1m' |
462 |
+ _RED=$'\e[1;31m' |
463 |
+ _GREEN=$'\e[1;32m' |
464 |
+ _BLUE=$'\e[1;34m' |
465 |
+ _CYAN=$'\e[1;36m' |
466 |
+ _NORMAL=$'\e[0m' |
467 |
+ else |
468 |
+ _BOLD= |
469 |
+ _RED= |
470 |
+ _GREEN= |
471 |
+ _BLUE= |
472 |
+ _CYAN= |
473 |
+ _NORMAL= |
474 |
+ fi |
475 |
+} |
476 |
+ |
477 |
# @FUNCTION: python_convert_shebangs |
478 |
# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
479 |
# @DESCRIPTION: |
480 |
@@ -1493,24 +1495,7 @@ |
481 |
if [[ "$#" -ne 1 ]]; then |
482 |
die "${FUNCNAME}() requires 1 argument" |
483 |
fi |
484 |
- "$(PYTHON "${PYTHON_ABI--A}")" -c "import $1" &> /dev/null |
485 |
-} |
486 |
- |
487 |
-# @FUNCTION: python_tkinter_exists |
488 |
-# @DESCRIPTION: |
489 |
-# Run without arguments, checks if Python was compiled with Tkinter |
490 |
-# support. If not, prints an error message and dies. |
491 |
-python_tkinter_exists() { |
492 |
- if ! "$(PYTHON "${PYTHON_ABI--A}")" -c "from sys import version_info |
493 |
-if version_info[0] == 3: |
494 |
- import tkinter |
495 |
-else: |
496 |
- import Tkinter" &> /dev/null; then |
497 |
- eerror "Python needs to be rebuilt with tkinter support enabled." |
498 |
- eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python" |
499 |
- eerror "dev-lang/python tk" |
500 |
- die "Python installed without support for tkinter" |
501 |
- fi |
502 |
+ "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null |
503 |
} |
504 |
|
505 |
# ================================================================================================ |
506 |
@@ -1528,6 +1513,8 @@ |
507 |
# @DESCRIPTION: |
508 |
# Execute nosetests for all enabled versions of Python. |
509 |
python_execute_nosetests() { |
510 |
+ _python_set_color_variables |
511 |
+ |
512 |
local PYTHONPATH_template= separate_build_dirs= |
513 |
|
514 |
while (($#)); do |
515 |
@@ -1564,10 +1551,10 @@ |
516 |
fi |
517 |
|
518 |
if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
519 |
- echo PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
520 |
+ echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
521 |
PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
522 |
else |
523 |
- echo nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
524 |
+ echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
525 |
nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
526 |
fi |
527 |
} |
528 |
@@ -1588,6 +1575,8 @@ |
529 |
# @DESCRIPTION: |
530 |
# Execute py.test for all enabled versions of Python. |
531 |
python_execute_py.test() { |
532 |
+ _python_set_color_variables |
533 |
+ |
534 |
local PYTHONPATH_template= separate_build_dirs= |
535 |
|
536 |
while (($#)); do |
537 |
@@ -1624,10 +1613,10 @@ |
538 |
fi |
539 |
|
540 |
if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
541 |
- echo PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" |
542 |
+ echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} |
543 |
PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" |
544 |
else |
545 |
- echo py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" |
546 |
+ echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} |
547 |
py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" |
548 |
fi |
549 |
} |
550 |
@@ -1648,6 +1637,8 @@ |
551 |
# @DESCRIPTION: |
552 |
# Execute trial for all enabled versions of Python. |
553 |
python_execute_trial() { |
554 |
+ _python_set_color_variables |
555 |
+ |
556 |
local PYTHONPATH_template= separate_build_dirs= |
557 |
|
558 |
while (($#)); do |
559 |
@@ -1684,10 +1675,10 @@ |
560 |
fi |
561 |
|
562 |
if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
563 |
- echo PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
564 |
+ echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
565 |
PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
566 |
else |
567 |
- echo trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
568 |
+ echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
569 |
trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
570 |
fi |
571 |
} |
572 |
@@ -1745,7 +1736,7 @@ |
573 |
[[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" |
574 |
|
575 |
if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
576 |
- local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
577 |
+ local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
578 |
|
579 |
# Strip trailing slash from ROOT. |
580 |
root="${EROOT%/}" |
581 |
@@ -1777,7 +1768,7 @@ |
582 |
ewarn "'${root}/$1' does not exist!" |
583 |
fi |
584 |
else |
585 |
- for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
586 |
+ for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
587 |
if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
588 |
site_packages_dirs+=("$1") |
589 |
break |
590 |
@@ -1799,7 +1790,7 @@ |
591 |
# Set additional options. |
592 |
options+=("-q") |
593 |
|
594 |
- for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
595 |
+ for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
596 |
if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
597 |
return_code="0" |
598 |
ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
599 |
@@ -1837,15 +1828,15 @@ |
600 |
return_code="0" |
601 |
ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" |
602 |
if ((${#other_dirs[@]})); then |
603 |
- "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
604 |
- if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON -A --ABI)}")" != "Jython" ]]; then |
605 |
- "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
606 |
+ "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
607 |
+ if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
608 |
+ "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
609 |
fi |
610 |
fi |
611 |
if ((${#other_files[@]})); then |
612 |
- "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
613 |
- if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON -A --ABI)}")" != "Jython" ]]; then |
614 |
- "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
615 |
+ "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
616 |
+ if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
617 |
+ "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
618 |
fi |
619 |
fi |
620 |
eend "${return_code}" |
621 |
@@ -1890,8 +1881,8 @@ |
622 |
|
623 |
ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
624 |
if ((${#mydirs[@]})); then |
625 |
- "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
626 |
- "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
627 |
+ "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
628 |
+ "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
629 |
fi |
630 |
|
631 |
if ((${#myfiles[@]})); then |
632 |
@@ -1915,8 +1906,9 @@ |
633 |
# This function should only be run in pkg_postrm(). |
634 |
python_mod_cleanup() { |
635 |
_python_initialize_prefix_variables |
636 |
+ _python_set_color_variables |
637 |
|
638 |
- local path py_file PYTHON_ABI SEARCH_PATH=() root |
639 |
+ local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root |
640 |
|
641 |
# Check if phase is pkg_postrm(). |
642 |
[[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" |
643 |
@@ -1932,7 +1924,7 @@ |
644 |
elif [[ "$1" =~ ^/ ]]; then |
645 |
SEARCH_PATH+=("${root}/${1#/}") |
646 |
else |
647 |
- for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
648 |
+ for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
649 |
SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
650 |
done |
651 |
fi |
652 |
@@ -1960,44 +1952,33 @@ |
653 |
done |
654 |
fi |
655 |
|
656 |
- local BLUE CYAN NORMAL |
657 |
- if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
658 |
- BLUE=$'\e[1;34m' |
659 |
- CYAN=$'\e[1;36m' |
660 |
- NORMAL=$'\e[0m' |
661 |
- else |
662 |
- BLUE= |
663 |
- CYAN= |
664 |
- NORMAL= |
665 |
- fi |
666 |
- |
667 |
for path in "${SEARCH_PATH[@]}"; do |
668 |
if [[ -d "${path}" ]]; then |
669 |
find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do |
670 |
if [[ "${REPLY}" == *[co] ]]; then |
671 |
py_file="${REPLY%[co]}" |
672 |
[[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue |
673 |
- einfo "${BLUE}<<< ${py_file}[co]${NORMAL}" |
674 |
+ einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" |
675 |
rm -f "${py_file}"[co] |
676 |
elif [[ "${REPLY}" == *\$py.class ]]; then |
677 |
py_file="${REPLY%\$py.class}.py" |
678 |
[[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue |
679 |
- einfo "${BLUE}<<< ${py_file%.py}\$py.class${NORMAL}" |
680 |
+ einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" |
681 |
rm -f "${py_file%.py}\$py.class" |
682 |
fi |
683 |
done |
684 |
|
685 |
# Attempt to delete directories, which may be empty. |
686 |
find "${path}" -type d | sort -r | while read -r dir; do |
687 |
- rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}" |
688 |
+ rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" |
689 |
done |
690 |
elif [[ "${path}" == *.py && ! -f "${path}" ]]; then |
691 |
if [[ (-f "${path}c" || -f "${path}o") ]]; then |
692 |
- einfo "${BLUE}<<< ${path}[co]${NORMAL}" |
693 |
+ einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" |
694 |
rm -f "${path}"[co] |
695 |
fi |
696 |
if [[ -f "${path%.py}\$py.class" ]]; then |
697 |
- einfo "${BLUE}<<< ${path%.py}\$py.class${NORMAL}" |
698 |
+ einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" |
699 |
rm -f "${path%.py}\$py.class" |
700 |
fi |
701 |
fi |
702 |
@@ -2013,7 +1994,7 @@ |
703 |
# Run without arguments and it will export the version of python |
704 |
# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
705 |
python_version() { |
706 |
- if ! has "${EAPI:-0}" 0 1 2; then |
707 |
+ if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
708 |
eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." |
709 |
die "${FUNCNAME}() cannot be used in this EAPI" |
710 |
fi |
711 |
@@ -2031,6 +2012,28 @@ |
712 |
export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
713 |
} |
714 |
|
715 |
+# @FUNCTION: python_tkinter_exists |
716 |
+# @DESCRIPTION: |
717 |
+# Run without arguments, checks if Python was compiled with Tkinter |
718 |
+# support. If not, prints an error message and dies. |
719 |
+python_tkinter_exists() { |
720 |
+ if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
721 |
+ eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
722 |
+ die "${FUNCNAME}() cannot be used in this EAPI" |
723 |
+ fi |
724 |
+ |
725 |
+ if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info |
726 |
+if version_info[0] == 3: |
727 |
+ import tkinter |
728 |
+else: |
729 |
+ import Tkinter" &> /dev/null; then |
730 |
+ eerror "Python needs to be rebuilt with tkinter support enabled." |
731 |
+ eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python" |
732 |
+ eerror "dev-lang/python tk" |
733 |
+ die "Python installed without support for tkinter" |
734 |
+ fi |
735 |
+} |
736 |
+ |
737 |
# @FUNCTION: python_mod_compile |
738 |
# @USAGE: <file> [more files ...] |
739 |
# @DESCRIPTION: |
740 |
@@ -2062,8 +2065,8 @@ |
741 |
done |
742 |
|
743 |
if ((${#myfiles[@]})); then |
744 |
- "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
745 |
- "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
746 |
+ "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
747 |
+ "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
748 |
else |
749 |
ewarn "No files to compile!" |
750 |
fi |