Gentoo Archives: gentoo-commits

From: "Arfrever Frehtes Taifersar Arahesis (arfrever)" <arfrever@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: python.eclass
Date: Tue, 02 Feb 2010 18:55:08
Message-Id: E1NcNtt-0000ZC-08@stork.gentoo.org
1 arfrever 10/02/02 18:55:00
2
3 Modified: python.eclass
4 Log:
5 Support EAPI="3".
6 Define _PYTHON2_SUPPORTED_VERSIONS and _PYTHON3_SUPPORTED_VERSIONS to avoid code duplication.
7 Support PYTHON_DEPEND.
8 Disallow using of NEED_PYTHON in EAPI >=3.
9 Use prefix variables (bug #302525).
10 Fix handling of -- option in some functions.
11 Ensure that python_execute_function() isn't called by a function, which is called by python_execute_function().
12 Set PYTHON_REQUESTED_ACTIVE_VERSION in python_set_active_version().
13 Add python_get_library() and python_get_version().
14 Use PYTHON() in python_mod_exists() and python_tkinter_exists().
15 Support Python 3 in python_tkinter_exists().
16 Support PYTHON_TEST_VERBOSITY.
17 Add python_execute_nosetests(), python_execute_py.test() and python_execute_trial().
18 Disallow using of python_version() in EAPI >=3.
19
20 Revision Changes Path
21 1.87 eclass/python.eclass
22
23 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.87&view=markup
24 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.87&content-type=text/plain
25 diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?r1=1.86&r2=1.87
26
27 Index: python.eclass
28 ===================================================================
29 RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v
30 retrieving revision 1.86
31 retrieving revision 1.87
32 diff -u -r1.86 -r1.87
33 --- python.eclass 15 Jan 2010 14:46:20 -0000 1.86
34 +++ python.eclass 2 Feb 2010 18:55:00 -0000 1.87
35 @@ -1,6 +1,6 @@
36 # Copyright 1999-2010 Gentoo Foundation
37 # Distributed under the terms of the GNU General Public License v2
38 -# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.86 2010/01/15 14:46:20 arfrever Exp $
39 +# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.87 2010/02/02 18:55:00 arfrever Exp $
40
41 # @ECLASS: python.eclass
42 # @MAINTAINER:
43 @@ -11,35 +11,161 @@
44
45 inherit multilib
46
47 -if ! has "${EAPI:-0}" 0 1 2; then
48 +if ! has "${EAPI:-0}" 0 1 2 3; then
49 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
50 fi
51
52 -if [[ -n "${NEED_PYTHON}" ]]; then
53 - PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}"
54 - DEPEND="${PYTHON_ATOM}"
55 - RDEPEND="${DEPEND}"
56 +_PYTHON2_SUPPORTED_VERSIONS=(2.4 2.5 2.6 2.7)
57 +_PYTHON3_SUPPORTED_VERSIONS=(3.0 3.1 3.2)
58 +
59 +# @ECLASS-VARIABLE: PYTHON_DEPEND
60 +# @DESCRIPTION:
61 +# Specification of dependency on dev-lang/python.
62 +# Syntax:
63 +# PYTHON_DEPEND: [[!]USE_flag? ]<version_components_group>[ version_components_group]
64 +# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
65 +# major_version: <2|3|*>
66 +# minimal_version: <minimal_major_version.minimal_minor_version>
67 +# maximal_version: <maximal_major_version.maximal_minor_version>
68 +
69 +_parse_PYTHON_DEPEND() {
70 + local accepted_version accepted_versions=() major_version maximal_version minimal_version python_all="0" python_atoms= python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
71 +
72 + version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
73 + version_components_groups="${PYTHON_DEPEND}"
74 +
75 + if [[ "${version_components_groups}" =~ ^((\!)?[[:alnum:]_-]+\?\ )?${version_components_group_regex}(\ ${version_components_group_regex})?$ ]]; then
76 + if [[ "${version_components_groups}" =~ ^(\!)?[[:alnum:]_-]+\? ]]; then
77 + USE_flag="${version_components_groups%\? *}"
78 + version_components_groups="${version_components_groups#* }"
79 + fi
80 + if [[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]]; then
81 + die "Invalid syntax of PYTHON_DEPEND: Incorrectly specified groups of versions"
82 + fi
83 +
84 + version_components_groups="${version_components_groups// /$'\n'}"
85 + while read version_components_group; do
86 + major_version="${version_components_group:0:1}"
87 + minimal_version="${version_components_group:2}"
88 + minimal_version="${minimal_version%:*}"
89 + maximal_version="${version_components_group:$((3 + ${#minimal_version}))}"
90 +
91 + if [[ "${major_version}" =~ ^(2|3)$ ]]; then
92 + if [[ -n "${minimal_version}" && "${major_version}" != "${minimal_version:0:1}" ]]; then
93 + die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' not in specified group of versions"
94 + fi
95 + if [[ -n "${maximal_version}" && "${major_version}" != "${maximal_version:0:1}" ]]; then
96 + die "Invalid syntax of PYTHON_DEPEND: Maximal version '${maximal_version}' not in specified group of versions"
97 + fi
98 + fi
99 +
100 + if [[ "${major_version}" == "2" ]]; then
101 + python2="1"
102 + python_versions=("${_PYTHON2_SUPPORTED_VERSIONS[@]}")
103 + python2_minimal_version="${minimal_version}"
104 + python2_maximal_version="${maximal_version}"
105 + elif [[ "${major_version}" == "3" ]]; then
106 + python3="1"
107 + python_versions=("${_PYTHON3_SUPPORTED_VERSIONS[@]}")
108 + python3_minimal_version="${minimal_version}"
109 + python3_maximal_version="${maximal_version}"
110 + else
111 + python_all="1"
112 + python_versions=("${_PYTHON2_SUPPORTED_VERSIONS[@]}" "${_PYTHON3_SUPPORTED_VERSIONS[@]}")
113 + python_minimal_version="${minimal_version}"
114 + python_maximal_version="${maximal_version}"
115 + fi
116 +
117 + if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
118 + die "Invalid syntax of PYTHON_DEPEND: Unrecognized minimal version '${minimal_version}'"
119 + fi
120 + if [[ -n "${maximal_version}" ]] && ! has "${maximal_version}" "${python_versions[@]}"; then
121 + die "Invalid syntax of PYTHON_DEPEND: Unrecognized maximal version '${maximal_version}'"
122 + fi
123 +
124 + if [[ -n "${minimal_version}" && -n "${maximal_version}" && "${minimal_version}" > "${maximal_version}" ]]; then
125 + die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' greater than maximal version '${maximal_version}'"
126 + fi
127 + done <<< "${version_components_groups}"
128 +
129 + _create_accepted_versions_range() {
130 + local accepted_version="0" i
131 + for ((i = "${#python_versions[@]}"; i >= 0; i--)); do
132 + if [[ "${python_versions[${i}]}" == "${python_maximal_version}" ]]; then
133 + accepted_version="1"
134 + fi
135 + if [[ "${accepted_version}" == "1" ]]; then
136 + accepted_versions+=("${python_versions[${i}]}")
137 + fi
138 + if [[ "${python_versions[${i}]}" == "${python_minimal_version}" ]]; then
139 + accepted_version="0"
140 + fi
141 + done
142 + }
143 +
144 + if [[ "${python_all}" == "1" ]]; then
145 + python_versions=("${_PYTHON2_SUPPORTED_VERSIONS[@]}" "${_PYTHON3_SUPPORTED_VERSIONS[@]}")
146 + python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
147 + python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
148 + _create_accepted_versions_range
149 + else
150 + if [[ "${python3}" == "1" ]]; then
151 + python_versions=("${_PYTHON3_SUPPORTED_VERSIONS[@]}")
152 + python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
153 + python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
154 + _create_accepted_versions_range
155 + fi
156 + if [[ "${python2}" == "1" ]]; then
157 + python_versions=("${_PYTHON2_SUPPORTED_VERSIONS[@]}")
158 + python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
159 + python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
160 + _create_accepted_versions_range
161 + fi
162 + fi
163 +
164 + for accepted_version in "${accepted_versions[@]}"; do
165 + python_atoms+="${python_atoms:+ }=dev-lang/python-${accepted_version}*"
166 + done
167 +
168 + _PYTHON_ATOMS="${python_atoms// /$'\n'}"
169 + DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${python_atoms} )${USE_flag:+ )}"
170 + RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${python_atoms} )${USE_flag:+ )}"
171 + else
172 + die "Invalid syntax of PYTHON_DEPEND"
173 + fi
174 +}
175 +
176 +DEPEND=">=app-admin/eselect-python-20090804"
177 +RDEPEND="${DEPEND}"
178 +
179 +if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
180 + die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
181 +elif [[ -n "${PYTHON_DEPEND}" ]]; then
182 + _parse_PYTHON_DEPEND
183 +elif [[ -n "${NEED_PYTHON}" ]]; then
184 + if ! has "${EAPI:-0}" 0 1 2; then
185 + eerror "Use PYTHON_DEPEND instead of NEED_PYTHON."
186 + die "NEED_PYTHON cannot be used in this EAPI"
187 + fi
188 + _PYTHON_ATOMS=">=dev-lang/python-${NEED_PYTHON}"
189 + DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS}"
190 + RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS}"
191 else
192 - PYTHON_ATOM="dev-lang/python"
193 + _PYTHON_ATOMS="dev-lang/python"
194 fi
195
196 -DEPEND+=" >=app-admin/eselect-python-20090804"
197 -
198 # @ECLASS-VARIABLE: PYTHON_USE_WITH
199 # @DESCRIPTION:
200 -# Set this to a space separated list of use flags
201 -# the python slot in use must be built with.
202 +# Set this to a space separated list of USE flags the Python slot in use must be built with.
203
204 # @ECLASS-VARIABLE: PYTHON_USE_WITH_OR
205 # @DESCRIPTION:
206 -# Set this to a space separated list of use flags
207 -# of which one must be turned on for the slot of
208 -# in use.
209 +# Set this to a space separated list of USE flags of which one must be turned on for the slot in use.
210
211 # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
212 # @DESCRIPTION:
213 -# Set this if you need to make either PYTHON_USE_WITH or
214 -# PYTHON_USE_WITH_OR atoms conditional under a use flag.
215 +# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
216 +# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
217
218 # @FUNCTION: python_pkg_setup
219 # @DESCRIPTION:
220 @@ -88,23 +214,31 @@
221
222 EXPORT_FUNCTIONS pkg_setup
223
224 + _PYTHON_USE_WITH_ATOM=""
225 if [[ -n "${PYTHON_USE_WITH}" ]]; then
226 - PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
227 + while read _PYTHON_ATOM; do
228 + _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
229 + done <<< "${_PYTHON_ATOMS}"
230 + _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )"
231 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
232 - PYTHON_USE_WITH_ATOM="|| ( "
233 - for use in ${PYTHON_USE_WITH_OR}; do
234 - PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
235 + for _USE_flag in ${PYTHON_USE_WITH_OR}; do
236 + while read _PYTHON_ATOM; do
237 + _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${_USE_flag}]"
238 + done <<< "${_PYTHON_ATOMS}"
239 done
240 - unset use
241 - PYTHON_USE_WITH_ATOM+=" )"
242 + unset _USE_flag
243 + _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )"
244 fi
245 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
246 - PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
247 + _PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOM} )"
248 fi
249 - DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
250 - RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
251 + DEPEND+=" ${_PYTHON_USE_WITH_ATOM}"
252 + RDEPEND+=" ${_PYTHON_USE_WITH_ATOM}"
253 + unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOM
254 fi
255
256 +unset _PYTHON_ATOMS
257 +
258 # ================================================================================================
259 # ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ========
260 # ================================================================================================
261 @@ -145,23 +279,21 @@
262 fi
263
264 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
265 - if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
266 - eerror "'/usr/bin/python' is not valid symlink."
267 + if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
268 + eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
269 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
270 - die "'/usr/bin/python' is not valid symlink"
271 + die "'${EPREFIX}/usr/bin/python' is not valid symlink"
272 fi
273 - if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
274 - eerror "'/usr/bin/python-config' is not valid script"
275 + if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
276 + eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
277 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
278 - die "'/usr/bin/python-config' is not valid script"
279 + die "'${EPREFIX}/usr/bin/python-config' is not valid script"
280 fi
281
282 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
283 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
284 - local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
285 - PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
286 - python2_supported_versions="2.4 2.5 2.6 2.7"
287 - python3_supported_versions="3.0 3.1 3.2"
288 + local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
289 + PYTHON_ABI_SUPPORTED_VALUES="${_PYTHON2_SUPPORTED_VERSIONS[@]} ${_PYTHON3_SUPPORTED_VERSIONS[@]}"
290
291 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
292 local python2_enabled="0" python3_enabled="0"
293 @@ -175,10 +307,10 @@
294 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
295 fi
296
297 - if has "${PYTHON_ABI}" ${python2_supported_versions}; then
298 + if has "${PYTHON_ABI}" "${_PYTHON2_SUPPORTED_VERSIONS[@]}"; then
299 python2_enabled="1"
300 fi
301 - if has "${PYTHON_ABI}" ${python3_supported_versions}; then
302 + if has "${PYTHON_ABI}" "${_PYTHON3_SUPPORTED_VERSIONS[@]}"; then
303 python3_enabled="1"
304 fi
305
306 @@ -205,16 +337,16 @@
307 else
308 local python_version python2_version= python3_version= support_python_major_version
309
310 - python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
311 + python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
312
313 if has_version "=dev-lang/python-2*"; then
314 - if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
315 - die "'/usr/bin/python2' is not valid symlink"
316 + if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
317 + die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
318 fi
319
320 - python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
321 + python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
322
323 - for PYTHON_ABI in ${python2_supported_versions}; do
324 + for PYTHON_ABI in "${_PYTHON2_SUPPORTED_VERSIONS[@]}"; do
325 support_python_major_version="1"
326 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
327 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
328 @@ -235,13 +367,13 @@
329 fi
330
331 if has_version "=dev-lang/python-3*"; then
332 - if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
333 - die "'/usr/bin/python3' is not valid symlink"
334 + if [[ "$(readlink "${EPREFIX}/usr/bin/python3")" != "python3."* ]]; then
335 + die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
336 fi
337
338 - python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
339 + python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
340
341 - for PYTHON_ABI in ${python3_supported_versions}; do
342 + for PYTHON_ABI in "${_PYTHON3_SUPPORTED_VERSIONS[@]}"; do
343 support_python_major_version="1"
344 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
345 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
346 @@ -262,12 +394,12 @@
347 fi
348
349 if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
350 - eerror "Python wrapper is configured incorrectly or /usr/bin/python2 symlink"
351 + eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink"
352 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
353 die "Incorrect configuration of Python"
354 fi
355 if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
356 - eerror "Python wrapper is configured incorrectly or /usr/bin/python3 symlink"
357 + eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink"
358 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
359 die "Incorrect configuration of Python"
360 fi
361 @@ -307,7 +439,7 @@
362 # Execute specified function for each value of PYTHON_ABIS, optionally passing additional
363 # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
364 python_execute_function() {
365 - local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir=
366 + 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=
367
368 while (($#)); do
369 case "$1" in
370 @@ -336,6 +468,7 @@
371 shift
372 ;;
373 --)
374 + shift
375 break
376 ;;
377 -*)
378 @@ -363,7 +496,7 @@
379 die "${FUNCNAME}(): '${function}' function is not defined"
380 fi
381 else
382 - if [[ "$#" -ne "0" ]]; then
383 + if [[ "$#" -ne 0 ]]; then
384 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
385 fi
386 if has "${EAPI:-0}" 0 1; then
387 @@ -402,6 +535,12 @@
388 function="python_default_function"
389 fi
390
391 + for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do
392 + if [[ "${FUNCNAME[${i}]}" == "python_execute_function" ]]; then
393 + die "${FUNCNAME}(): Invalid call stack"
394 + fi
395 + done
396 +
397 if [[ "${quiet}" == "0" ]]; then
398 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
399 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
400 @@ -526,7 +665,7 @@
401 # @FUNCTION: python_copy_sources
402 # @USAGE: [--no-link] [--] [directory]
403 # @DESCRIPTION:
404 -# Copy unpacked sources of given package for each Python ABI.
405 +# Copy unpacked sources of given package to separate build directory for each Python ABI.
406 python_copy_sources() {
407 local dir dirs=() no_link="0" PYTHON_ABI
408
409 @@ -536,6 +675,7 @@
410 no_link="1"
411 ;;
412 --)
413 + shift
414 break
415 ;;
416 -*)
417 @@ -591,9 +731,9 @@
418 # If --respect-EPYTHON option is specified, then generated wrapper scripts will
419 # respect EPYTHON variable at run time.
420 python_generate_wrapper_scripts() {
421 - local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python2_supported_versions python3_enabled="0" python3_supported_versions respect_EPYTHON="0"
422 - python2_supported_versions="2.4 2.5 2.6 2.7"
423 - python3_supported_versions="3.0 3.1 3.2"
424 + _python_initialize_prefix_variables
425 +
426 + local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
427
428 while (($#)); do
429 case "$1" in
430 @@ -607,6 +747,7 @@
431 quiet="1"
432 ;;
433 --)
434 + shift
435 break
436 ;;
437 -*)
438 @@ -624,12 +765,12 @@
439 fi
440
441 validate_PYTHON_ABIS
442 - for PYTHON_ABI in ${python2_supported_versions}; do
443 + for PYTHON_ABI in "${_PYTHON2_SUPPORTED_VERSIONS[@]}"; do
444 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
445 python2_enabled="1"
446 fi
447 done
448 - for PYTHON_ABI in ${python3_supported_versions}; do
449 + for PYTHON_ABI in "${_PYTHON3_SUPPORTED_VERSIONS[@]}"; do
450 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
451 python3_enabled="1"
452 fi
453 @@ -681,7 +822,7 @@
454 sys.exit(1)
455 else:
456 try:
457 - eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
458 + eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
459 if eselect_process.wait() != 0:
460 raise ValueError
461 except (OSError, ValueError):
462 @@ -706,7 +847,7 @@
463 else
464 cat << EOF >> "${file}"
465 try:
466 - eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
467 + eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
468 if eselect_process.wait() != 0:
469 raise ValueError
470 except (OSError, ValueError):
471 @@ -742,7 +883,7 @@
472 if [[ "$?" != "0" ]]; then
473 die "${FUNCNAME}(): Generation of '$1' failed"
474 fi
475 - fperms +x "${file#${D%/}}" || die "fperms '${file}' failed"
476 + fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
477 done
478 }
479
480 @@ -755,7 +896,7 @@
481 # @DESCRIPTION:
482 # Set active version of Python.
483 python_set_active_version() {
484 - if [[ "$#" -ne "1" ]]; then
485 + if [[ "$#" -ne 1 ]]; then
486 die "${FUNCNAME}() requires 1 argument"
487 fi
488
489 @@ -782,6 +923,9 @@
490 # so it does not need to be exported to subprocesses.
491 PYTHON_ABI="${EPYTHON#python}"
492 PYTHON_ABI="${PYTHON_ABI%%-*}"
493 +
494 + # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
495 + PYTHON_REQUESTED_ACTIVE_VERSION="$1"
496 }
497
498 # @FUNCTION: python_need_rebuild
499 @@ -800,7 +944,7 @@
500 # @FUNCTION: PYTHON
501 # @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
502 # @DESCRIPTION:
503 -# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
504 +# Print Python interpreter filename for specified Python ABI. If Python_ABI argument
505 # is ommitted, then PYTHON_ABI environment variable must be set and is used.
506 # If -2 option is specified, then active version of Python 2 is used.
507 # If -3 option is specified, then active version of Python 3 is used.
508 @@ -835,6 +979,7 @@
509 final_ABI="1"
510 ;;
511 --)
512 + shift
513 break
514 ;;
515 -*)
516 @@ -860,7 +1005,7 @@
517 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
518 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
519 fi
520 - slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
521 + slot="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
522 elif [[ "${final_ABI}" == "1" ]]; then
523 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
524 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python"
525 @@ -910,7 +1055,7 @@
526 echo -n "${slot}"
527 return
528 elif [[ "${absolute_path_output}" == "1" ]]; then
529 - echo -n "/usr/bin/python${slot}"
530 + echo -n "${EPREFIX}/usr/bin/python${slot}"
531 else
532 echo -n "python${slot}"
533 fi
534 @@ -923,7 +1068,7 @@
535 # @FUNCTION: python_get_includedir
536 # @USAGE: [-f|--final-ABI]
537 # @DESCRIPTION:
538 -# Print Python include directory.
539 +# Print path to Python include directory.
540 # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
541 python_get_includedir() {
542 local final_ABI="0"
543 @@ -955,7 +1100,7 @@
544 # @FUNCTION: python_get_libdir
545 # @USAGE: [-f|--final-ABI]
546 # @DESCRIPTION:
547 -# Print Python library directory.
548 +# Print path to Python library directory.
549 # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
550 python_get_libdir() {
551 local final_ABI="0"
552 @@ -987,7 +1132,7 @@
553 # @FUNCTION: python_get_sitedir
554 # @USAGE: [-f|--final-ABI]
555 # @DESCRIPTION:
556 -# Print Python site-packages directory.
557 +# Print path to Python site-packages directory.
558 # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
559 python_get_sitedir() {
560 local options=()
561 @@ -1010,6 +1155,103 @@
562 echo "$(python_get_libdir "${options[@]}")/site-packages"
563 }
564
565 +# @FUNCTION: python_get_library
566 +# @USAGE: [-f|--final-ABI] [-l|--linker-option]
567 +# @DESCRIPTION:
568 +# Print path to Python library.
569 +# If --linker-option is specified, then "-l${library}" linker option is printed.
570 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
571 +python_get_library() {
572 + local final_ABI="0" linker_option="0" python_version
573 +
574 + while (($#)); do
575 + case "$1" in
576 + -f|--final-ABI)
577 + final_ABI="1"
578 + ;;
579 + -l|--linker-option)
580 + linker_option="1"
581 + ;;
582 + -*)
583 + die "${FUNCNAME}(): Unrecognized option '$1'"
584 + ;;
585 + *)
586 + die "${FUNCNAME}(): Invalid usage"
587 + ;;
588 + esac
589 + shift
590 + done
591 +
592 + if [[ "${final_ABI}" == "1" ]]; then
593 + python_version="$(PYTHON -f --ABI)"
594 + elif [[ -n "${PYTHON_ABI}" ]]; then
595 + python_version="${PYTHON_ABI}"
596 + else
597 + python_version="$(PYTHON -A --ABI)"
598 + fi
599 +
600 + if [[ "${linker_option}" == "1" ]]; then
601 + echo "-lpython${python_version}"
602 + else
603 + echo "/usr/$(get_libdir)/libpython${python_version}$(get_libname)"
604 + fi
605 +}
606 +
607 +# @FUNCTION: python_get_version
608 +# @USAGE: [-f|--final-ABI] [--major] [--minor] [--micro]
609 +# @DESCRIPTION:
610 +# Print Python version.
611 +# --major, --minor and --micro options cannot be specified simultaneously.
612 +# If --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
613 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
614 +python_get_version() {
615 + local final_ABI="0" major="0" minor="0" micro="0" python_command
616 +
617 + while (($#)); do
618 + case "$1" in
619 + -f|--final-ABI)
620 + final_ABI="1"
621 + ;;
622 + --major)
623 + major="1"
624 + ;;
625 + --minor)
626 + minor="1"
627 + ;;
628 + --micro)
629 + micro="1"
630 + ;;
631 + -*)
632 + die "${FUNCNAME}(): Unrecognized option '$1'"
633 + ;;
634 + *)
635 + die "${FUNCNAME}(): Invalid usage"
636 + ;;
637 + esac
638 + shift
639 + done
640 +
641 + if [[ "$((${major} + ${minor} + ${micro}))" -gt 1 ]]; then
642 + die "${FUNCNAME}(): '--major', '--minor' or '--micro' options cannot be specified simultaneously"
643 + fi
644 +
645 + if [[ "${major}" == "1" ]]; then
646 + python_command="from sys import version_info; print(version_info[0])"
647 + elif [[ "${minor}" == "1" ]]; then
648 + python_command="from sys import version_info; print(version_info[1])"
649 + elif [[ "${micro}" == "1" ]]; then
650 + python_command="from sys import version_info; print(version_info[2])"
651 + else
652 + python_command="from sys import version_info; print('.'.join([str(x) for x in version_info[:2]]))"
653 + fi
654 +
655 + if [[ "${final_ABI}" == "1" ]]; then
656 + "$(PYTHON -f)" -c "${python_command}"
657 + else
658 + "$(PYTHON "${PYTHON_ABI--A}")" -c "${python_command}"
659 + fi
660 +}
661 +
662 # ================================================================================================
663 # =================================== MISCELLANEOUS FUNCTIONS ====================================
664 # ================================================================================================
665 @@ -1022,6 +1264,17 @@
666 fi
667 }
668
669 +_python_initialize_prefix_variables() {
670 + if has "${EAPI:-0}" 0 1 2; then
671 + if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
672 + EROOT="${ROOT%/}${EPREFIX}/"
673 + fi
674 + if [[ -n "${D}" && -z "${ED}" ]]; then
675 + ED="${D%/}${EPREFIX}/"
676 + fi
677 + fi
678 +}
679 +
680 # @FUNCTION: python_convert_shebangs
681 # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
682 # @DESCRIPTION:
683 @@ -1041,6 +1294,7 @@
684 only_executables="1"
685 ;;
686 --)
687 + shift
688 break
689 ;;
690 -*)
691 @@ -1101,8 +1355,8 @@
692 # @FUNCTION: python_mod_exists
693 # @USAGE: <module>
694 # @DESCRIPTION:
695 -# Run with the module name as an argument. it will check if a
696 -# python module is installed and loadable. it will return
697 +# Run with the module name as an argument. It will check if a
698 +# Python module is installed and loadable. It will return
699 # TRUE(0) if the module exists, and FALSE(1) if the module does
700 # not exist.
701 #
702 @@ -1111,21 +1365,210 @@
703 # echo "gtk support enabled"
704 # fi
705 python_mod_exists() {
706 - [[ "$1" ]] || die "${FUNCNAME} requires an argument!"
707 - python -c "import $1" &>/dev/null
708 + if [[ "$#" -ne 1 ]]; then
709 + die "${FUNCNAME}() requires 1 argument"
710 + fi
711 + "$(PYTHON "${PYTHON_ABI--A}")" -c "import $1" &> /dev/null
712 }
713
714 # @FUNCTION: python_tkinter_exists
715 # @DESCRIPTION:
716 -# Run without arguments, checks if python was compiled with Tkinter
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 ! python -c "import Tkinter" >/dev/null 2>&1; then
721 - eerror "You need to recompile python with Tkinter support."
722 - eerror "Try adding: 'dev-lang/python tk'"
723 - eerror "in to /etc/portage/package.use"
724 - echo
725 - die "missing tkinter support with installed python"
726 + if ! "$(PYTHON "${PYTHON_ABI--A}")" -c "from sys import version_info
727 +if version_info[0] == 3:
728 + import tkinter
729 +else:
730 + import Tkinter" &> /dev/null; then
731 + eerror "Python needs to be rebuilt with tkinter support enabled."
732 + eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
733 + eerror "dev-lang/python tk"
734 + die "Python installed without support for tkinter"
735 + fi
736 +}
737 +
738 +# ================================================================================================
739 +# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
740 +# ================================================================================================
741 +
742 +# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
743 +# @DESCRIPTION:
744 +# User-configurable verbosity of tests of Python modules.
745 +# Supported values: 0, 1, 2, 3, 4.
746 +PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
747 +
748 +# @FUNCTION: python_execute_nosetests
749 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
750 +# @DESCRIPTION:
751 +# Execute nosetests for all enabled versions of Python.
752 +python_execute_nosetests() {
753 + local PYTHONPATH_template= separate_build_dirs=
754 +
755 + while (($#)); do
756 + case "$1" in
757 + -P|--PYTHONPATH)
758 + PYTHONPATH_template="$2"
759 + shift
760 + ;;
761 + -s|--separate-build-dirs)
762 + separate_build_dirs="1"
763 + ;;
764 + --)
765 + shift
766 + break
767 + ;;
768 + -*)
769 + die "${FUNCNAME}(): Unrecognized option '$1'"
770 + ;;
771 + *)
772 + break
773 + ;;
774 + esac
775 + shift
776 + done
777 +
778 + python_test_function() {
779 + local evaluated_PYTHONPATH=
780 +
781 + if [[ -n "${PYTHONPATH_template}" ]]; then
782 + evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
783 + if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
784 + unset evaluated_PYTHONPATH
785 + fi
786 + fi
787 +
788 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
789 + echo PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
790 + PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
791 + else
792 + echo nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
793 + nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
794 + fi
795 + }
796 + if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
797 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
798 + else
799 + if [[ -n "${separate_build_dirs}" ]]; then
800 + die "${FUNCNAME}(): Invalid usage"
801 + fi
802 + python_test_function "$@"
803 + fi
804 +}
805 +
806 +# @FUNCTION: python_execute_py.test
807 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
808 +# @DESCRIPTION:
809 +# Execute py.test for all enabled versions of Python.
810 +python_execute_py.test() {
811 + local PYTHONPATH_template= separate_build_dirs=
812 +
813 + while (($#)); do
814 + case "$1" in
815 + -P|--PYTHONPATH)
816 + PYTHONPATH_template="$2"
817 + shift
818 + ;;
819 + -s|--separate-build-dirs)
820 + separate_build_dirs="1"
821 + ;;
822 + --)
823 + shift
824 + break
825 + ;;
826 + -*)
827 + die "${FUNCNAME}(): Unrecognized option '$1'"
828 + ;;
829 + *)
830 + break
831 + ;;
832 + esac
833 + shift
834 + done
835 +
836 + python_test_function() {
837 + local evaluated_PYTHONPATH=
838 +
839 + if [[ -n "${PYTHONPATH_template}" ]]; then
840 + evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
841 + if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
842 + unset evaluated_PYTHONPATH
843 + fi
844 + fi
845 +
846 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
847 + echo PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"
848 + PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"
849 + else
850 + echo py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"
851 + py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"
852 + fi
853 + }
854 + if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
855 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
856 + else
857 + if [[ -n "${separate_build_dirs}" ]]; then
858 + die "${FUNCNAME}(): Invalid usage"
859 + fi
860 + python_test_function "$@"
861 + fi
862 +}
863 +
864 +# @FUNCTION: python_execute_trial
865 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
866 +# @DESCRIPTION:
867 +# Execute trial for all enabled versions of Python.
868 +python_execute_trial() {
869 + local PYTHONPATH_template= separate_build_dirs=
870 +
871 + while (($#)); do
872 + case "$1" in
873 + -P|--PYTHONPATH)
874 + PYTHONPATH_template="$2"
875 + shift
876 + ;;
877 + -s|--separate-build-dirs)
878 + separate_build_dirs="1"
879 + ;;
880 + --)
881 + shift
882 + break
883 + ;;
884 + -*)
885 + die "${FUNCNAME}(): Unrecognized option '$1'"
886 + ;;
887 + *)
888 + break
889 + ;;
890 + esac
891 + shift
892 + done
893 +
894 + python_test_function() {
895 + local evaluated_PYTHONPATH=
896 +
897 + if [[ -n "${PYTHONPATH_template}" ]]; then
898 + evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
899 + if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
900 + unset evaluated_PYTHONPATH
901 + fi
902 + fi
903 +
904 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
905 + echo PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
906 + PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
907 + else
908 + echo trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
909 + trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
910 + fi
911 + }
912 + if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
913 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
914 + else
915 + if [[ -n "${separate_build_dirs}" ]]; then
916 + die "${FUNCNAME}(): Invalid usage"
917 + fi
918 + python_test_function "$@"
919 fi
920 }
921
922 @@ -1165,14 +1608,16 @@
923 # Example:
924 # python_mod_optimize ctypesgencore
925 python_mod_optimize() {
926 + _python_initialize_prefix_variables
927 +
928 # Check if phase is pkg_postinst().
929 - [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()"
930 + [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()"
931
932 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
933 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=()
934
935 # Strip trailing slash from ROOT.
936 - root="${ROOT%/}"
937 + root="${EROOT%/}"
938
939 # Respect ROOT and options passed to compileall.py.
940 while (($#)); do
941 @@ -1185,11 +1630,11 @@
942 shift
943 ;;
944 -*)
945 - ewarn "${FUNCNAME}: Ignoring option '$1'"
946 + ewarn "${FUNCNAME}(): Ignoring option '$1'"
947 ;;
948 *)
949 - if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
950 - die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
951 + if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
952 + die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
953 elif [[ "$1" =~ ^/ ]]; then
954 if [[ -d "${root}/$1" ]]; then
955 other_dirs+=("${root}/$1")
956 @@ -1270,7 +1715,7 @@
957 local myroot mydirs=() myfiles=() myopts=() return_code="0"
958
959 # strip trailing slash
960 - myroot="${ROOT%/}"
961 + myroot="${EROOT%/}"
962
963 # respect ROOT and options passed to compileall.py
964 while (($#)); do
965 @@ -1283,7 +1728,7 @@
966 shift
967 ;;
968 -*)
969 - ewarn "${FUNCNAME}: Ignoring option '$1'"
970 + ewarn "${FUNCNAME}(): Ignoring option '$1'"
971 ;;
972 *)
973 if [[ -d "${myroot}"/$1 ]]; then
974 @@ -1330,19 +1775,21 @@
975 #
976 # This function should only be run in pkg_postrm().
977 python_mod_cleanup() {
978 + _python_initialize_prefix_variables
979 +
980 local path py_file PYTHON_ABI SEARCH_PATH=() root
981
982 # Check if phase is pkg_postrm().
983 - [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
984 + [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()"
985
986 # Strip trailing slash from ROOT.
987 - root="${ROOT%/}"
988 + root="${EROOT%/}"
989
990 if (($#)); then
991 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
992 while (($#)); do
993 - if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
994 - die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
995 + if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
996 + die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
997 elif [[ "$1" =~ ^/ ]]; then
998 SEARCH_PATH+=("${root}/${1#/}")
999 else
1000 @@ -1409,9 +1856,14 @@
1001 # Run without arguments and it will export the version of python
1002 # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
1003 python_version() {
1004 + if ! has "${EAPI:-0}" 0 1 2; then
1005 + eerror "Use PYTHON() and/or python_get_*() instead of python_version()."
1006 + die "${FUNCNAME}() cannot be used in this EAPI"
1007 + fi
1008 +
1009 [[ -n "${PYVER}" ]] && return 0
1010 local tmpstr
1011 - python="${python:-/usr/bin/python}"
1012 + python="${python:-${EPREFIX}/usr/bin/python}"
1013 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
1014 export PYVER_ALL="${tmpstr#Python }"
1015 export PYVER_MAJOR="${PYVER_ALL:0:1}"
1016 @@ -1433,17 +1885,19 @@
1017 #
1018 python_mod_compile() {
1019 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1020 + eerror "Use python_mod_optimize() instead of python_mod_compile()."
1021 die "${FUNCNAME}() cannot be used in this EAPI"
1022 fi
1023
1024 + _python_initialize_prefix_variables
1025 +
1026 local f myroot myfiles=()
1027
1028 # Check if phase is pkg_postinst()
1029 - [[ ${EBUILD_PHASE} != postinst ]] &&\
1030 - die "${FUNCNAME} should only be run in pkg_postinst()"
1031 + [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() should only be run in pkg_postinst()"
1032
1033 # strip trailing slash
1034 - myroot="${ROOT%/}"
1035 + myroot="${EROOT%/}"
1036
1037 # respect ROOT
1038 for f in "$@"; do