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

Diff of /eclass/python.eclass

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

Revision 1.89 Revision 1.90
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.89 2010/02/14 18:53:11 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.90 2010/02/28 11:48:40 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
261# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 261# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
262# @DESCRIPTION: 262# @DESCRIPTION:
263# Set this in EAPI <= 4 to indicate that current package supports installation for 263# Set this in EAPI <= 4 to indicate that current package supports installation for
264# multiple versions of Python. 264# multiple versions of Python.
265 265
266# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS 266# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
267# @DESCRIPTION: 267# @DESCRIPTION:
268# Set this to define default functions for the following ebuild phases: 268# Set this to export phase functions for the following ebuild phases:
269# src_prepare, src_configure, src_compile, src_test, src_install. 269# src_prepare, src_configure, src_compile, src_test, src_install.
270if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then 270if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
271 python_src_prepare() { 271 python_src_prepare() {
272 python_copy_sources 272 python_copy_sources
273 } 273 }
274 274
275 for python_default_function in src_configure src_compile src_test src_install; do 275 for python_default_function in src_configure src_compile src_test src_install; do
276 eval "python_${python_default_function}() { python_execute_function -d -s; }" 276 eval "python_${python_default_function}() { python_execute_function -d -s; }"
277 done 277 done
278 unset python_default_function 278 unset python_default_function
279 279
280 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
280 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 281 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
282 fi
281fi 283fi
282 284
283unset PYTHON_ABIS 285unset PYTHON_ABIS
284unset PYTHON_ABIS_SANITY_CHECKS
285 286
286# @FUNCTION: validate_PYTHON_ABIS 287# @FUNCTION: validate_PYTHON_ABIS
287# @DESCRIPTION: 288# @DESCRIPTION:
288# Ensure that PYTHON_ABIS variable has valid value. 289# Ensure that PYTHON_ABIS variable has valid value.
289# This function usually should not be directly called in ebuilds. 290# This function usually should not be directly called in ebuilds.
291 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable. 292 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable.
292 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 293 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
293 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" 294 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
294 fi 295 fi
295 296
296 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 297 _python_initial_sanity_checks
297 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
298 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
299 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
300 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
301 fi
302 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
303 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
304 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
305 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
306 fi
307 298
308 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. 299 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
309 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 300 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
310 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 301 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
311 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 302 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
426 PYTHON_ABIS="${PYTHON_ABIS# }" 417 PYTHON_ABIS="${PYTHON_ABIS# }"
427 export PYTHON_ABIS="${PYTHON_ABIS% }" 418 export PYTHON_ABIS="${PYTHON_ABIS% }"
428 fi 419 fi
429 fi 420 fi
430 421
431 if ! _python_implementation && [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then 422 _python_final_sanity_checks
432 local PYTHON_ABI
433 for PYTHON_ABI in ${PYTHON_ABIS}; do
434 # Ensure that appropriate version of Python is installed.
435 if ! has_version "$(python_get_implementational_package)"; then
436 die "$(python_get_implementational_package) is not installed"
437 fi
438
439 # Ensure that EPYTHON variable is respected.
440 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
441 eerror "python: '$(type -p python)'"
442 eerror "ABI: '${ABI}'"
443 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
444 eerror "EPYTHON: '$(PYTHON)'"
445 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
446 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
447 die "'python' does not respect EPYTHON variable"
448 fi
449 done
450 PYTHON_ABIS_SANITY_CHECKS="1"
451 fi
452} 423}
453 424
454# @FUNCTION: python_execute_function 425# @FUNCTION: python_execute_function
455# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] 426# @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]
456# @DESCRIPTION: 427# @DESCRIPTION:
457# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 428# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
458# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 429# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
459python_execute_function() { 430python_execute_function() {
460 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function i nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= 431 _python_set_color_variables
432
433 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=
461 434
462 while (($#)); do 435 while (($#)); do
463 case "$1" in 436 case "$1" in
464 --action-message) 437 --action-message)
465 action_message_template="$2" 438 action_message_template="$2"
469 default_function="1" 442 default_function="1"
470 ;; 443 ;;
471 --failure-message) 444 --failure-message)
472 failure_message_template="$2" 445 failure_message_template="$2"
473 shift 446 shift
447 ;;
448 -f|--final-ABI)
449 final_ABI="1"
474 ;; 450 ;;
475 --nonfatal) 451 --nonfatal)
476 nonfatal="1" 452 nonfatal="1"
477 ;; 453 ;;
478 -q|--quiet) 454 -q|--quiet)
571 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 547 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
572 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 548 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
573 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 549 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
574 fi 550 fi
575 551
576 local RED GREEN BLUE NORMAL 552 validate_PYTHON_ABIS
577 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 553 if [[ "${final_ABI}" == "1" ]]; then
578 RED=$'\e[1;31m' 554 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
579 GREEN=$'\e[1;32m'
580 BLUE=$'\e[1;34m'
581 NORMAL=$'\e[0m'
582 else 555 else
583 RED= 556 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
584 GREEN=
585 BLUE=
586 NORMAL=
587 fi 557 fi
588
589 validate_PYTHON_ABIS
590 for PYTHON_ABI in ${PYTHON_ABIS}; do 558 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
591 if [[ "${quiet}" == "0" ]]; then 559 if [[ "${quiet}" == "0" ]]; then
592 if [[ -n "${action_message_template}" ]]; then 560 if [[ -n "${action_message_template}" ]]; then
593 action_message="$(eval echo -n "${action_message_template}")" 561 action_message="$(eval echo -n "${action_message_template}")"
594 else 562 else
595 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 563 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
596 fi 564 fi
597 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 565 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
598 fi 566 fi
599 567
600 if [[ "${separate_build_dirs}" == "1" ]]; then 568 if [[ "${separate_build_dirs}" == "1" ]]; then
601 if [[ -n "${source_dir}" ]]; then 569 if [[ -n "${source_dir}" ]]; then
602 export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}" 570 export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}"
625 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 593 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
626 fi 594 fi
627 595
628 if [[ "${nonfatal}" == "1" ]]; then 596 if [[ "${nonfatal}" == "1" ]]; then
629 if [[ "${quiet}" == "0" ]]; then 597 if [[ "${quiet}" == "0" ]]; then
630 ewarn "${RED}${failure_message}${NORMAL}" 598 ewarn "${_RED}${failure_message}${_NORMAL}"
631 fi 599 fi
632 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 600 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
633 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 601 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
634 local enabled_PYTHON_ABIS= other_PYTHON_ABI 602 local enabled_PYTHON_ABIS= other_PYTHON_ABI
635 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 603 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
636 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 604 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
637 done 605 done
638 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 606 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
639 fi 607 fi
640 if [[ "${quiet}" == "0" ]]; then 608 if [[ "${quiet}" == "0" ]]; then
641 ewarn "${RED}${failure_message}${NORMAL}" 609 ewarn "${_RED}${failure_message}${_NORMAL}"
642 fi 610 fi
643 if [[ -z "${PYTHON_ABIS}" ]]; then 611 if [[ -z "${PYTHON_ABIS}" ]]; then
644 die "${function}() function failed with all enabled versions of Python" 612 die "${function}() function failed with all enabled versions of Python"
645 fi 613 fi
646 else 614 else
679 unset -f python_default_function 647 unset -f python_default_function
680 fi 648 fi
681} 649}
682 650
683# @FUNCTION: python_copy_sources 651# @FUNCTION: python_copy_sources
684# @USAGE: [--no-link] [--] [directory] 652# @USAGE: <directory="${S}"> [directory]
685# @DESCRIPTION: 653# @DESCRIPTION:
686# Copy unpacked sources of current package to separate build directory for each Python ABI. 654# Copy unpacked sources of current package to separate build directory for each Python ABI.
687python_copy_sources() { 655python_copy_sources() {
688 local dir dirs=() no_link="0" PYTHON_ABI 656 local dir dirs=() PYTHON_ABI
689
690 while (($#)); do
691 case "$1" in
692 --no-link)
693 no_link="1"
694 ;;
695 --)
696 shift
697 break
698 ;;
699 -*)
700 die "${FUNCNAME}(): Unrecognized option '$1'"
701 ;;
702 *)
703 break
704 ;;
705 esac
706 shift
707 done
708 657
709 if [[ "$#" -eq 0 ]]; then 658 if [[ "$#" -eq 0 ]]; then
710 if [[ "${WORKDIR}" == "${S}" ]]; then 659 if [[ "${WORKDIR}" == "${S}" ]]; then
711 die "${FUNCNAME}() cannot be used" 660 die "${FUNCNAME}() cannot be used"
712 fi 661 fi
713 dirs="${S}" 662 dirs=("${S}")
714 else 663 else
715 dirs="$@" 664 dirs=("$@")
716 fi 665 fi
717 666
718 validate_PYTHON_ABIS 667 validate_PYTHON_ABIS
719 for PYTHON_ABI in ${PYTHON_ABIS}; do 668 for PYTHON_ABI in ${PYTHON_ABIS}; do
720 for dir in "${dirs[@]}"; do 669 for dir in "${dirs[@]}"; do
721 if [[ "${no_link}" == "1" ]]; then
722 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 670 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
723 else
724 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
725 fi
726 done 671 done
727 done 672 done
728} 673}
729 674
730# @FUNCTION: python_set_build_dir_symlink 675# @FUNCTION: python_set_build_dir_symlink
731# @USAGE: [directory="build"] 676# @USAGE: <directory="build">
732# @DESCRIPTION: 677# @DESCRIPTION:
733# Create build directory symlink. 678# Create build directory symlink.
734python_set_build_dir_symlink() { 679python_set_build_dir_symlink() {
735 local dir="$1" 680 local dir="$1"
736 681
920 865
921 if [[ "$#" -ne 1 ]]; then 866 if [[ "$#" -ne 1 ]]; then
922 die "${FUNCNAME}() requires 1 argument" 867 die "${FUNCNAME}() requires 1 argument"
923 fi 868 fi
924 869
870 _python_initial_sanity_checks
871
925 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 872 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
926 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 873 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
927 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 874 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
928 fi 875 fi
929 export EPYTHON="$(PYTHON "$1")" 876 export EPYTHON="$(PYTHON "$1")"
944 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 891 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
945 # so it does not need to be exported to subprocesses. 892 # so it does not need to be exported to subprocesses.
946 PYTHON_ABI="${EPYTHON#python}" 893 PYTHON_ABI="${EPYTHON#python}"
947 PYTHON_ABI="${PYTHON_ABI%%-*}" 894 PYTHON_ABI="${PYTHON_ABI%%-*}"
948 895
896 _python_final_sanity_checks
897
949 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 898 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
950 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 899 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
951} 900}
952 901
953# @FUNCTION: python_need_rebuild 902# @FUNCTION: python_need_rebuild
954# @DESCRIPTION: Mark current package for rebuilding by python-updater after 903# @DESCRIPTION: Mark current package for rebuilding by python-updater after
955# switching of active version of Python. 904# switching of active version of Python.
956python_need_rebuild() { 905python_need_rebuild() {
906 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
907 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
908 fi
909
957 export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)" 910 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
958} 911}
959 912
960# ================================================================================================ 913# ================================================================================================
961# ======================================= GETTER FUNCTIONS ======================================= 914# ======================================= GETTER FUNCTIONS =======================================
962# ================================================================================================ 915# ================================================================================================
980 die "${FUNCNAME}(): Unrecognized Python ABI '$1'" 933 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
981 fi 934 fi
982} 935}
983 936
984# @FUNCTION: PYTHON 937# @FUNCTION: PYTHON
985# @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 938# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
986# @DESCRIPTION: 939# @DESCRIPTION:
987# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument 940# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument
988# is ommitted, then PYTHON_ABI environment variable must be set and is used. 941# is ommitted, then PYTHON_ABI environment variable must be set and is used.
989# If -2 option is specified, then active version of Python 2 is used. 942# If -2 option is specified, then active version of Python 2 is used.
990# If -3 option is specified, then active version of Python 3 is used. 943# If -3 option is specified, then active version of Python 3 is used.
991# If --active option is specified, then active version of Python is used.
992# Active version of Python can be set by python_set_active_version().
993# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 944# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
994# -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously. 945# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
995# If --ABI option is specified, then only specified Python ABI is printed instead of 946# If --ABI option is specified, then only specified Python ABI is printed instead of
996# filename of Python interpreter. 947# filename of Python interpreter.
997# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 948# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
998# --ABI and --absolute-path options cannot be specified simultaneously. 949# --ABI and --absolute-path options cannot be specified simultaneously.
999PYTHON() { 950PYTHON() {
1000 local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 951 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1001 952
1002 while (($#)); do 953 while (($#)); do
1003 case "$1" in 954 case "$1" in
1004 -2) 955 -2)
1005 python2="1" 956 python2="1"
1008 python3="1" 959 python3="1"
1009 ;; 960 ;;
1010 --ABI) 961 --ABI)
1011 ABI_output="1" 962 ABI_output="1"
1012 ;; 963 ;;
1013 -A|--active)
1014 active="1"
1015 ;;
1016 -a|--absolute-path) 964 -a|--absolute-path)
1017 absolute_path_output="1" 965 absolute_path_output="1"
1018 ;; 966 ;;
1019 -f|--final-ABI) 967 -f|--final-ABI)
1020 final_ABI="1" 968 final_ABI="1"
1035 983
1036 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 984 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1037 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 985 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously"
1038 fi 986 fi
1039 987
1040 if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then 988 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1041 die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously" 989 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1042 fi 990 fi
1043 991
1044 if [[ "$#" -eq 0 ]]; then 992 if [[ "$#" -eq 0 ]]; then
1045 if [[ "${active}" == "1" ]]; then
1046 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1047 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
1048 fi
1049 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1050 elif [[ "${final_ABI}" == "1" ]]; then 993 if [[ "${final_ABI}" == "1" ]]; then
1051 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 994 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
1052 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" 995 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python"
1053 fi 996 fi
1054 validate_PYTHON_ABIS 997 validate_PYTHON_ABIS
1055 PYTHON_ABI="${PYTHON_ABIS##* }" 998 PYTHON_ABI="${PYTHON_ABIS##* }"
1065 if [[ -z "${PYTHON_ABI}" ]]; then 1008 if [[ -z "${PYTHON_ABI}" ]]; then
1066 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1009 die "${FUNCNAME}(): Active Python 3 interpreter not set"
1067 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1010 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1068 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1011 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1069 fi 1012 fi
1013 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
1014 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1070 elif [[ -z "${PYTHON_ABI}" ]]; then 1015 elif [[ -z "${PYTHON_ABI}" ]]; then
1071 die "${FUNCNAME}(): Invalid usage: Python ABI not specified" 1016 die "${FUNCNAME}(): Invalid usage: Python ABI not specified"
1072 fi 1017 fi
1073 elif [[ "$#" -eq 1 ]]; then 1018 elif [[ "$#" -eq 1 ]]; then
1074 if [[ "${active}" == "1" ]]; then
1075 die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously"
1076 fi
1077 if [[ "${final_ABI}" == "1" ]]; then 1019 if [[ "${final_ABI}" == "1" ]]; then
1078 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1020 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1079 fi 1021 fi
1080 if [[ "${python2}" == "1" ]]; then 1022 if [[ "${python2}" == "1" ]]; then
1081 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" 1023 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
1134 done 1076 done
1135 1077
1136 if [[ "${final_ABI}" == "1" ]]; then 1078 if [[ "${final_ABI}" == "1" ]]; then
1137 PYTHON_ABI="$(PYTHON -f --ABI)" 1079 PYTHON_ABI="$(PYTHON -f --ABI)"
1138 elif [[ -z "${PYTHON_ABI}" ]]; then 1080 elif [[ -z "${PYTHON_ABI}" ]]; then
1139 PYTHON_ABI="$(PYTHON -A --ABI)" 1081 PYTHON_ABI="$(PYTHON --ABI)"
1140 fi 1082 fi
1141 1083
1142 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1084 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1143} 1085}
1144 1086
1166 done 1108 done
1167 1109
1168 if [[ "${final_ABI}" == "1" ]]; then 1110 if [[ "${final_ABI}" == "1" ]]; then
1169 PYTHON_ABI="$(PYTHON -f --ABI)" 1111 PYTHON_ABI="$(PYTHON -f --ABI)"
1170 elif [[ -z "${PYTHON_ABI}" ]]; then 1112 elif [[ -z "${PYTHON_ABI}" ]]; then
1171 PYTHON_ABI="$(PYTHON -A --ABI)" 1113 PYTHON_ABI="$(PYTHON --ABI)"
1172 fi 1114 fi
1173 1115
1174 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1116 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1175 echo "dev-lang/python:${PYTHON_ABI}" 1117 echo "dev-lang/python:${PYTHON_ABI}"
1176 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1118 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1202 done 1144 done
1203 1145
1204 if [[ "${final_ABI}" == "1" ]]; then 1146 if [[ "${final_ABI}" == "1" ]]; then
1205 PYTHON_ABI="$(PYTHON -f --ABI)" 1147 PYTHON_ABI="$(PYTHON -f --ABI)"
1206 elif [[ -z "${PYTHON_ABI}" ]]; then 1148 elif [[ -z "${PYTHON_ABI}" ]]; then
1207 PYTHON_ABI="$(PYTHON -A --ABI)" 1149 PYTHON_ABI="$(PYTHON --ABI)"
1208 fi 1150 fi
1209 1151
1210 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1152 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1211 echo "/usr/include/python${PYTHON_ABI}" 1153 echo "/usr/include/python${PYTHON_ABI}"
1212 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1154 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1238 done 1180 done
1239 1181
1240 if [[ "${final_ABI}" == "1" ]]; then 1182 if [[ "${final_ABI}" == "1" ]]; then
1241 PYTHON_ABI="$(PYTHON -f --ABI)" 1183 PYTHON_ABI="$(PYTHON -f --ABI)"
1242 elif [[ -z "${PYTHON_ABI}" ]]; then 1184 elif [[ -z "${PYTHON_ABI}" ]]; then
1243 PYTHON_ABI="$(PYTHON -A --ABI)" 1185 PYTHON_ABI="$(PYTHON --ABI)"
1244 fi 1186 fi
1245 1187
1246 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1188 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1247 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1189 echo "/usr/$(get_libdir)/python${PYTHON_ABI}"
1248 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1190 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1304 done 1246 done
1305 1247
1306 if [[ "${final_ABI}" == "1" ]]; then 1248 if [[ "${final_ABI}" == "1" ]]; then
1307 PYTHON_ABI="$(PYTHON -f --ABI)" 1249 PYTHON_ABI="$(PYTHON -f --ABI)"
1308 elif [[ -z "${PYTHON_ABI}" ]]; then 1250 elif [[ -z "${PYTHON_ABI}" ]]; then
1309 PYTHON_ABI="$(PYTHON -A --ABI)" 1251 PYTHON_ABI="$(PYTHON --ABI)"
1310 fi 1252 fi
1311 1253
1312 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1254 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1313 if [[ "${linker_option}" == "1" ]]; then 1255 if [[ "${linker_option}" == "1" ]]; then
1314 echo "-lpython${PYTHON_ABI}" 1256 echo "-lpython${PYTHON_ABI}"
1369 fi 1311 fi
1370 1312
1371 if [[ "${final_ABI}" == "1" ]]; then 1313 if [[ "${final_ABI}" == "1" ]]; then
1372 "$(PYTHON -f)" -c "${python_command}" 1314 "$(PYTHON -f)" -c "${python_command}"
1373 else 1315 else
1374 "$(PYTHON "${PYTHON_ABI--A}")" -c "${python_command}" 1316 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1375 fi 1317 fi
1376} 1318}
1377 1319
1378# ================================================================================================ 1320# ================================================================================================
1379# =================================== MISCELLANEOUS FUNCTIONS ==================================== 1321# =================================== MISCELLANEOUS FUNCTIONS ====================================
1395 EROOT="${ROOT%/}${EPREFIX}/" 1337 EROOT="${ROOT%/}${EPREFIX}/"
1396 fi 1338 fi
1397 if [[ -n "${D}" && -z "${ED}" ]]; then 1339 if [[ -n "${D}" && -z "${ED}" ]]; then
1398 ED="${D%/}${EPREFIX}/" 1340 ED="${D%/}${EPREFIX}/"
1399 fi 1341 fi
1342 fi
1343}
1344
1345unset PYTHON_SANITY_CHECKS
1346
1347_python_initial_sanity_checks() {
1348 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1349 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
1350 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
1351 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
1352 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1353 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
1354 fi
1355 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
1356 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
1357 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1358 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
1359 fi
1360 fi
1361}
1362
1363_python_final_sanity_checks() {
1364 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1365 local PYTHON_ABI="${PYTHON_ABI}"
1366 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
1367 # Ensure that appropriate version of Python is installed.
1368 if ! has_version "$(python_get_implementational_package)"; then
1369 die "$(python_get_implementational_package) is not installed"
1370 fi
1371
1372 # Ensure that EPYTHON variable is respected.
1373 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
1374 eerror "python: '$(type -p python)'"
1375 eerror "ABI: '${ABI}'"
1376 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
1377 eerror "EPYTHON: '$(PYTHON)'"
1378 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
1379 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
1380 die "'python' does not respect EPYTHON variable"
1381 fi
1382 done
1383 fi
1384 PYTHON_SANITY_CHECKS="1"
1385}
1386
1387_python_set_color_variables() {
1388 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1389 _BOLD=$'\e[1m'
1390 _RED=$'\e[1;31m'
1391 _GREEN=$'\e[1;32m'
1392 _BLUE=$'\e[1;34m'
1393 _CYAN=$'\e[1;36m'
1394 _NORMAL=$'\e[0m'
1395 else
1396 _BOLD=
1397 _RED=
1398 _GREEN=
1399 _BLUE=
1400 _CYAN=
1401 _NORMAL=
1400 fi 1402 fi
1401} 1403}
1402 1404
1403# @FUNCTION: python_convert_shebangs 1405# @FUNCTION: python_convert_shebangs
1404# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 1406# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
1491# fi 1493# fi
1492python_mod_exists() { 1494python_mod_exists() {
1493 if [[ "$#" -ne 1 ]]; then 1495 if [[ "$#" -ne 1 ]]; then
1494 die "${FUNCNAME}() requires 1 argument" 1496 die "${FUNCNAME}() requires 1 argument"
1495 fi 1497 fi
1496 "$(PYTHON "${PYTHON_ABI--A}")" -c "import $1" &> /dev/null 1498 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
1497}
1498
1499# @FUNCTION: python_tkinter_exists
1500# @DESCRIPTION:
1501# Run without arguments, checks if Python was compiled with Tkinter
1502# support. If not, prints an error message and dies.
1503python_tkinter_exists() {
1504 if ! "$(PYTHON "${PYTHON_ABI--A}")" -c "from sys import version_info
1505if version_info[0] == 3:
1506 import tkinter
1507else:
1508 import Tkinter" &> /dev/null; then
1509 eerror "Python needs to be rebuilt with tkinter support enabled."
1510 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
1511 eerror "dev-lang/python tk"
1512 die "Python installed without support for tkinter"
1513 fi
1514} 1499}
1515 1500
1516# ================================================================================================ 1501# ================================================================================================
1517# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1502# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1518# ================================================================================================ 1503# ================================================================================================
1526# @FUNCTION: python_execute_nosetests 1511# @FUNCTION: python_execute_nosetests
1527# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1512# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1528# @DESCRIPTION: 1513# @DESCRIPTION:
1529# Execute nosetests for all enabled versions of Python. 1514# Execute nosetests for all enabled versions of Python.
1530python_execute_nosetests() { 1515python_execute_nosetests() {
1516 _python_set_color_variables
1517
1531 local PYTHONPATH_template= separate_build_dirs= 1518 local PYTHONPATH_template= separate_build_dirs=
1532 1519
1533 while (($#)); do 1520 while (($#)); do
1534 case "$1" in 1521 case "$1" in
1535 -P|--PYTHONPATH) 1522 -P|--PYTHONPATH)
1562 unset evaluated_PYTHONPATH 1549 unset evaluated_PYTHONPATH
1563 fi 1550 fi
1564 fi 1551 fi
1565 1552
1566 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1553 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1567 echo PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1554 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1568 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1555 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
1569 else 1556 else
1570 echo nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1557 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1571 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1558 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"
1572 fi 1559 fi
1573 } 1560 }
1574 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1561 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1575 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1562 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1586# @FUNCTION: python_execute_py.test 1573# @FUNCTION: python_execute_py.test
1587# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1574# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1588# @DESCRIPTION: 1575# @DESCRIPTION:
1589# Execute py.test for all enabled versions of Python. 1576# Execute py.test for all enabled versions of Python.
1590python_execute_py.test() { 1577python_execute_py.test() {
1578 _python_set_color_variables
1579
1591 local PYTHONPATH_template= separate_build_dirs= 1580 local PYTHONPATH_template= separate_build_dirs=
1592 1581
1593 while (($#)); do 1582 while (($#)); do
1594 case "$1" in 1583 case "$1" in
1595 -P|--PYTHONPATH) 1584 -P|--PYTHONPATH)
1622 unset evaluated_PYTHONPATH 1611 unset evaluated_PYTHONPATH
1623 fi 1612 fi
1624 fi 1613 fi
1625 1614
1626 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1615 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1627 echo PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" 1616 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1628 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" 1617 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"
1629 else 1618 else
1630 echo py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" 1619 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
1631 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" 1620 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"
1632 fi 1621 fi
1633 } 1622 }
1634 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1623 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1635 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1624 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1646# @FUNCTION: python_execute_trial 1635# @FUNCTION: python_execute_trial
1647# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1636# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1648# @DESCRIPTION: 1637# @DESCRIPTION:
1649# Execute trial for all enabled versions of Python. 1638# Execute trial for all enabled versions of Python.
1650python_execute_trial() { 1639python_execute_trial() {
1640 _python_set_color_variables
1641
1651 local PYTHONPATH_template= separate_build_dirs= 1642 local PYTHONPATH_template= separate_build_dirs=
1652 1643
1653 while (($#)); do 1644 while (($#)); do
1654 case "$1" in 1645 case "$1" in
1655 -P|--PYTHONPATH) 1646 -P|--PYTHONPATH)
1682 unset evaluated_PYTHONPATH 1673 unset evaluated_PYTHONPATH
1683 fi 1674 fi
1684 fi 1675 fi
1685 1676
1686 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1677 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1687 echo PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1678 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1688 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1679 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
1689 else 1680 else
1690 echo trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1681 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1691 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1682 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"
1692 fi 1683 fi
1693 } 1684 }
1694 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1685 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1695 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1686 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1743 1734
1744 # Check if phase is pkg_postinst(). 1735 # Check if phase is pkg_postinst().
1745 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 1736 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()"
1746 1737
1747 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1738 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1748 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 1739 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=()
1749 1740
1750 # Strip trailing slash from ROOT. 1741 # Strip trailing slash from ROOT.
1751 root="${EROOT%/}" 1742 root="${EROOT%/}"
1752 1743
1753 # Respect ROOT and options passed to compileall.py. 1744 # Respect ROOT and options passed to compileall.py.
1775 ewarn "'${root}/$1' is not a file or a directory!" 1766 ewarn "'${root}/$1' is not a file or a directory!"
1776 else 1767 else
1777 ewarn "'${root}/$1' does not exist!" 1768 ewarn "'${root}/$1' does not exist!"
1778 fi 1769 fi
1779 else 1770 else
1780 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do 1771 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1781 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 1772 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1782 site_packages_dirs+=("$1") 1773 site_packages_dirs+=("$1")
1783 break 1774 break
1784 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then 1775 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1785 site_packages_files+=("$1") 1776 site_packages_files+=("$1")
1797 done 1788 done
1798 1789
1799 # Set additional options. 1790 # Set additional options.
1800 options+=("-q") 1791 options+=("-q")
1801 1792
1802 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do 1793 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1803 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 1794 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
1804 return_code="0" 1795 return_code="0"
1805 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 1796 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1806 if ((${#site_packages_dirs[@]})); then 1797 if ((${#site_packages_dirs[@]})); then
1807 for dir in "${site_packages_dirs[@]}"; do 1798 for dir in "${site_packages_dirs[@]}"; do
1835 1826
1836 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 1827 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1837 return_code="0" 1828 return_code="0"
1838 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 1829 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
1839 if ((${#other_dirs[@]})); then 1830 if ((${#other_dirs[@]})); then
1840 "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 1831 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1841 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON -A --ABI)}")" != "Jython" ]]; then 1832 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then
1842 "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 1833 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1843 fi 1834 fi
1844 fi 1835 fi
1845 if ((${#other_files[@]})); then 1836 if ((${#other_files[@]})); then
1846 "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 1837 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1847 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON -A --ABI)}")" != "Jython" ]]; then 1838 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then
1848 "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 1839 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1849 fi 1840 fi
1850 fi 1841 fi
1851 eend "${return_code}" 1842 eend "${return_code}"
1852 fi 1843 fi
1853 else 1844 else
1888 # set additional opts 1879 # set additional opts
1889 myopts+=(-q) 1880 myopts+=(-q)
1890 1881
1891 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 1882 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1892 if ((${#mydirs[@]})); then 1883 if ((${#mydirs[@]})); then
1893 "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 1884 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1894 "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 1885 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
1895 fi 1886 fi
1896 1887
1897 if ((${#myfiles[@]})); then 1888 if ((${#myfiles[@]})); then
1898 python_mod_compile "${myfiles[@]}" 1889 python_mod_compile "${myfiles[@]}"
1899 fi 1890 fi
1913# If they are, then it will remove their corresponding .pyc and .pyo files. 1904# If they are, then it will remove their corresponding .pyc and .pyo files.
1914# 1905#
1915# This function should only be run in pkg_postrm(). 1906# This function should only be run in pkg_postrm().
1916python_mod_cleanup() { 1907python_mod_cleanup() {
1917 _python_initialize_prefix_variables 1908 _python_initialize_prefix_variables
1909 _python_set_color_variables
1918 1910
1919 local path py_file PYTHON_ABI SEARCH_PATH=() root 1911 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1920 1912
1921 # Check if phase is pkg_postrm(). 1913 # Check if phase is pkg_postrm().
1922 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" 1914 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()"
1923 1915
1924 # Strip trailing slash from ROOT. 1916 # Strip trailing slash from ROOT.
1930 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 1922 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1931 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 1923 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1932 elif [[ "$1" =~ ^/ ]]; then 1924 elif [[ "$1" =~ ^/ ]]; then
1933 SEARCH_PATH+=("${root}/${1#/}") 1925 SEARCH_PATH+=("${root}/${1#/}")
1934 else 1926 else
1935 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do 1927 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1936 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") 1928 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
1937 done 1929 done
1938 fi 1930 fi
1939 shift 1931 shift
1940 done 1932 done
1958 SEARCH_PATH+=("${sitedir}") 1950 SEARCH_PATH+=("${sitedir}")
1959 fi 1951 fi
1960 done 1952 done
1961 fi 1953 fi
1962 1954
1963 local BLUE CYAN NORMAL
1964 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1965 BLUE=$'\e[1;34m'
1966 CYAN=$'\e[1;36m'
1967 NORMAL=$'\e[0m'
1968 else
1969 BLUE=
1970 CYAN=
1971 NORMAL=
1972 fi
1973
1974 for path in "${SEARCH_PATH[@]}"; do 1955 for path in "${SEARCH_PATH[@]}"; do
1975 if [[ -d "${path}" ]]; then 1956 if [[ -d "${path}" ]]; then
1976 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do 1957 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
1977 if [[ "${REPLY}" == *[co] ]]; then 1958 if [[ "${REPLY}" == *[co] ]]; then
1978 py_file="${REPLY%[co]}" 1959 py_file="${REPLY%[co]}"
1979 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue 1960 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1980 einfo "${BLUE}<<< ${py_file}[co]${NORMAL}" 1961 einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
1981 rm -f "${py_file}"[co] 1962 rm -f "${py_file}"[co]
1982 elif [[ "${REPLY}" == *\$py.class ]]; then 1963 elif [[ "${REPLY}" == *\$py.class ]]; then
1983 py_file="${REPLY%\$py.class}.py" 1964 py_file="${REPLY%\$py.class}.py"
1984 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue 1965 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
1985 einfo "${BLUE}<<< ${py_file%.py}\$py.class${NORMAL}" 1966 einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
1986 rm -f "${py_file%.py}\$py.class" 1967 rm -f "${py_file%.py}\$py.class"
1987 fi 1968 fi
1988 done 1969 done
1989 1970
1990 # Attempt to delete directories, which may be empty. 1971 # Attempt to delete directories, which may be empty.
1991 find "${path}" -type d | sort -r | while read -r dir; do 1972 find "${path}" -type d | sort -r | while read -r dir; do
1992 rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}" 1973 rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}"
1993 done 1974 done
1994 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then 1975 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
1995 if [[ (-f "${path}c" || -f "${path}o") ]]; then 1976 if [[ (-f "${path}c" || -f "${path}o") ]]; then
1996 einfo "${BLUE}<<< ${path}[co]${NORMAL}" 1977 einfo "${_BLUE}<<< ${path}[co]${_NORMAL}"
1997 rm -f "${path}"[co] 1978 rm -f "${path}"[co]
1998 fi 1979 fi
1999 if [[ -f "${path%.py}\$py.class" ]]; then 1980 if [[ -f "${path%.py}\$py.class" ]]; then
2000 einfo "${BLUE}<<< ${path%.py}\$py.class${NORMAL}" 1981 einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2001 rm -f "${path%.py}\$py.class" 1982 rm -f "${path%.py}\$py.class"
2002 fi 1983 fi
2003 fi 1984 fi
2004 done 1985 done
2005} 1986}
2011# @FUNCTION: python_version 1992# @FUNCTION: python_version
2012# @DESCRIPTION: 1993# @DESCRIPTION:
2013# Run without arguments and it will export the version of python 1994# Run without arguments and it will export the version of python
2014# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 1995# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2015python_version() { 1996python_version() {
2016 if ! has "${EAPI:-0}" 0 1 2; then 1997 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2017 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." 1998 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2018 die "${FUNCNAME}() cannot be used in this EAPI" 1999 die "${FUNCNAME}() cannot be used in this EAPI"
2019 fi 2000 fi
2020 2001
2021 [[ -n "${PYVER}" ]] && return 0 2002 [[ -n "${PYVER}" ]] && return 0
2027 export PYVER_MINOR="${PYVER_ALL:2:1}" 2008 export PYVER_MINOR="${PYVER_ALL:2:1}"
2028 if [[ "${PYVER_ALL:3:1}" == "." ]]; then 2009 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2029 export PYVER_MICRO="${PYVER_ALL:4}" 2010 export PYVER_MICRO="${PYVER_ALL:4}"
2030 fi 2011 fi
2031 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" 2012 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2013}
2014
2015# @FUNCTION: python_tkinter_exists
2016# @DESCRIPTION:
2017# Run without arguments, checks if Python was compiled with Tkinter
2018# support. If not, prints an error message and dies.
2019python_tkinter_exists() {
2020 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2021 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2022 die "${FUNCNAME}() cannot be used in this EAPI"
2023 fi
2024
2025 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2026if version_info[0] == 3:
2027 import tkinter
2028else:
2029 import Tkinter" &> /dev/null; then
2030 eerror "Python needs to be rebuilt with tkinter support enabled."
2031 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2032 eerror "dev-lang/python tk"
2033 die "Python installed without support for tkinter"
2034 fi
2032} 2035}
2033 2036
2034# @FUNCTION: python_mod_compile 2037# @FUNCTION: python_mod_compile
2035# @USAGE: <file> [more files ...] 2038# @USAGE: <file> [more files ...]
2036# @DESCRIPTION: 2039# @DESCRIPTION:
2060 for f in "$@"; do 2063 for f in "$@"; do
2061 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 2064 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2062 done 2065 done
2063 2066
2064 if ((${#myfiles[@]})); then 2067 if ((${#myfiles[@]})); then
2065 "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" 2068 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2066 "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null 2069 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2067 else 2070 else
2068 ewarn "No files to compile!" 2071 ewarn "No files to compile!"
2069 fi 2072 fi
2070} 2073}

Legend:
Removed from v.1.89  
changed lines
  Added in v.1.90

  ViewVC Help
Powered by ViewVC 1.1.20