/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.95 Revision 1.104
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.104 2010/10/25 11:54:19 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) 19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_SUPPORTED_ABIS=(${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
26
27_python_set_IUSE() {
28 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI
29
30 _PYTHON_ABIS_USE_FLAGS=""
31 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
32
33 for PYTHON_ABI in "${_PYTHON_SUPPORTED_ABIS[@]}"; do
34 support_ABI="1"
35 while read restricted_ABI; do
36 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
37 support_ABI="0"
38 break
39 fi
40 done <<< "${restricted_ABIs}"
41 [[ "${support_ABI}" == "1" ]] && _PYTHON_ABIS_USE_FLAGS+="${_PYTHON_ABIS_USE_FLAGS:+ }python_abis_${PYTHON_ABI}"
42 done
43
44 IUSE="${_PYTHON_ABIS_USE_FLAGS}"
45}
46
47if ! has "${EAPI:-0}" 0 1 2 3 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
48 _python_set_IUSE
49fi
50unset -f _python_set_IUSE
21 51
22# @ECLASS-VARIABLE: PYTHON_DEPEND 52# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 53# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 54# Specification of dependency on dev-lang/python.
25# Syntax: 55# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 57# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 58# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 59# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 60# maximal_version: <maximal_major_version.maximal_minor_version>
31 61
32_parse_PYTHON_DEPEND() { 62_python_parse_PYTHON_DEPEND() {
33 local major_version maximal_version minimal_version python_all="0" 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 63 local major_version maximal_version minimal_version python_all="0" 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
34 64
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 65 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 66 version_components_groups="${PYTHON_DEPEND}"
37 67
153} 183}
154 184
155DEPEND=">=app-admin/eselect-python-20091230" 185DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 186RDEPEND="${DEPEND}"
157 187
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 188if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 189 _python_parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON."
165 die "NEED_PYTHON cannot be used in this EAPI"
166 fi
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 190else
171 _PYTHON_ATOMS=("dev-lang/python") 191 _PYTHON_ATOMS=("dev-lang/python")
172fi 192fi
193unset -f _python_parse_PYTHON_DEPEND
194
195if [[ -n "${NEED_PYTHON}" ]]; then
196 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
197 die "NEED_PYTHON variable is banned"
198fi
173 199
174# @ECLASS-VARIABLE: PYTHON_USE_WITH 200# @ECLASS-VARIABLE: PYTHON_USE_WITH
175# @DESCRIPTION: 201# @DESCRIPTION:
176# Set this to a space separated list of USE flags 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.
177 203
182# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT 208# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
183# @DESCRIPTION: 209# @DESCRIPTION:
184# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or 210# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
185# PYTHON_USE_WITH_OR atoms conditional under a USE flag. 211# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
186 212
187# @FUNCTION: python_pkg_setup
188# @DESCRIPTION:
189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
190# are respected. Only exported if one of those variables is set.
191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 213if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
192 python_pkg_setup() {
193 # Check if phase is pkg_setup().
194 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
195
196 python_pkg_setup_fail() {
197 eerror "${1}"
198 die "${1}"
199 }
200
201 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
202 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
203 use ${PYTHON_USE_WITH_OPT#!} && return
204 else
205 use !${PYTHON_USE_WITH_OPT} && return
206 fi
207 fi
208
209 python_pkg_setup_check_USE_flags() {
210 local pyatom use
211 pyatom="$(python_get_implementational_package)"
212
213 for use in ${PYTHON_USE_WITH}; do
214 if ! has_version "${pyatom}[${use}]"; then
215 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
216 fi
217 done
218
219 for use in ${PYTHON_USE_WITH_OR}; do
220 if has_version "${pyatom}[${use}]"; then
221 return
222 fi
223 done
224
225 if [[ ${PYTHON_USE_WITH_OR} ]]; then
226 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
227 fi
228 }
229
230 if _python_package_supporting_installation_for_multiple_python_abis; then
231 python_execute_function -q python_pkg_setup_check_USE_flags
232 else
233 python_pkg_setup_check_USE_flags
234 fi
235
236 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
237 }
238
239 EXPORT_FUNCTIONS pkg_setup
240
241 _PYTHON_USE_WITH_ATOMS_ARRAY=() 214 _PYTHON_USE_WITH_ATOMS_ARRAY=()
242 if [[ -n "${PYTHON_USE_WITH}" ]]; then 215 if [[ -n "${PYTHON_USE_WITH}" ]]; then
243 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 216 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
244 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]") 217 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
245 done 218 done
246 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 219 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
247 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 220 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
248 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 221 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
249 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") 222 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
264 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY 237 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
265fi 238fi
266 239
267unset _PYTHON_ATOMS 240unset _PYTHON_ATOMS
268 241
242# @FUNCTION: python_abi_depend
243# @USAGE: [-e|--exclude-ABIs Python_ABIs] [-i|--include-ABIs Python_ABIs] [--] <dependency_atom> [dependency_atoms]
244# @DESCRIPTION:
245# Print dependency atoms with USE dependencies for Python ABIs added.
246# If --exclude-ABIs option is specified, then Python ABIs matching its argument are not used.
247# If --include-ABIs option is specified, then only Python ABIs matching its argument are used.
248# --exclude-ABIs and --include-ABIs options cannot be specified simultaneously.
249python_abi_depend() {
250 local atom atom_index atoms=() exclude_ABIs="0" excluded_ABI excluded_ABIs include_ABIs="0" included_ABI included_ABIs support_ABI USE_dependencies USE_flag USE_flag_index USE_flags=()
251
252 if has "${EAPI:-0}" 0 1 2 3; then
253 die "${FUNCNAME}() cannot be used in this EAPI"
254 fi
255
256 if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
257 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
258 fi
259
260 while (($#)); do
261 case "$1" in
262 -e|--exclude-ABIs)
263 exclude_ABIs="1"
264 excluded_ABIs="${2// /$'\n'}"
265 shift
266 ;;
267 -i|--include-ABIs)
268 include_ABIs="1"
269 included_ABIs="${2// /$'\n'}"
270 shift
271 ;;
272 --)
273 shift
274 break
275 ;;
276 -*)
277 die "${FUNCNAME}(): Unrecognized option '$1'"
278 ;;
279 *)
280 break
281 ;;
282 esac
283 shift
284 done
285
286 if [[ "${exclude_ABIs}" == "1" && "${include_ABIs}" == "1" ]]; then
287 die "${FUNCNAME}(): '--exclude-ABIs' and '--include-ABIs' options cannot be specified simultaneously"
288 fi
289
290 if [[ "$#" -eq 0 ]]; then
291 die "${FUNCNAME}(): Missing dependency atoms"
292 fi
293
294 atoms=("$@")
295
296 if [[ "${exclude_ABIs}" == "0" && "${include_ABIs}" == "0" ]]; then
297 USE_dependencies="$(printf ",%s?" ${_PYTHON_ABIS_USE_FLAGS})"
298 USE_dependencies="${USE_dependencies#,}"
299
300 for atom_index in "${!atoms[@]}"; do
301 atom="${atoms[${atom_index}]}"
302
303 if [[ "${atom}" == *"["*"]" ]]; then
304 echo -n "${atom%]},"
305 else
306 echo -n "${atom}["
307 fi
308 echo -n "${USE_dependencies}]"
309
310 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
311 echo -n " "
312 fi
313 done
314 else
315 if [[ "${exclude_ABIs}" == "1" ]]; then
316 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
317 while read excluded_ABI; do
318 support_ABI="1"
319 if [[ "${USE_flag}" == python_abis_${excluded_ABI} ]]; then
320 support_ABI="0"
321 break
322 fi
323 done <<< "${excluded_ABIs}"
324 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
325 done
326 elif [[ "${include_ABIs}" == "1" ]]; then
327 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
328 while read included_ABI; do
329 support_ABI="0"
330 if [[ "${USE_flag}" == python_abis_${included_ABI} ]]; then
331 support_ABI="1"
332 break
333 fi
334 done <<< "${included_ABIs}"
335 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
336 done
337 else
338 die "${FUNCNAME}(): Internal error"
339 fi
340
341 for USE_flag_index in "${!USE_flags[@]}"; do
342 USE_flag="${USE_flags[${USE_flag_index}]}"
343 USE_dependencies="${USE_flag}"
344
345 echo -n "${USE_flag}? ( "
346
347 for atom_index in "${!atoms[@]}"; do
348 atom="${atoms[${atom_index}]}"
349
350 if [[ "${atom}" == *"["*"]" ]]; then
351 echo -n "${atom%]},"
352 else
353 echo -n "${atom}["
354 fi
355 echo -n "${USE_dependencies}]"
356
357 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
358 echo -n " "
359 fi
360 done
361
362 echo -n " )"
363
364 if [[ "${USE_flag_index}" -ne $((${#USE_flags[@]} - 1)) ]]; then
365 echo -n " "
366 fi
367 done
368 fi
369}
370
371# ================================================================================================
372# =================================== MISCELLANEOUS FUNCTIONS ====================================
373# ================================================================================================
374
375_python_implementation() {
376 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
377 return 0
378 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
379 return 0
380 else
381 return 1
382 fi
383}
384
385_python_package_supporting_installation_for_multiple_python_abis() {
386 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
387 die "${FUNCNAME}() cannot be used in global scope"
388 fi
389
390 if has "${EAPI:-0}" 0 1 2 3 4; then
391 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
392 return 0
393 else
394 return 1
395 fi
396 else
397 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
398 fi
399}
400
401_python_abi-specific_local_scope() {
402 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
403}
404
405_python_initialize_prefix_variables() {
406 if has "${EAPI:-0}" 0 1 2; then
407 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
408 EROOT="${ROOT%/}${EPREFIX}/"
409 fi
410 if [[ -n "${D}" && -z "${ED}" ]]; then
411 ED="${D%/}${EPREFIX}/"
412 fi
413 fi
414}
415
416unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
417
418_python_initial_sanity_checks() {
419 if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
420 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
421 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
422 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
423 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
424 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
425 fi
426 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
427 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
428 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
429 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
430 fi
431 fi
432}
433
434_python_final_sanity_checks() {
435 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
436 local PYTHON_ABI="${PYTHON_ABI}"
437 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
438 # Ensure that appropriate version of Python is installed.
439 if ! has_version "$(python_get_implementational_package)"; then
440 die "$(python_get_implementational_package) is not installed"
441 fi
442
443 # Ensure that EPYTHON variable is respected.
444 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
445 eerror "Path to 'python': '$(type -p python)'"
446 eerror "ABI: '${ABI}'"
447 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
448 eerror "EPYTHON: '$(PYTHON)'"
449 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
450 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
451 die "'python' does not respect EPYTHON variable"
452 fi
453 done
454 fi
455 PYTHON_SANITY_CHECKS_EXECUTED="1"
456}
457
458# @ECLASS-VARIABLE: PYTHON_COLORS
459# @DESCRIPTION:
460# User-configurable colored output.
461PYTHON_COLORS="${PYTHON_COLORS:-0}"
462
463_python_set_color_variables() {
464 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
465 _BOLD=$'\e[1m'
466 _RED=$'\e[1;31m'
467 _GREEN=$'\e[1;32m'
468 _BLUE=$'\e[1;34m'
469 _CYAN=$'\e[1;36m'
470 _NORMAL=$'\e[0m'
471 else
472 _BOLD=
473 _RED=
474 _GREEN=
475 _BLUE=
476 _CYAN=
477 _NORMAL=
478 fi
479}
480
481unset PYTHON_PKG_SETUP_EXECUTED
482
483_python_check_python_pkg_setup_execution() {
484 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
485
486 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
487 die "python_pkg_setup() not called"
488 fi
489}
490
491# @FUNCTION: python_pkg_setup
492# @DESCRIPTION:
493# Perform sanity checks and initialize environment.
494#
495# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
496# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
497#
498# This function can be used only in pkg_setup() phase.
499python_pkg_setup() {
500 # Check if phase is pkg_setup().
501 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
502
503 if [[ "$#" -ne 0 ]]; then
504 die "${FUNCNAME}() does not accept arguments"
505 fi
506
507 if _python_package_supporting_installation_for_multiple_python_abis; then
508 _python_calculate_PYTHON_ABIS
509 export EPYTHON="$(PYTHON -f)"
510 else
511 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
512 fi
513
514 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
515 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
516 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
517 use ${PYTHON_USE_WITH_OPT#!} && return
518 else
519 use !${PYTHON_USE_WITH_OPT} && return
520 fi
521 fi
522
523 python_pkg_setup_check_USE_flags() {
524 local python_atom USE_flag
525 python_atom="$(python_get_implementational_package)"
526
527 for USE_flag in ${PYTHON_USE_WITH}; do
528 if ! has_version "${python_atom}[${USE_flag}]"; then
529 eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
530 die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
531 fi
532 done
533
534 for USE_flag in ${PYTHON_USE_WITH_OR}; do
535 if has_version "${python_atom}[${USE_flag}]"; then
536 return
537 fi
538 done
539
540 if [[ ${PYTHON_USE_WITH_OR} ]]; then
541 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
542 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
543 fi
544 }
545
546 if _python_package_supporting_installation_for_multiple_python_abis; then
547 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
548 else
549 python_pkg_setup_check_USE_flags
550 fi
551
552 unset -f python_pkg_setup_check_USE_flags
553 fi
554
555 PYTHON_PKG_SETUP_EXECUTED="1"
556}
557
558if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
559 EXPORT_FUNCTIONS pkg_setup
560fi
561
562# @FUNCTION: python_convert_shebangs
563# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
564# @DESCRIPTION:
565# Convert shebangs in specified files. Directories can be specified only with --recursive option.
566python_convert_shebangs() {
567 _python_check_python_pkg_setup_execution
568
569 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
570
571 while (($#)); do
572 case "$1" in
573 -r|--recursive)
574 recursive="1"
575 ;;
576 -q|--quiet)
577 quiet="1"
578 ;;
579 -x|--only-executables)
580 only_executables="1"
581 ;;
582 --)
583 shift
584 break
585 ;;
586 -*)
587 die "${FUNCNAME}(): Unrecognized option '$1'"
588 ;;
589 *)
590 break
591 ;;
592 esac
593 shift
594 done
595
596 if [[ "$#" -eq 0 ]]; then
597 die "${FUNCNAME}(): Missing Python version and files or directories"
598 elif [[ "$#" -eq 1 ]]; then
599 die "${FUNCNAME}(): Missing files or directories"
600 fi
601
602 python_version="$1"
603 shift
604
605 for argument in "$@"; do
606 if [[ ! -e "${argument}" ]]; then
607 die "${FUNCNAME}(): '${argument}' does not exist"
608 elif [[ -f "${argument}" ]]; then
609 files+=("${argument}")
610 elif [[ -d "${argument}" ]]; then
611 if [[ "${recursive}" == "1" ]]; then
612 while read -d $'\0' -r file; do
613 files+=("${file}")
614 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
615 else
616 die "${FUNCNAME}(): '${argument}' is not a regular file"
617 fi
618 else
619 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
620 fi
621 done
622
623 for file in "${files[@]}"; do
624 file="${file#./}"
625 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
626
627 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
628 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
629
630 if [[ "${quiet}" == "0" ]]; then
631 einfo "Converting shebang in '${file}'"
632 fi
633
634 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
635
636 # Delete potential whitespace after "#!".
637 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
638 fi
639 done
640}
641
642# @FUNCTION: python_clean_installation_image
643# @USAGE: [-q|--quiet]
644# @DESCRIPTION:
645# Delete needless files in installation image.
646python_clean_installation_image() {
647 _python_check_python_pkg_setup_execution
648 _python_initialize_prefix_variables
649
650 local file files=() quiet="0"
651
652 # Check if phase is src_install().
653 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
654
655 while (($#)); do
656 case "$1" in
657 -q|--quiet)
658 quiet="1"
659 ;;
660 -*)
661 die "${FUNCNAME}(): Unrecognized option '$1'"
662 ;;
663 *)
664 die "${FUNCNAME}(): Invalid usage"
665 ;;
666 esac
667 shift
668 done
669
670 while read -d $'\0' -r file; do
671 files+=("${file}")
672 done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
673
674 if [[ "${#files[@]}" -gt 0 ]]; then
675 if [[ "${quiet}" == "0" ]]; then
676 ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
677 fi
678 for file in "${files[@]}"; do
679 if [[ "${quiet}" == "0" ]]; then
680 ewarn " ${file}"
681 fi
682 rm -f "${file}"
683
684 # Delete empty __pycache__ directories.
685 if [[ "${file%/*}" == *"/__pycache__" ]]; then
686 rmdir "${file%/*}" 2> /dev/null
687 fi
688 done
689 fi
690
691 python_clean_sitedirs() {
692 if [[ -d "${ED}$(python_get_sitedir)" ]]; then
693 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
694 fi
695 }
696 if _python_package_supporting_installation_for_multiple_python_abis; then
697 python_execute_function -q python_clean_sitedirs
698 else
699 python_clean_sitedirs
700 fi
701
702 unset -f python_clean_sitedirs
703}
704
269# ================================================================================================ 705# ================================================================================================
270# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ 706# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
271# ================================================================================================ 707# ================================================================================================
272 708
273# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 709# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
279# @DESCRIPTION: 715# @DESCRIPTION:
280# Set this to export phase functions for the following ebuild phases: 716# Set this to export phase functions for the following ebuild phases:
281# src_prepare, src_configure, src_compile, src_test, src_install. 717# src_prepare, src_configure, src_compile, src_test, src_install.
282if ! has "${EAPI:-0}" 0 1; then 718if ! has "${EAPI:-0}" 0 1; then
283 python_src_prepare() { 719 python_src_prepare() {
720 _python_check_python_pkg_setup_execution
721
284 if ! _python_package_supporting_installation_for_multiple_python_abis; then 722 if ! _python_package_supporting_installation_for_multiple_python_abis; then
285 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 723 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
286 fi 724 fi
287 725
726 if [[ "$#" -ne 0 ]]; then
727 die "${FUNCNAME}() does not accept arguments"
728 fi
729
288 python_copy_sources 730 python_copy_sources
289 } 731 }
290 732
291 for python_default_function in src_configure src_compile src_test src_install; do 733 for python_default_function in src_configure src_compile src_test src_install; do
292 eval "python_${python_default_function}() { 734 eval "python_${python_default_function}() {
735 _python_check_python_pkg_setup_execution
736
293 if ! _python_package_supporting_installation_for_multiple_python_abis; then 737 if ! _python_package_supporting_installation_for_multiple_python_abis; then
294 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 738 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
295 fi 739 fi
296 740
297 python_execute_function -d -s \"\$@\" 741 python_execute_function -d -s -- \"\$@\"
298 }" 742 }"
299 done 743 done
300 unset python_default_function 744 unset python_default_function
301 745
302 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
303 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 747 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
304 fi 748 fi
305fi 749fi
306 750
751if has "${EAPI:-0}" 0 1 2 3; then
307unset PYTHON_ABIS 752 unset PYTHON_ABIS
753fi
308 754
309# @FUNCTION: validate_PYTHON_ABIS 755_python_calculate_PYTHON_ABIS() {
310# @DESCRIPTION:
311# Ensure that PYTHON_ABIS variable has valid value.
312# This function usually should not be directly called in ebuilds.
313validate_PYTHON_ABIS() {
314 if ! _python_package_supporting_installation_for_multiple_python_abis; then 756 if ! _python_package_supporting_installation_for_multiple_python_abis; then
315 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 757 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
316 fi 758 fi
317 759
318 _python_initial_sanity_checks 760 _python_initial_sanity_checks
319 761
320 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
321 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 762 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
322 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 763 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
323 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 764
765 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
324 766
325 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 767 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
326 local cpython_enabled="0" 768 local cpython_enabled="0"
327 769
328 if [[ -z "${USE_PYTHON}" ]]; then 770 if [[ -z "${USE_PYTHON}" ]]; then
329 die "USE_PYTHON variable is empty" 771 die "USE_PYTHON variable is empty"
330 fi 772 fi
331 773
332 for PYTHON_ABI in ${USE_PYTHON}; do 774 for PYTHON_ABI in ${USE_PYTHON}; do
333 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 775 if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then
334 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 776 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
335 fi 777 fi
336 778
337 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 779 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
338 cpython_enabled="1" 780 cpython_enabled="1"
339 fi 781 fi
340 782
341 support_ABI="1" 783 support_ABI="1"
342 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 784 while read restricted_ABI; do
343 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 785 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
344 support_ABI="0" 786 support_ABI="0"
345 break 787 break
346 fi 788 fi
347 done 789 done <<< "${restricted_ABIs}"
348 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 790 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
349 done 791 done
350 792
351 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 793 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
352 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 794 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
355 if [[ "${cpython_enabled}" == "0" ]]; then 797 if [[ "${cpython_enabled}" == "0" ]]; then
356 die "USE_PYTHON variable does not enable any CPython ABI" 798 die "USE_PYTHON variable does not enable any CPython ABI"
357 fi 799 fi
358 else 800 else
359 local python_version python2_version= python3_version= support_python_major_version 801 local python_version python2_version= python3_version= support_python_major_version
802
803 if ! has_version "dev-lang/python"; then
804 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
805 fi
360 806
361 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 807 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
362 808
363 if has_version "=dev-lang/python-2*"; then 809 if has_version "=dev-lang/python-2*"; then
364 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then 810 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
367 813
368 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 814 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
369 815
370 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 816 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
371 support_python_major_version="1" 817 support_python_major_version="1"
372 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 818 while read restricted_ABI; do
373 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 819 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
374 support_python_major_version="0" 820 support_python_major_version="0"
375 fi 821 fi
376 done 822 done <<< "${restricted_ABIs}"
377 [[ "${support_python_major_version}" == "1" ]] && break 823 [[ "${support_python_major_version}" == "1" ]] && break
378 done 824 done
379 if [[ "${support_python_major_version}" == "1" ]]; then 825 if [[ "${support_python_major_version}" == "1" ]]; then
380 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 826 while read restricted_ABI; do
381 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 827 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
382 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 828 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
383 fi 829 fi
384 done 830 done <<< "${restricted_ABIs}"
385 else 831 else
386 python2_version="" 832 python2_version=""
387 fi 833 fi
388 fi 834 fi
389 835
394 840
395 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 841 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
396 842
397 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 843 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
398 support_python_major_version="1" 844 support_python_major_version="1"
399 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 845 while read restricted_ABI; do
400 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 846 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
401 support_python_major_version="0" 847 support_python_major_version="0"
402 fi 848 fi
403 done 849 done <<< "${restricted_ABIs}"
404 [[ "${support_python_major_version}" == "1" ]] && break 850 [[ "${support_python_major_version}" == "1" ]] && break
405 done 851 done
406 if [[ "${support_python_major_version}" == "1" ]]; then 852 if [[ "${support_python_major_version}" == "1" ]]; then
407 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 853 while read restricted_ABI; do
408 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 854 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
409 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 855 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
410 fi 856 fi
411 done 857 done <<< "${restricted_ABIs}"
412 else 858 else
413 python3_version="" 859 python3_version=""
414 fi 860 fi
415 fi 861 fi
416 862
432 fi 878 fi
433 879
434 _python_final_sanity_checks 880 _python_final_sanity_checks
435} 881}
436 882
883_python_prepare_flags() {
884 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
885
886 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
887 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
888 for prefix in PYTHON_USER_ PYTHON_; do
889 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
890 eval "array=(\"\${${prefix}${variable}[@]}\")"
891 for element in "${array[@]}"; do
892 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
893 pattern="${element%% *}"
894 element="${element#* }"
895 operator="${element%% *}"
896 flags="${element#* }"
897 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
898 if [[ "${operator}" == "+" ]]; then
899 eval "export ${variable}+=\"\${variable:+ }${flags}\""
900 elif [[ "${operator}" == "-" ]]; then
901 flags="${flags// /$'\n'}"
902 old_value="${!variable// /$'\n'}"
903 new_value=""
904 while read old_flag; do
905 while read deleted_flag; do
906 if [[ "${old_flag}" == ${deleted_flag} ]]; then
907 continue 2
908 fi
909 done <<< "${flags}"
910 new_value+="${new_value:+ }${old_flag}"
911 done <<< "${old_value}"
912 eval "export ${variable}=\"\${new_value}\""
913 fi
914 fi
915 else
916 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
917 fi
918 done
919 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
920 die "${prefix}${variable} should be indexed array"
921 fi
922 done
923 done
924}
925
926_python_restore_flags() {
927 local variable
928
929 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
930 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
931 unset _PYTHON_SAVED_${variable}
932 done
933}
934
437# @FUNCTION: python_execute_function 935# @FUNCTION: python_execute_function
438# @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] 936# @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]
439# @DESCRIPTION: 937# @DESCRIPTION:
440# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 938# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
441# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 939# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
442python_execute_function() { 940python_execute_function() {
941 _python_check_python_pkg_setup_execution
942
443 if ! _python_package_supporting_installation_for_multiple_python_abis; then 943 if ! _python_package_supporting_installation_for_multiple_python_abis; then
444 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 944 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
445 fi 945 fi
446 946
447 _python_set_color_variables 947 _python_set_color_variables
448 948
449 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= 949 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir=
450 950
451 while (($#)); do 951 while (($#)); do
452 case "$1" in 952 case "$1" in
453 --action-message) 953 --action-message)
454 action_message_template="$2" 954 action_message_template="$2"
541 fi 1041 fi
542 function="python_default_function" 1042 function="python_default_function"
543 fi 1043 fi
544 1044
545 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 1045 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
546 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 1046 if _python_abi-specific_local_scope; then
547 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
548 die "${FUNCNAME}(): Invalid call stack" 1047 die "${FUNCNAME}(): Invalid call stack"
549 fi 1048 fi
550 done
551 1049
552 if [[ "${quiet}" == "0" ]]; then 1050 if [[ "${quiet}" == "0" ]]; then
553 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 1051 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
554 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 1052 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
555 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 1053 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
561 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 1059 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
562 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 1060 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
563 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 1061 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
564 fi 1062 fi
565 1063
566 validate_PYTHON_ABIS 1064 _python_calculate_PYTHON_ABIS
567 if [[ "${final_ABI}" == "1" ]]; then 1065 if [[ "${final_ABI}" == "1" ]]; then
568 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 1066 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
569 else 1067 else
570 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 1068 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
571 fi 1069 fi
572 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1070 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1071 _python_prepare_flags
1072
573 if [[ "${quiet}" == "0" ]]; then 1073 if [[ "${quiet}" == "0" ]]; then
574 if [[ -n "${action_message_template}" ]]; then 1074 if [[ -n "${action_message_template}" ]]; then
575 action_message="$(eval echo -n "${action_message_template}")" 1075 eval "action_message=\"${action_message_template}\""
576 else 1076 else
577 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 1077 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
578 fi 1078 fi
579 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 1079 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
580 fi 1080 fi
598 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 1098 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
599 else 1099 else
600 EPYTHON="$(PYTHON)" "${function}" "$@" 1100 EPYTHON="$(PYTHON)" "${function}" "$@"
601 fi 1101 fi
602 1102
603 if [[ "$?" != "0" ]]; then 1103 return_code="$?"
1104
1105 _python_restore_flags
1106
1107 if [[ "${return_code}" -ne 0 ]]; then
604 if [[ -n "${failure_message_template}" ]]; then 1108 if [[ -n "${failure_message_template}" ]]; then
605 failure_message="$(eval echo -n "${failure_message_template}")" 1109 eval "failure_message=\"${failure_message_template}\""
606 else 1110 else
607 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 1111 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
608 fi 1112 fi
609 1113
610 if [[ "${nonfatal}" == "1" ]]; then 1114 if [[ "${nonfatal}" == "1" ]]; then
611 if [[ "${quiet}" == "0" ]]; then 1115 if [[ "${quiet}" == "0" ]]; then
612 ewarn "${_RED}${failure_message}${_NORMAL}" 1116 ewarn "${failure_message}"
613 fi 1117 fi
614 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 1118 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
615 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 1119 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
616 local enabled_PYTHON_ABIS= other_PYTHON_ABI 1120 local enabled_PYTHON_ABIS= other_PYTHON_ABI
617 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 1121 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
618 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 1122 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
619 done 1123 done
620 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 1124 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
621 fi 1125 fi
622 if [[ "${quiet}" == "0" ]]; then 1126 if [[ "${quiet}" == "0" ]]; then
623 ewarn "${_RED}${failure_message}${_NORMAL}" 1127 ewarn "${failure_message}"
624 fi 1128 fi
625 if [[ -z "${PYTHON_ABIS}" ]]; then 1129 if [[ -z "${PYTHON_ABIS}" ]]; then
626 die "${function}() function failed with all enabled Python ABIs" 1130 die "${function}() function failed with all enabled Python ABIs"
627 fi 1131 fi
628 else 1132 else
665# @FUNCTION: python_copy_sources 1169# @FUNCTION: python_copy_sources
666# @USAGE: <directory="${S}"> [directory] 1170# @USAGE: <directory="${S}"> [directory]
667# @DESCRIPTION: 1171# @DESCRIPTION:
668# Copy unpacked sources of current package to separate build directory for each Python ABI. 1172# Copy unpacked sources of current package to separate build directory for each Python ABI.
669python_copy_sources() { 1173python_copy_sources() {
1174 _python_check_python_pkg_setup_execution
1175
670 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1176 if ! _python_package_supporting_installation_for_multiple_python_abis; then
671 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1177 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
672 fi 1178 fi
673 1179
674 local dir dirs=() PYTHON_ABI 1180 local dir dirs=() PYTHON_ABI
675 1181
676 if [[ "$#" -eq 0 ]]; then 1182 if [[ "$#" -eq 0 ]]; then
677 if [[ "${WORKDIR}" == "${S}" ]]; then 1183 if [[ "${WORKDIR}" == "${S}" ]]; then
678 die "${FUNCNAME}() cannot be used" 1184 die "${FUNCNAME}() cannot be used with current value of S variable"
679 fi 1185 fi
680 dirs=("${S%/}") 1186 dirs=("${S%/}")
681 else 1187 else
682 dirs=("$@") 1188 dirs=("$@")
683 fi 1189 fi
684 1190
685 validate_PYTHON_ABIS 1191 _python_calculate_PYTHON_ABIS
686 for PYTHON_ABI in ${PYTHON_ABIS}; do 1192 for PYTHON_ABI in ${PYTHON_ABIS}; do
687 for dir in "${dirs[@]}"; do 1193 for dir in "${dirs[@]}"; do
688 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 1194 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
689 done 1195 done
690 done 1196 done
695# @DESCRIPTION: 1201# @DESCRIPTION:
696# Generate wrapper scripts. Existing files are overwritten only with --force option. 1202# Generate wrapper scripts. Existing files are overwritten only with --force option.
697# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1203# If --respect-EPYTHON option is specified, then generated wrapper scripts will
698# respect EPYTHON variable at run time. 1204# respect EPYTHON variable at run time.
699python_generate_wrapper_scripts() { 1205python_generate_wrapper_scripts() {
1206 _python_check_python_pkg_setup_execution
1207
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1208 if ! _python_package_supporting_installation_for_multiple_python_abis; then
701 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1209 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 1210 fi
703 1211
704 _python_initialize_prefix_variables 1212 _python_initialize_prefix_variables
732 1240
733 if [[ "$#" -eq 0 ]]; then 1241 if [[ "$#" -eq 0 ]]; then
734 die "${FUNCNAME}(): Missing arguments" 1242 die "${FUNCNAME}(): Missing arguments"
735 fi 1243 fi
736 1244
737 validate_PYTHON_ABIS 1245 _python_calculate_PYTHON_ABIS
738 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1246 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
739 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1247 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
740 python2_enabled="1" 1248 python2_enabled="1"
741 fi 1249 fi
742 done 1250 done
846 fi 1354 fi
847 cat << EOF >> "${file}" 1355 cat << EOF >> "${file}"
848 1356
849wrapper_script_path = os.path.realpath(sys.argv[0]) 1357wrapper_script_path = os.path.realpath(sys.argv[0])
850target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1358target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1359os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
851os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1360os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
852os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1361os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
853if not os.path.exists(target_executable_path): 1362if not os.path.exists(target_executable_path):
854 sys.stderr.write("'%s' does not exist\n" % target_executable_path) 1363 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
855 sys.exit(1) 1364 sys.exit(1)
897 1406
898# ================================================================================================ 1407# ================================================================================================
899# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1408# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
900# ================================================================================================ 1409# ================================================================================================
901 1410
1411unset EPYTHON PYTHON_ABI
1412
902# @FUNCTION: python_set_active_version 1413# @FUNCTION: python_set_active_version
903# @USAGE: <CPython_ABI|2|3> 1414# @USAGE: <CPython_ABI|2|3>
904# @DESCRIPTION: 1415# @DESCRIPTION:
905# Set specified version of CPython as active version of Python. 1416# Set specified version of CPython as active version of Python.
1417#
1418# This function can be used only in pkg_setup() phase.
906python_set_active_version() { 1419python_set_active_version() {
1420 # Check if phase is pkg_setup().
1421 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1422
907 if _python_package_supporting_installation_for_multiple_python_abis; then 1423 if _python_package_supporting_installation_for_multiple_python_abis; then
908 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1424 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
909 fi 1425 fi
910 1426
911 if [[ "$#" -ne 1 ]]; then 1427 if [[ "$#" -ne 1 ]]; then
912 die "${FUNCNAME}() requires 1 argument" 1428 die "${FUNCNAME}() requires 1 argument"
913 fi 1429 fi
914 1430
915 _python_initial_sanity_checks 1431 _python_initial_sanity_checks
916 1432
1433 if [[ -z "${PYTHON_ABI}" ]]; then
917 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1434 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
918 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1435 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
919 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1436 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
920 fi 1437 fi
921 export EPYTHON="$(PYTHON "$1")" 1438 export EPYTHON="$(PYTHON "$1")"
922 elif [[ "$1" == "2" ]]; then 1439 elif [[ "$1" == "2" ]]; then
923 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1440 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
924 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1441 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
925 fi 1442 fi
926 export EPYTHON="$(PYTHON -2)" 1443 export EPYTHON="$(PYTHON -2)"
927 elif [[ "$1" == "3" ]]; then 1444 elif [[ "$1" == "3" ]]; then
928 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1445 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
929 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1446 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
930 fi 1447 fi
931 export EPYTHON="$(PYTHON -3)" 1448 export EPYTHON="$(PYTHON -3)"
932 else 1449 else
933 die "${FUNCNAME}(): Unrecognized argument '$1'" 1450 die "${FUNCNAME}(): Unrecognized argument '$1'"
934 fi 1451 fi
935 1452
936 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1453 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
937 # so it does not need to be exported to subprocesses. 1454 # so it does not need to be exported to subprocesses.
938 PYTHON_ABI="${EPYTHON#python}" 1455 PYTHON_ABI="${EPYTHON#python}"
939 PYTHON_ABI="${PYTHON_ABI%%-*}" 1456 PYTHON_ABI="${PYTHON_ABI%%-*}"
1457 fi
940 1458
941 _python_final_sanity_checks 1459 _python_final_sanity_checks
942 1460
943 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1461 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
944 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1462 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
946 1464
947# @FUNCTION: python_need_rebuild 1465# @FUNCTION: python_need_rebuild
948# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1466# @DESCRIPTION: Mark current package for rebuilding by python-updater after
949# switching of active version of Python. 1467# switching of active version of Python.
950python_need_rebuild() { 1468python_need_rebuild() {
1469 _python_check_python_pkg_setup_execution
1470
951 if _python_package_supporting_installation_for_multiple_python_abis; then 1471 if _python_package_supporting_installation_for_multiple_python_abis; then
952 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1472 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1473 fi
1474
1475 if [[ "$#" -ne 0 ]]; then
1476 die "${FUNCNAME}() does not accept arguments"
953 fi 1477 fi
954 1478
955 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1479 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
956} 1480}
957 1481
991# If --ABI option is specified, then only specified Python ABI is printed instead of 1515# If --ABI option is specified, then only specified Python ABI is printed instead of
992# filename of Python interpreter. 1516# filename of Python interpreter.
993# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1517# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
994# --ABI and --absolute-path options cannot be specified simultaneously. 1518# --ABI and --absolute-path options cannot be specified simultaneously.
995PYTHON() { 1519PYTHON() {
1520 _python_check_python_pkg_setup_execution
1521
996 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1522 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
997 1523
998 while (($#)); do 1524 while (($#)); do
999 case "$1" in 1525 case "$1" in
1000 -2) 1526 -2)
1025 esac 1551 esac
1026 shift 1552 shift
1027 done 1553 done
1028 1554
1029 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1555 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1030 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1556 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1031 fi 1557 fi
1032 1558
1033 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1559 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1034 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1560 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1035 fi 1561 fi
1037 if [[ "$#" -eq 0 ]]; then 1563 if [[ "$#" -eq 0 ]]; then
1038 if [[ "${final_ABI}" == "1" ]]; then 1564 if [[ "${final_ABI}" == "1" ]]; then
1039 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1565 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1040 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1566 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1041 fi 1567 fi
1042 validate_PYTHON_ABIS 1568 _python_calculate_PYTHON_ABIS
1043 PYTHON_ABI="${PYTHON_ABIS##* }" 1569 PYTHON_ABI="${PYTHON_ABIS##* }"
1044 elif [[ "${python2}" == "1" ]]; then 1570 elif [[ "${python2}" == "1" ]]; then
1045 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1571 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1046 if [[ -z "${PYTHON_ABI}" ]]; then 1572 if [[ -z "${PYTHON_ABI}" ]]; then
1047 die "${FUNCNAME}(): Active Python 2 interpreter not set" 1573 die "${FUNCNAME}(): Active version of Python 2 not set"
1048 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1574 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1049 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1575 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1050 fi 1576 fi
1051 elif [[ "${python3}" == "1" ]]; then 1577 elif [[ "${python3}" == "1" ]]; then
1052 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1578 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1053 if [[ -z "${PYTHON_ABI}" ]]; then 1579 if [[ -z "${PYTHON_ABI}" ]]; then
1054 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1580 die "${FUNCNAME}(): Active version of Python 3 not set"
1055 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1581 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1056 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1582 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1057 fi 1583 fi
1058 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1584 elif _python_package_supporting_installation_for_multiple_python_abis; then
1585 if ! _python_abi-specific_local_scope; then
1586 die "${FUNCNAME}() should be used in ABI-specific local scope"
1587 fi
1588 else
1059 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1589 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1060 elif [[ -z "${PYTHON_ABI}" ]]; then 1590 if [[ -z "${PYTHON_ABI}" ]]; then
1061 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" 1591 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1592 fi
1062 fi 1593 fi
1063 elif [[ "$#" -eq 1 ]]; then 1594 elif [[ "$#" -eq 1 ]]; then
1064 if [[ "${final_ABI}" == "1" ]]; then 1595 if [[ "${final_ABI}" == "1" ]]; then
1065 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1596 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1066 fi 1597 fi
1101# @USAGE: [-f|--final-ABI] 1632# @USAGE: [-f|--final-ABI]
1102# @DESCRIPTION: 1633# @DESCRIPTION:
1103# Print name of Python implementation. 1634# Print name of Python implementation.
1104# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1635# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1105python_get_implementation() { 1636python_get_implementation() {
1637 _python_check_python_pkg_setup_execution
1638
1106 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1639 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1107 1640
1108 while (($#)); do 1641 while (($#)); do
1109 case "$1" in 1642 case "$1" in
1110 -f|--final-ABI) 1643 -f|--final-ABI)
1123 if [[ "${final_ABI}" == "1" ]]; then 1656 if [[ "${final_ABI}" == "1" ]]; then
1124 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1657 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1125 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1658 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1126 fi 1659 fi
1127 PYTHON_ABI="$(PYTHON -f --ABI)" 1660 PYTHON_ABI="$(PYTHON -f --ABI)"
1128 elif [[ -z "${PYTHON_ABI}" ]]; then 1661 else
1662 if _python_package_supporting_installation_for_multiple_python_abis; then
1663 if ! _python_abi-specific_local_scope; then
1664 die "${FUNCNAME}() should be used in ABI-specific local scope"
1665 fi
1666 else
1129 PYTHON_ABI="$(PYTHON --ABI)" 1667 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1668 fi
1130 fi 1669 fi
1131 1670
1132 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1671 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1133} 1672}
1134 1673
1136# @USAGE: [-f|--final-ABI] 1675# @USAGE: [-f|--final-ABI]
1137# @DESCRIPTION: 1676# @DESCRIPTION:
1138# Print category, name and slot of package providing Python implementation. 1677# Print category, name and slot of package providing Python implementation.
1139# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1678# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1140python_get_implementational_package() { 1679python_get_implementational_package() {
1680 _python_check_python_pkg_setup_execution
1681
1141 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1682 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1142 1683
1143 while (($#)); do 1684 while (($#)); do
1144 case "$1" in 1685 case "$1" in
1145 -f|--final-ABI) 1686 -f|--final-ABI)
1158 if [[ "${final_ABI}" == "1" ]]; then 1699 if [[ "${final_ABI}" == "1" ]]; then
1159 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1700 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1160 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1701 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1161 fi 1702 fi
1162 PYTHON_ABI="$(PYTHON -f --ABI)" 1703 PYTHON_ABI="$(PYTHON -f --ABI)"
1163 elif [[ -z "${PYTHON_ABI}" ]]; then 1704 else
1705 if _python_package_supporting_installation_for_multiple_python_abis; then
1706 if ! _python_abi-specific_local_scope; then
1707 die "${FUNCNAME}() should be used in ABI-specific local scope"
1708 fi
1709 else
1164 PYTHON_ABI="$(PYTHON --ABI)" 1710 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1165 fi 1711 fi
1712 fi
1166 1713
1714 if [[ "${EAPI:-0}" == "0" ]]; then
1167 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1715 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1168 echo "dev-lang/python:${PYTHON_ABI}" 1716 echo "=dev-lang/python-${PYTHON_ABI}*"
1169 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1717 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1718 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1719 fi
1720 else
1721 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1722 echo "dev-lang/python:${PYTHON_ABI}"
1723 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1170 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1724 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1725 fi
1171 fi 1726 fi
1172} 1727}
1173 1728
1174# @FUNCTION: python_get_includedir 1729# @FUNCTION: python_get_includedir
1175# @USAGE: [-f|--final-ABI] 1730# @USAGE: [-b|--base-path] [-f|--final-ABI]
1176# @DESCRIPTION: 1731# @DESCRIPTION:
1177# Print path to Python include directory. 1732# Print path to Python include directory.
1733# If --base-path option is specified, then path not prefixed with "/" is printed.
1178# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1734# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1179python_get_includedir() { 1735python_get_includedir() {
1736 _python_check_python_pkg_setup_execution
1737
1180 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1738 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1181 1739
1182 while (($#)); do 1740 while (($#)); do
1183 case "$1" in 1741 case "$1" in
1742 -b|--base-path)
1743 base_path="1"
1744 ;;
1184 -f|--final-ABI) 1745 -f|--final-ABI)
1185 final_ABI="1" 1746 final_ABI="1"
1186 ;; 1747 ;;
1187 -*) 1748 -*)
1188 die "${FUNCNAME}(): Unrecognized option '$1'" 1749 die "${FUNCNAME}(): Unrecognized option '$1'"
1191 die "${FUNCNAME}(): Invalid usage" 1752 die "${FUNCNAME}(): Invalid usage"
1192 ;; 1753 ;;
1193 esac 1754 esac
1194 shift 1755 shift
1195 done 1756 done
1757
1758 if [[ "${base_path}" == "0" ]]; then
1759 prefix="/"
1760 fi
1196 1761
1197 if [[ "${final_ABI}" == "1" ]]; then 1762 if [[ "${final_ABI}" == "1" ]]; then
1198 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1763 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1199 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1764 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1200 fi 1765 fi
1201 PYTHON_ABI="$(PYTHON -f --ABI)" 1766 PYTHON_ABI="$(PYTHON -f --ABI)"
1202 elif [[ -z "${PYTHON_ABI}" ]]; then 1767 else
1768 if _python_package_supporting_installation_for_multiple_python_abis; then
1769 if ! _python_abi-specific_local_scope; then
1770 die "${FUNCNAME}() should be used in ABI-specific local scope"
1771 fi
1772 else
1203 PYTHON_ABI="$(PYTHON --ABI)" 1773 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1774 fi
1204 fi 1775 fi
1205 1776
1206 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1777 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1207 echo "/usr/include/python${PYTHON_ABI}" 1778 echo "${prefix}usr/include/python${PYTHON_ABI}"
1208 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1779 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1209 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1780 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1210 fi 1781 fi
1211} 1782}
1212 1783
1213# @FUNCTION: python_get_libdir 1784# @FUNCTION: python_get_libdir
1214# @USAGE: [-f|--final-ABI] 1785# @USAGE: [-b|--base-path] [-f|--final-ABI]
1215# @DESCRIPTION: 1786# @DESCRIPTION:
1216# Print path to Python library directory. 1787# Print path to Python library directory.
1788# If --base-path option is specified, then path not prefixed with "/" is printed.
1217# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1789# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1218python_get_libdir() { 1790python_get_libdir() {
1791 _python_check_python_pkg_setup_execution
1792
1219 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1793 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1220 1794
1221 while (($#)); do 1795 while (($#)); do
1222 case "$1" in 1796 case "$1" in
1797 -b|--base-path)
1798 base_path="1"
1799 ;;
1223 -f|--final-ABI) 1800 -f|--final-ABI)
1224 final_ABI="1" 1801 final_ABI="1"
1225 ;; 1802 ;;
1226 -*) 1803 -*)
1227 die "${FUNCNAME}(): Unrecognized option '$1'" 1804 die "${FUNCNAME}(): Unrecognized option '$1'"
1230 die "${FUNCNAME}(): Invalid usage" 1807 die "${FUNCNAME}(): Invalid usage"
1231 ;; 1808 ;;
1232 esac 1809 esac
1233 shift 1810 shift
1234 done 1811 done
1812
1813 if [[ "${base_path}" == "0" ]]; then
1814 prefix="/"
1815 fi
1235 1816
1236 if [[ "${final_ABI}" == "1" ]]; then 1817 if [[ "${final_ABI}" == "1" ]]; then
1237 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1818 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1238 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1819 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1239 fi 1820 fi
1240 PYTHON_ABI="$(PYTHON -f --ABI)" 1821 PYTHON_ABI="$(PYTHON -f --ABI)"
1241 elif [[ -z "${PYTHON_ABI}" ]]; then 1822 else
1823 if _python_package_supporting_installation_for_multiple_python_abis; then
1824 if ! _python_abi-specific_local_scope; then
1825 die "${FUNCNAME}() should be used in ABI-specific local scope"
1826 fi
1827 else
1242 PYTHON_ABI="$(PYTHON --ABI)" 1828 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1829 fi
1243 fi 1830 fi
1244 1831
1245 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1832 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1246 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1833 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1247 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1834 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1248 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1835 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1249 fi 1836 fi
1250} 1837}
1251 1838
1252# @FUNCTION: python_get_sitedir 1839# @FUNCTION: python_get_sitedir
1253# @USAGE: [-f|--final-ABI] 1840# @USAGE: [-b|--base-path] [-f|--final-ABI]
1254# @DESCRIPTION: 1841# @DESCRIPTION:
1255# Print path to Python site-packages directory. 1842# Print path to Python site-packages directory.
1843# If --base-path option is specified, then path not prefixed with "/" is printed.
1256# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1844# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1257python_get_sitedir() { 1845python_get_sitedir() {
1258 local options=() 1846 _python_check_python_pkg_setup_execution
1847
1848 local final_ABI="0" options=()
1259 1849
1260 while (($#)); do 1850 while (($#)); do
1261 case "$1" in 1851 case "$1" in
1852 -b|--base-path)
1853 options+=("$1")
1854 ;;
1262 -f|--final-ABI) 1855 -f|--final-ABI)
1263 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1856 final_ABI="1"
1264 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1265 fi
1266 options+=("$1") 1857 options+=("$1")
1267 ;; 1858 ;;
1268 -*) 1859 -*)
1269 die "${FUNCNAME}(): Unrecognized option '$1'" 1860 die "${FUNCNAME}(): Unrecognized option '$1'"
1270 ;; 1861 ;;
1273 ;; 1864 ;;
1274 esac 1865 esac
1275 shift 1866 shift
1276 done 1867 done
1277 1868
1869 if [[ "${final_ABI}" == "1" ]]; then
1870 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1871 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1872 fi
1873 else
1874 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1875 die "${FUNCNAME}() should be used in ABI-specific local scope"
1876 fi
1877 fi
1878
1278 echo "$(python_get_libdir "${options[@]}")/site-packages" 1879 echo "$(python_get_libdir "${options[@]}")/site-packages"
1279} 1880}
1280 1881
1281# @FUNCTION: python_get_library 1882# @FUNCTION: python_get_library
1282# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1883# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1283# @DESCRIPTION: 1884# @DESCRIPTION:
1284# Print path to Python library. 1885# Print path to Python library.
1886# If --base-path option is specified, then path not prefixed with "/" is printed.
1285# If --linker-option is specified, then "-l${library}" linker option is printed. 1887# If --linker-option is specified, then "-l${library}" linker option is printed.
1286# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1888# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1287python_get_library() { 1889python_get_library() {
1890 _python_check_python_pkg_setup_execution
1891
1288 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1892 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1289 1893
1290 while (($#)); do 1894 while (($#)); do
1291 case "$1" in 1895 case "$1" in
1896 -b|--base-path)
1897 base_path="1"
1898 ;;
1292 -f|--final-ABI) 1899 -f|--final-ABI)
1293 final_ABI="1" 1900 final_ABI="1"
1294 ;; 1901 ;;
1295 -l|--linker-option) 1902 -l|--linker-option)
1296 linker_option="1" 1903 linker_option="1"
1302 die "${FUNCNAME}(): Invalid usage" 1909 die "${FUNCNAME}(): Invalid usage"
1303 ;; 1910 ;;
1304 esac 1911 esac
1305 shift 1912 shift
1306 done 1913 done
1914
1915 if [[ "${base_path}" == "0" ]]; then
1916 prefix="/"
1917 fi
1918
1919 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1920 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1921 fi
1307 1922
1308 if [[ "${final_ABI}" == "1" ]]; then 1923 if [[ "${final_ABI}" == "1" ]]; then
1309 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1924 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1310 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1925 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1311 fi 1926 fi
1312 PYTHON_ABI="$(PYTHON -f --ABI)" 1927 PYTHON_ABI="$(PYTHON -f --ABI)"
1313 elif [[ -z "${PYTHON_ABI}" ]]; then 1928 else
1929 if _python_package_supporting_installation_for_multiple_python_abis; then
1930 if ! _python_abi-specific_local_scope; then
1931 die "${FUNCNAME}() should be used in ABI-specific local scope"
1932 fi
1933 else
1314 PYTHON_ABI="$(PYTHON --ABI)" 1934 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1935 fi
1315 fi 1936 fi
1316 1937
1317 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1938 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1318 if [[ "${linker_option}" == "1" ]]; then 1939 if [[ "${linker_option}" == "1" ]]; then
1319 echo "-lpython${PYTHON_ABI}" 1940 echo "-lpython${PYTHON_ABI}"
1320 else 1941 else
1321 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1942 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1322 fi 1943 fi
1323 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1944 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1324 die "${FUNCNAME}(): Jython does not have shared library" 1945 die "${FUNCNAME}(): Jython does not have shared library"
1325 fi 1946 fi
1326} 1947}
1331# Print Python version. 1952# Print Python version.
1332# --full, --major, --minor and --micro options cannot be specified simultaneously. 1953# --full, --major, --minor and --micro options cannot be specified simultaneously.
1333# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1954# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1334# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1955# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1335python_get_version() { 1956python_get_version() {
1957 _python_check_python_pkg_setup_execution
1958
1336 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1959 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1337 1960
1338 while (($#)); do 1961 while (($#)); do
1339 case "$1" in 1962 case "$1" in
1340 -f|--final-ABI) 1963 -f|--final-ABI)
1390 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2013 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1391 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 2014 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1392 fi 2015 fi
1393 "$(PYTHON -f)" -c "${python_command}" 2016 "$(PYTHON -f)" -c "${python_command}"
1394 else 2017 else
2018 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
2019 die "${FUNCNAME}() should be used in ABI-specific local scope"
2020 fi
1395 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2021 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1396 fi 2022 fi
1397}
1398
1399# ================================================================================================
1400# =================================== MISCELLANEOUS FUNCTIONS ====================================
1401# ================================================================================================
1402
1403_python_implementation() {
1404 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
1405 return 0
1406 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1407 return 0
1408 else
1409 return 1
1410 fi
1411}
1412
1413_python_package_supporting_installation_for_multiple_python_abis() {
1414 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1415 die "${FUNCNAME}() cannot be used in global scope"
1416 fi
1417
1418 if has "${EAPI:-0}" 0 1 2 3 4; then
1419 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1420 return 0
1421 else
1422 return 1
1423 fi
1424 else
1425 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1426 fi
1427}
1428
1429_python_initialize_prefix_variables() {
1430 if has "${EAPI:-0}" 0 1 2; then
1431 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
1432 EROOT="${ROOT%/}${EPREFIX}/"
1433 fi
1434 if [[ -n "${D}" && -z "${ED}" ]]; then
1435 ED="${D%/}${EPREFIX}/"
1436 fi
1437 fi
1438}
1439
1440unset PYTHON_SANITY_CHECKS
1441
1442_python_initial_sanity_checks() {
1443 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1444 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
1445 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
1446 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
1447 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1448 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
1449 fi
1450 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
1451 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
1452 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1453 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
1454 fi
1455 fi
1456}
1457
1458_python_final_sanity_checks() {
1459 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1460 local PYTHON_ABI="${PYTHON_ABI}"
1461 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
1462 # Ensure that appropriate version of Python is installed.
1463 if ! has_version "$(python_get_implementational_package)"; then
1464 die "$(python_get_implementational_package) is not installed"
1465 fi
1466
1467 # Ensure that EPYTHON variable is respected.
1468 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
1469 eerror "python: '$(type -p python)'"
1470 eerror "ABI: '${ABI}'"
1471 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
1472 eerror "EPYTHON: '$(PYTHON)'"
1473 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
1474 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
1475 die "'python' does not respect EPYTHON variable"
1476 fi
1477 done
1478 fi
1479 PYTHON_SANITY_CHECKS="1"
1480}
1481
1482_python_set_color_variables() {
1483 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1484 _BOLD=$'\e[1m'
1485 _RED=$'\e[1;31m'
1486 _GREEN=$'\e[1;32m'
1487 _BLUE=$'\e[1;34m'
1488 _CYAN=$'\e[1;36m'
1489 _NORMAL=$'\e[0m'
1490 else
1491 _BOLD=
1492 _RED=
1493 _GREEN=
1494 _BLUE=
1495 _CYAN=
1496 _NORMAL=
1497 fi
1498}
1499
1500# @FUNCTION: python_convert_shebangs
1501# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
1502# @DESCRIPTION:
1503# Convert shebangs in specified files. Directories can be specified only with --recursive option.
1504python_convert_shebangs() {
1505 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
1506
1507 while (($#)); do
1508 case "$1" in
1509 -r|--recursive)
1510 recursive="1"
1511 ;;
1512 -q|--quiet)
1513 quiet="1"
1514 ;;
1515 -x|--only-executables)
1516 only_executables="1"
1517 ;;
1518 --)
1519 shift
1520 break
1521 ;;
1522 -*)
1523 die "${FUNCNAME}(): Unrecognized option '$1'"
1524 ;;
1525 *)
1526 break
1527 ;;
1528 esac
1529 shift
1530 done
1531
1532 if [[ "$#" -eq 0 ]]; then
1533 die "${FUNCNAME}(): Missing Python version and files or directories"
1534 elif [[ "$#" -eq 1 ]]; then
1535 die "${FUNCNAME}(): Missing files or directories"
1536 fi
1537
1538 python_version="$1"
1539 shift
1540
1541 for argument in "$@"; do
1542 if [[ ! -e "${argument}" ]]; then
1543 die "${FUNCNAME}(): '${argument}' does not exist"
1544 elif [[ -f "${argument}" ]]; then
1545 files+=("${argument}")
1546 elif [[ -d "${argument}" ]]; then
1547 if [[ "${recursive}" == "1" ]]; then
1548 while read -d $'\0' -r file; do
1549 files+=("${file}")
1550 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1551 else
1552 die "${FUNCNAME}(): '${argument}' is not a regular file"
1553 fi
1554 else
1555 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1556 fi
1557 done
1558
1559 for file in "${files[@]}"; do
1560 file="${file#./}"
1561 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1562
1563 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1564 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1565
1566 if [[ "${quiet}" == "0" ]]; then
1567 einfo "Converting shebang in '${file}'"
1568 fi
1569
1570 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1571
1572 # Delete potential whitespace after "#!".
1573 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1574 fi
1575 done
1576}
1577
1578# @FUNCTION: python_clean_sitedirs
1579# @DESCRIPTION:
1580# Delete needless files in site-packages directories in ${ED}.
1581python_clean_sitedirs() {
1582 _python_initialize_prefix_variables
1583
1584 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1585} 2023}
1586 2024
1587# ================================================================================================ 2025# ================================================================================================
1588# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 2026# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1589# ================================================================================================ 2027# ================================================================================================
1609# @DESCRIPTION: 2047# @DESCRIPTION:
1610# Execute nosetests for all enabled Python ABIs. 2048# Execute nosetests for all enabled Python ABIs.
1611# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 2049# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1612# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2050# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1613python_execute_nosetests() { 2051python_execute_nosetests() {
2052 _python_check_python_pkg_setup_execution
1614 _python_set_color_variables 2053 _python_set_color_variables
1615 2054
1616 local PYTHONPATH_template= separate_build_dirs= 2055 local PYTHONPATH_template= separate_build_dirs=
1617 2056
1618 while (($#)); do 2057 while (($#)); do
1637 esac 2076 esac
1638 shift 2077 shift
1639 done 2078 done
1640 2079
1641 python_test_function() { 2080 python_test_function() {
1642 local evaluated_PYTHONPATH= 2081 local evaluated_PYTHONPATH
1643 2082
1644 if [[ -n "${PYTHONPATH_template}" ]]; then
1645 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2083 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1646 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1647 unset evaluated_PYTHONPATH
1648 fi
1649 fi
1650 2084
1651 _python_test_hook pre 2085 _python_test_hook pre
1652 2086
1653 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2087 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1654 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2088 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1677# @DESCRIPTION: 2111# @DESCRIPTION:
1678# Execute py.test for all enabled Python ABIs. 2112# Execute py.test for all enabled Python ABIs.
1679# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 2113# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1680# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2114# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1681python_execute_py.test() { 2115python_execute_py.test() {
2116 _python_check_python_pkg_setup_execution
1682 _python_set_color_variables 2117 _python_set_color_variables
1683 2118
1684 local PYTHONPATH_template= separate_build_dirs= 2119 local PYTHONPATH_template= separate_build_dirs=
1685 2120
1686 while (($#)); do 2121 while (($#)); do
1705 esac 2140 esac
1706 shift 2141 shift
1707 done 2142 done
1708 2143
1709 python_test_function() { 2144 python_test_function() {
1710 local evaluated_PYTHONPATH= 2145 local evaluated_PYTHONPATH
1711 2146
1712 if [[ -n "${PYTHONPATH_template}" ]]; then
1713 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2147 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1714 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1715 unset evaluated_PYTHONPATH
1716 fi
1717 fi
1718 2148
1719 _python_test_hook pre 2149 _python_test_hook pre
1720 2150
1721 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2151 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1722 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 2152 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1745# @DESCRIPTION: 2175# @DESCRIPTION:
1746# Execute trial for all enabled Python ABIs. 2176# Execute trial for all enabled Python ABIs.
1747# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2177# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1748# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2178# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1749python_execute_trial() { 2179python_execute_trial() {
2180 _python_check_python_pkg_setup_execution
1750 _python_set_color_variables 2181 _python_set_color_variables
1751 2182
1752 local PYTHONPATH_template= separate_build_dirs= 2183 local PYTHONPATH_template= separate_build_dirs=
1753 2184
1754 while (($#)); do 2185 while (($#)); do
1773 esac 2204 esac
1774 shift 2205 shift
1775 done 2206 done
1776 2207
1777 python_test_function() { 2208 python_test_function() {
1778 local evaluated_PYTHONPATH= 2209 local evaluated_PYTHONPATH
1779 2210
1780 if [[ -n "${PYTHONPATH_template}" ]]; then
1781 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2211 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1782 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1783 unset evaluated_PYTHONPATH
1784 fi
1785 fi
1786 2212
1787 _python_test_hook pre 2213 _python_test_hook pre
1788 2214
1789 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2215 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1790 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2216 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1815# @FUNCTION: python_enable_pyc 2241# @FUNCTION: python_enable_pyc
1816# @DESCRIPTION: 2242# @DESCRIPTION:
1817# Tell Python to automatically recompile modules to .pyc/.pyo if the 2243# Tell Python to automatically recompile modules to .pyc/.pyo if the
1818# timestamps/version stamps have changed. 2244# timestamps/version stamps have changed.
1819python_enable_pyc() { 2245python_enable_pyc() {
2246 _python_check_python_pkg_setup_execution
2247
2248 if [[ "$#" -ne 0 ]]; then
2249 die "${FUNCNAME}() does not accept arguments"
2250 fi
2251
1820 unset PYTHONDONTWRITEBYTECODE 2252 unset PYTHONDONTWRITEBYTECODE
1821} 2253}
1822 2254
1823# @FUNCTION: python_disable_pyc 2255# @FUNCTION: python_disable_pyc
1824# @DESCRIPTION: 2256# @DESCRIPTION:
1825# Tell Python not to automatically recompile modules to .pyc/.pyo 2257# Tell Python not to automatically recompile modules to .pyc/.pyo
1826# even if the timestamps/version stamps do not match. This is done 2258# even if the timestamps/version stamps do not match. This is done
1827# to protect sandbox. 2259# to protect sandbox.
1828python_disable_pyc() { 2260python_disable_pyc() {
2261 _python_check_python_pkg_setup_execution
2262
2263 if [[ "$#" -ne 0 ]]; then
2264 die "${FUNCNAME}() does not accept arguments"
2265 fi
2266
1829 export PYTHONDONTWRITEBYTECODE="1" 2267 export PYTHONDONTWRITEBYTECODE="1"
1830} 2268}
1831 2269
2270_python_clean_compiled_modules() {
2271 _python_initialize_prefix_variables
2272 _python_set_color_variables
2273
2274 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2275
2276 local base_module_name compiled_file compiled_files=() dir path py_file root
2277
2278 # Strip trailing slash from EROOT.
2279 root="${EROOT%/}"
2280
2281 for path in "$@"; do
2282 compiled_files=()
2283 if [[ -d "${path}" ]]; then
2284 while read -d $'\0' -r compiled_file; do
2285 compiled_files+=("${compiled_file}")
2286 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
2287
2288 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2289 # Delete empty child directories.
2290 find "${path}" -type d | sort -r | while read -r dir; do
2291 if rmdir "${dir}" 2> /dev/null; then
2292 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2293 fi
2294 done
2295 fi
2296 elif [[ "${path}" == *.py ]]; then
2297 base_module_name="${path##*/}"
2298 base_module_name="${base_module_name%.py}"
2299 if [[ -d "${path%/*}/__pycache__" ]]; then
2300 while read -d $'\0' -r compiled_file; do
2301 compiled_files+=("${compiled_file}")
2302 done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
2303 fi
2304 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
2305 fi
2306
2307 for compiled_file in "${compiled_files[@]}"; do
2308 [[ ! -f "${compiled_file}" ]] && continue
2309 dir="${compiled_file%/*}"
2310 dir="${dir##*/}"
2311 if [[ "${compiled_file}" == *.py[co] ]]; then
2312 if [[ "${dir}" == "__pycache__" ]]; then
2313 base_module_name="${compiled_file##*/}"
2314 base_module_name="${base_module_name%.*py[co]}"
2315 base_module_name="${base_module_name%.*}"
2316 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2317 else
2318 py_file="${compiled_file%[co]}"
2319 fi
2320 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2321 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2322 else
2323 [[ -f "${py_file}" ]] && continue
2324 fi
2325 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
2326 rm -f "${compiled_file%[co]}"[co]
2327 elif [[ "${compiled_file}" == *\$py.class ]]; then
2328 if [[ "${dir}" == "__pycache__" ]]; then
2329 base_module_name="${compiled_file##*/}"
2330 base_module_name="${base_module_name%\$py.class}"
2331 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2332 else
2333 py_file="${compiled_file%\$py.class}"
2334 fi
2335 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2336 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2337 else
2338 [[ -f "${py_file}" ]] && continue
2339 fi
2340 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
2341 rm -f "${compiled_file}"
2342 else
2343 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2344 fi
2345
2346 # Delete empty parent directories.
2347 dir="${compiled_file%/*}"
2348 while [[ "${dir}" != "${root}" ]]; do
2349 if rmdir "${dir}" 2> /dev/null; then
2350 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2351 else
2352 break
2353 fi
2354 dir="${dir%/*}"
2355 done
2356 done
2357 done
2358}
2359
1832# @FUNCTION: python_mod_optimize 2360# @FUNCTION: python_mod_optimize
1833# @USAGE: [options] [directory|file] 2361# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
1834# @DESCRIPTION: 2362# @DESCRIPTION:
1835# If no arguments supplied, it will recompile not recursively all modules 2363# Byte-compile specified Python modules.
1836# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1837#
1838# If supplied with arguments, it will recompile all modules recursively
1839# in the supplied directory.
1840#
1841# Options passed to this function are passed to compileall.py. 2364# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
1842# 2365#
1843# This function can be used only in pkg_postinst() phase. 2366# This function can be used only in pkg_postinst() phase.
1844python_mod_optimize() { 2367python_mod_optimize() {
2368 _python_check_python_pkg_setup_execution
1845 _python_initialize_prefix_variables 2369 _python_initialize_prefix_variables
1846 2370
1847 # Check if phase is pkg_postinst(). 2371 # Check if phase is pkg_postinst().
1848 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2372 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1849 2373
2374 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2375 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2376 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
2377
1850 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2378 if _python_package_supporting_installation_for_multiple_python_abis; then
1851 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=() 2379 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2380 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2381 fi
2382 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2383 else
2384 if has "${EAPI:-0}" 0 1 2 3; then
2385 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2386 else
2387 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2388 fi
2389 fi
1852 2390
1853 # Strip trailing slash from ROOT. 2391 # Strip trailing slash from EROOT.
1854 root="${EROOT%/}" 2392 root="${EROOT%/}"
1855 2393
1856 # Respect ROOT and options passed to compileall.py.
1857 while (($#)); do 2394 while (($#)); do
1858 case "$1" in 2395 case "$1" in
2396 --allow-evaluated-non-sitedir-paths)
2397 allow_evaluated_non_sitedir_paths="1"
2398 ;;
1859 -l|-f|-q) 2399 -l|-f|-q)
1860 options+=("$1") 2400 options+=("$1")
1861 ;; 2401 ;;
1862 -d|-x) 2402 -d|-x)
1863 options+=("$1" "$2") 2403 options+=("$1" "$2")
1864 shift 2404 shift
1865 ;; 2405 ;;
2406 --)
2407 shift
2408 break
2409 ;;
1866 -*) 2410 -*)
1867 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2411 die "${FUNCNAME}(): Unrecognized option '$1'"
1868 ;; 2412 ;;
1869 *) 2413 *)
1870 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1871 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1872 elif [[ "$1" =~ ^/ ]]; then
1873 if [[ -d "${root}/$1" ]]; then
1874 other_dirs+=("${root}/$1")
1875 elif [[ -f "${root}/$1" ]]; then
1876 other_files+=("${root}/$1")
1877 elif [[ -e "${root}/$1" ]]; then
1878 ewarn "'${root}/$1' is not a file or a directory!"
1879 else
1880 ewarn "'${root}/$1' does not exist!"
1881 fi
1882 else
1883 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1884 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1885 site_packages_dirs+=("$1")
1886 break 2414 break
1887 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1888 site_packages_files+=("$1")
1889 break
1890 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
1891 ewarn "'$1' is not a file or a directory!"
1892 else
1893 ewarn "'$1' does not exist!"
1894 fi
1895 done
1896 fi
1897 ;; 2415 ;;
1898 esac 2416 esac
1899 shift 2417 shift
1900 done 2418 done
1901 2419
2420 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2421 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2422 fi
2423
2424 if [[ "$#" -eq 0 ]]; then
2425 die "${FUNCNAME}(): Missing files or directories"
2426 fi
2427
2428 while (($#)); do
2429 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2430 die "${FUNCNAME}(): Invalid argument '$1'"
2431 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2432 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2433 elif [[ "$1" =~ ^/ ]]; then
2434 if _python_package_supporting_installation_for_multiple_python_abis; then
2435 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2436 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2437 fi
2438 if [[ "$1" != *\$* ]]; then
2439 die "${FUNCNAME}(): '$1' has invalid syntax"
2440 fi
2441 if [[ "$1" == *.py ]]; then
2442 evaluated_files+=("$1")
2443 else
2444 evaluated_dirs+=("$1")
2445 fi
2446 else
2447 if [[ -d "${root}$1" ]]; then
2448 other_dirs+=("${root}$1")
2449 elif [[ -f "${root}$1" ]]; then
2450 other_files+=("${root}$1")
2451 elif [[ -e "${root}$1" ]]; then
2452 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2453 else
2454 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2455 fi
2456 fi
2457 else
2458 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2459 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2460 site_packages_dirs+=("$1")
2461 break
2462 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2463 site_packages_files+=("$1")
2464 break
2465 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2466 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2467 else
2468 eerror "${FUNCNAME}(): '$1' does not exist"
2469 fi
2470 done
2471 fi
2472 shift
2473 done
2474
1902 # Set additional options. 2475 # Set additional options.
1903 options+=("-q") 2476 options+=("-q")
1904 2477
1905 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2478 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1906 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2479 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
1907 return_code="0" 2480 return_code="0"
1908 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2481 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1909 if ((${#site_packages_dirs[@]})); then 2482 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
1910 for dir in "${site_packages_dirs[@]}"; do 2483 for dir in "${site_packages_dirs[@]}"; do
1911 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2484 dirs+=("${root}$(python_get_sitedir)/${dir}")
1912 done 2485 done
2486 for dir in "${evaluated_dirs[@]}"; do
2487 eval "dirs+=(\"\${root}${dir}\")"
2488 done
1913 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2489 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
1914 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2490 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1915 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2491 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
1916 fi 2492 fi
2493 _python_clean_compiled_modules "${dirs[@]}"
1917 fi 2494 fi
1918 if ((${#site_packages_files[@]})); then 2495 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
1919 for file in "${site_packages_files[@]}"; do 2496 for file in "${site_packages_files[@]}"; do
1920 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2497 files+=("${root}$(python_get_sitedir)/${file}")
1921 done 2498 done
2499 for file in "${evaluated_files[@]}"; do
2500 eval "files+=(\"\${root}${file}\")"
2501 done
1922 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2502 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
1923 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2503 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1924 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2504 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
1925 fi 2505 fi
2506 _python_clean_compiled_modules "${files[@]}"
1926 fi 2507 fi
1927 eend "${return_code}" 2508 eend "${return_code}"
1928 fi 2509 fi
1929 unset site_packages_absolute_dirs site_packages_absolute_files 2510 unset dirs files
1930 done 2511 done
1931 2512
2513 if _python_package_supporting_installation_for_multiple_python_abis; then
1932 # Restore previous value of PYTHON_ABI. 2514 # Restore previous value of PYTHON_ABI.
1933 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2515 if [[ -n "${previous_PYTHON_ABI}" ]]; then
1934 PYTHON_ABI="${previous_PYTHON_ABI}" 2516 PYTHON_ABI="${previous_PYTHON_ABI}"
1935 else 2517 else
1936 unset PYTHON_ABI 2518 unset PYTHON_ABI
2519 fi
1937 fi 2520 fi
1938 2521
1939 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2522 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1940 return_code="0" 2523 return_code="0"
1941 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2524 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
1942 if ((${#other_dirs[@]})); then 2525 if ((${#other_dirs[@]})); then
1943 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2526 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1944 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2527 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1945 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2528 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1946 fi 2529 fi
2530 _python_clean_compiled_modules "${other_dirs[@]}"
1947 fi 2531 fi
1948 if ((${#other_files[@]})); then 2532 if ((${#other_files[@]})); then
1949 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2533 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1950 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2534 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1951 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2535 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1952 fi 2536 fi
2537 _python_clean_compiled_modules "${other_files[@]}"
1953 fi 2538 fi
1954 eend "${return_code}" 2539 eend "${return_code}"
1955 fi 2540 fi
1956 else 2541 else
2542 # Deprecated part of python_mod_optimize()
2543 # ewarn
2544 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2545 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2546 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2547 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2548 # ewarn
2549
1957 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2550 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1958 2551
1959 # strip trailing slash 2552 # strip trailing slash
1960 myroot="${EROOT%/}" 2553 myroot="${EROOT%/}"
1961 2554
1962 # respect ROOT and options passed to compileall.py 2555 # respect EROOT and options passed to compileall.py
1963 while (($#)); do 2556 while (($#)); do
1964 case "$1" in 2557 case "$1" in
1965 -l|-f|-q) 2558 -l|-f|-q)
1966 myopts+=("$1") 2559 myopts+=("$1")
1967 ;; 2560 ;;
1968 -d|-x) 2561 -d|-x)
1969 myopts+=("$1" "$2") 2562 myopts+=("$1" "$2")
1970 shift 2563 shift
1971 ;; 2564 ;;
2565 --)
2566 shift
2567 break
2568 ;;
1972 -*) 2569 -*)
1973 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2570 die "${FUNCNAME}(): Unrecognized option '$1'"
1974 ;; 2571 ;;
1975 *) 2572 *)
1976 if [[ -d "${myroot}"/$1 ]]; then 2573 break
1977 mydirs+=("${myroot}/$1")
1978 elif [[ -f "${myroot}"/$1 ]]; then
1979 # Files are passed to python_mod_compile which is ROOT-aware
1980 myfiles+=("$1")
1981 elif [[ -e "${myroot}/$1" ]]; then
1982 ewarn "${myroot}/$1 is not a file or directory!"
1983 else
1984 ewarn "${myroot}/$1 does not exist!"
1985 fi
1986 ;; 2574 ;;
1987 esac 2575 esac
1988 shift 2576 shift
1989 done 2577 done
1990 2578
2579 if [[ "$#" -eq 0 ]]; then
2580 die "${FUNCNAME}(): Missing files or directories"
2581 fi
2582
2583 while (($#)); do
2584 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2585 die "${FUNCNAME}(): Invalid argument '$1'"
2586 elif [[ -d "${myroot}/${1#/}" ]]; then
2587 mydirs+=("${myroot}/${1#/}")
2588 elif [[ -f "${myroot}/${1#/}" ]]; then
2589 myfiles+=("${myroot}/${1#/}")
2590 elif [[ -e "${myroot}/${1#/}" ]]; then
2591 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2592 else
2593 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2594 fi
2595 shift
2596 done
2597
1991 # set additional opts 2598 # set additional opts
1992 myopts+=(-q) 2599 myopts+=(-q)
2600
2601 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1993 2602
1994 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2603 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1995 if ((${#mydirs[@]})); then 2604 if ((${#mydirs[@]})); then
1996 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2605 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1997 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2606 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2607 _python_clean_compiled_modules "${mydirs[@]}"
1998 fi 2608 fi
1999 2609
2000 if ((${#myfiles[@]})); then 2610 if ((${#myfiles[@]})); then
2611 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2612 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2001 python_mod_compile "${myfiles[@]}" 2613 _python_clean_compiled_modules "${myfiles[@]}"
2002 fi 2614 fi
2003 2615
2004 eend "${return_code}" 2616 eend "${return_code}"
2005 fi 2617 fi
2006} 2618}
2007 2619
2008# @FUNCTION: python_mod_cleanup 2620# @FUNCTION: python_mod_cleanup
2009# @USAGE: [directory|file] 2621# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2010# @DESCRIPTION: 2622# @DESCRIPTION:
2011# Run with optional arguments, where arguments are Python modules. If none given, 2623# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2012# it will look in /usr/lib/python[0-9].[0-9].
2013#
2014# It will recursively scan all compiled Python modules in the directories and
2015# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2016# If they are, then it will remove their corresponding .pyc and .pyo files.
2017# 2624#
2018# This function can be used only in pkg_postrm() phase. 2625# This function can be used only in pkg_postrm() phase.
2019python_mod_cleanup() { 2626python_mod_cleanup() {
2627 _python_check_python_pkg_setup_execution
2020 _python_initialize_prefix_variables 2628 _python_initialize_prefix_variables
2021 _python_set_color_variables
2022 2629
2023 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2630 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2024 2631
2025 # Check if phase is pkg_postrm(). 2632 # Check if phase is pkg_postrm().
2026 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2633 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2027 2634
2635 if _python_package_supporting_installation_for_multiple_python_abis; then
2636 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2637 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2638 fi
2639 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2640 else
2641 if has "${EAPI:-0}" 0 1 2 3; then
2642 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2643 else
2644 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2645 fi
2646 fi
2647
2028 # Strip trailing slash from ROOT. 2648 # Strip trailing slash from EROOT.
2029 root="${EROOT%/}" 2649 root="${EROOT%/}"
2030 2650
2031 if (($#)); then 2651 while (($#)); do
2032 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2652 case "$1" in
2653 --allow-evaluated-non-sitedir-paths)
2654 allow_evaluated_non_sitedir_paths="1"
2655 ;;
2656 --)
2657 shift
2658 break
2659 ;;
2660 -*)
2661 die "${FUNCNAME}(): Unrecognized option '$1'"
2662 ;;
2663 *)
2664 break
2665 ;;
2666 esac
2667 shift
2668 done
2669
2670 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2671 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2672 fi
2673
2674 if [[ "$#" -eq 0 ]]; then
2675 die "${FUNCNAME}(): Missing files or directories"
2676 fi
2677
2678 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2033 while (($#)); do 2679 while (($#)); do
2680 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2681 die "${FUNCNAME}(): Invalid argument '$1'"
2034 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2682 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2035 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 2683 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2036 elif [[ "$1" =~ ^/ ]]; then 2684 elif [[ "$1" =~ ^/ ]]; then
2037 SEARCH_PATH+=("${root}/${1#/}") 2685 if _python_package_supporting_installation_for_multiple_python_abis; then
2686 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2687 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2688 fi
2689 if [[ "$1" != *\$* ]]; then
2690 die "${FUNCNAME}(): '$1' has invalid syntax"
2691 fi
2692 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2693 eval "search_paths+=(\"\${root}$1\")"
2694 done
2038 else 2695 else
2039 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2696 search_paths+=("${root}$1")
2040 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
2041 done
2042 fi
2043 shift
2044 done
2045 else
2046 SEARCH_PATH=("${@#/}")
2047 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
2048 fi
2049 else
2050 local dir sitedir
2051 for dir in "${root}"/usr/lib*; do
2052 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2053 for sitedir in "${dir}"/python*/site-packages; do
2054 if [[ -d "${sitedir}" ]]; then
2055 SEARCH_PATH+=("${sitedir}")
2056 fi 2697 fi
2698 else
2699 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2700 search_paths+=("${root}$(python_get_sitedir)/$1")
2057 done 2701 done
2058 fi 2702 fi
2703 shift
2059 done 2704 done
2060 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2705 else
2061 if [[ -d "${sitedir}" ]]; then 2706 # Deprecated part of python_mod_cleanup()
2062 SEARCH_PATH+=("${sitedir}") 2707 # ewarn
2063 fi 2708 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2064 done 2709 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2065 fi 2710 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2711 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2712 # ewarn
2066 2713
2067 for path in "${SEARCH_PATH[@]}"; do 2714 search_paths=("${@#/}")
2068 if [[ -d "${path}" ]]; then 2715 search_paths=("${search_paths[@]/#/${root}/}")
2069 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
2070 if [[ "${REPLY}" == *[co] ]]; then
2071 py_file="${REPLY%[co]}"
2072 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
2073 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
2074 rm -f "${py_file}"[co]
2075 elif [[ "${REPLY}" == *\$py.class ]]; then
2076 py_file="${REPLY%\$py.class}.py"
2077 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
2078 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
2079 rm -f "${py_file%.py}\$py.class"
2080 fi
2081 done
2082
2083 # Attempt to delete directories, which may be empty.
2084 find "${path}" -type d | sort -r | while read -r dir; do
2085 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
2086 done
2087 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
2088 if [[ (-f "${path}c" || -f "${path}o") ]]; then
2089 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
2090 rm -f "${path}"[co]
2091 fi
2092 if [[ -f "${path%.py}\$py.class" ]]; then
2093 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2094 rm -f "${path%.py}\$py.class"
2095 fi
2096 fi 2716 fi
2097 done 2717
2718 _python_clean_compiled_modules "${search_paths[@]}"
2098} 2719}
2099 2720
2100# ================================================================================================ 2721# ================================================================================================
2101# ===================================== DEPRECATED FUNCTIONS ===================================== 2722# ===================================== DEPRECATED FUNCTIONS =====================================
2102# ================================================================================================ 2723# ================================================================================================
2103 2724
2104# @FUNCTION: python_version 2725# Scheduled for deletion on 2011-01-01.
2105# @DESCRIPTION:
2106# Run without arguments and it will export the version of python
2107# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2108python_version() { 2726python_version() {
2109 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2110 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2111 die "${FUNCNAME}() cannot be used in this EAPI"
2112 fi
2113
2114 _python_set_color_variables
2115
2116 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2117 echo
2118 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2119 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2120 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2121 echo
2122
2123 einfo &> /dev/null
2124 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2125 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null 2727 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2126 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2728 die "${FUNCNAME}() is banned"
2127 einfo &> /dev/null
2128 fi
2129
2130 [[ -n "${PYVER}" ]] && return 0
2131 local tmpstr
2132 python="${python:-${EPREFIX}/usr/bin/python}"
2133 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2134 export PYVER_ALL="${tmpstr#Python }"
2135 export PYVER_MAJOR="${PYVER_ALL:0:1}"
2136 export PYVER_MINOR="${PYVER_ALL:2:1}"
2137 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2138 export PYVER_MICRO="${PYVER_ALL:4}"
2139 fi
2140 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2141} 2729}
2142 2730
2143# @FUNCTION: python_mod_exists 2731# Scheduled for deletion on 2011-01-01.
2144# @USAGE: <module>
2145# @DESCRIPTION:
2146# Run with the module name as an argument. It will check if a
2147# Python module is installed and loadable. It will return
2148# TRUE(0) if the module exists, and FALSE(1) if the module does
2149# not exist.
2150#
2151# Example:
2152# if python_mod_exists gtk; then
2153# echo "gtk support enabled"
2154# fi
2155python_mod_exists() { 2732python_mod_exists() {
2156 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2157 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2733 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2158 die "${FUNCNAME}() cannot be used in this EAPI" 2734 die "${FUNCNAME}() is banned"
2159 fi
2160
2161 echo
2162 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2163 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2165 echo
2166
2167 einfo &> /dev/null
2168 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2169 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2170 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2171 einfo &> /dev/null
2172
2173 if [[ "$#" -ne 1 ]]; then
2174 die "${FUNCNAME}() requires 1 argument"
2175 fi
2176 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2177} 2735}
2178 2736
2179# @FUNCTION: python_tkinter_exists 2737# Scheduled for deletion on 2011-01-01.
2180# @DESCRIPTION:
2181# Run without arguments, checks if Python was compiled with Tkinter
2182# support. If not, prints an error message and dies.
2183python_tkinter_exists() { 2738python_tkinter_exists() {
2184 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2185 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2739 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2186 die "${FUNCNAME}() cannot be used in this EAPI" 2740 die "${FUNCNAME}() is banned"
2187 fi
2188
2189 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2190 echo
2191 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2192 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2194 echo
2195
2196 einfo &> /dev/null
2197 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2198 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2199 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2200 einfo &> /dev/null
2201 fi
2202
2203 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2204if version_info[0] == 3:
2205 import tkinter
2206else:
2207 import Tkinter" &> /dev/null; then
2208 eerror "Python needs to be rebuilt with tkinter support enabled."
2209 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2210 eerror "dev-lang/python tk"
2211 die "Python installed without support for tkinter"
2212 fi
2213} 2741}
2214 2742
2215# @FUNCTION: python_mod_compile 2743# Scheduled for deletion on 2011-04-01.
2216# @USAGE: <file> [more files ...]
2217# @DESCRIPTION:
2218# Given filenames, it will pre-compile the module's .pyc and .pyo.
2219# This function can be used only in pkg_postinst() phase.
2220#
2221# Example:
2222# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2223#
2224python_mod_compile() { 2744python_mod_compile() {
2225 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2226 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2745 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2227 die "${FUNCNAME}() cannot be used in this EAPI" 2746 die "${FUNCNAME}() is banned"
2228 fi
2229
2230 _python_initialize_prefix_variables
2231
2232 local f myroot myfiles=()
2233
2234 # Check if phase is pkg_postinst()
2235 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2236
2237 # strip trailing slash
2238 myroot="${EROOT%/}"
2239
2240 # respect ROOT
2241 for f in "$@"; do
2242 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2243 done
2244
2245 if ((${#myfiles[@]})); then
2246 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2247 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2248 else
2249 ewarn "No files to compile!"
2250 fi
2251} 2747}

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.104

  ViewVC Help
Powered by ViewVC 1.1.20