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

Diff of /eclass/python.eclass

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

Revision 1.98 Revision 1.103
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.98 2010/05/25 15:04:40 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.103 2010/10/03 00:38:13 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
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" 159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 160elif [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 161 _parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then 162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then 163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON." 164 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
165 die "NEED_PYTHON cannot be used in this EAPI" 165 die "NEED_PYTHON variable cannot be used in this EAPI"
166 fi 166 fi
167
168 ewarn
169 ewarn "\"${EBUILD}\":"
170 ewarn "Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01."
171 ewarn "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
172 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
173 ewarn
174
175 unset _BOLD _NORMAL
176
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}") 177 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}" 178 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}" 179 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 180else
171 _PYTHON_ATOMS=("dev-lang/python") 181 _PYTHON_ATOMS=("dev-lang/python")
241 else 251 else
242 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" 252 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
243 fi 253 fi
244} 254}
245 255
256_python_abi-specific_local_scope() {
257 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
258}
259
246_python_initialize_prefix_variables() { 260_python_initialize_prefix_variables() {
247 if has "${EAPI:-0}" 0 1 2; then 261 if has "${EAPI:-0}" 0 1 2; then
248 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then 262 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
249 EROOT="${ROOT%/}${EPREFIX}/" 263 EROOT="${ROOT%/}${EPREFIX}/"
250 fi 264 fi
252 ED="${D%/}${EPREFIX}/" 266 ED="${D%/}${EPREFIX}/"
253 fi 267 fi
254 fi 268 fi
255} 269}
256 270
257unset PYTHON_SANITY_CHECKS 271unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
258 272
259_python_initial_sanity_checks() { 273_python_initial_sanity_checks() {
260 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 274 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
261 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 275 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
262 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then 276 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
263 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." 277 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
264 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 278 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
265 die "'${EPREFIX}/usr/bin/python' is not valid symlink" 279 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
271 fi 285 fi
272 fi 286 fi
273} 287}
274 288
275_python_final_sanity_checks() { 289_python_final_sanity_checks() {
276 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 290 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
277 local PYTHON_ABI="${PYTHON_ABI}" 291 local PYTHON_ABI="${PYTHON_ABI}"
278 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do 292 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
279 # Ensure that appropriate version of Python is installed. 293 # Ensure that appropriate version of Python is installed.
280 if ! has_version "$(python_get_implementational_package)"; then 294 if ! has_version "$(python_get_implementational_package)"; then
281 die "$(python_get_implementational_package) is not installed" 295 die "$(python_get_implementational_package) is not installed"
291 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" 305 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
292 die "'python' does not respect EPYTHON variable" 306 die "'python' does not respect EPYTHON variable"
293 fi 307 fi
294 done 308 done
295 fi 309 fi
296 PYTHON_SANITY_CHECKS="1" 310 PYTHON_SANITY_CHECKS_EXECUTED="1"
297} 311}
312
313# @ECLASS-VARIABLE: PYTHON_COLORS
314# @DESCRIPTION:
315# User-configurable colored output.
316PYTHON_COLORS="${PYTHON_COLORS:-0}"
298 317
299_python_set_color_variables() { 318_python_set_color_variables() {
300 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 319 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
301 _BOLD=$'\e[1m' 320 _BOLD=$'\e[1m'
302 _RED=$'\e[1;31m' 321 _RED=$'\e[1;31m'
303 _GREEN=$'\e[1;32m' 322 _GREEN=$'\e[1;32m'
304 _BLUE=$'\e[1;34m' 323 _BLUE=$'\e[1;34m'
305 _CYAN=$'\e[1;36m' 324 _CYAN=$'\e[1;36m'
313 _NORMAL= 332 _NORMAL=
314 fi 333 fi
315} 334}
316 335
317unset PYTHON_PKG_SETUP_EXECUTED 336unset PYTHON_PKG_SETUP_EXECUTED
337
338_python_check_python_pkg_setup_execution() {
339 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
340
341 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
342 die "python_pkg_setup() not called"
343 fi
344}
318 345
319# @FUNCTION: python_pkg_setup 346# @FUNCTION: python_pkg_setup
320# @DESCRIPTION: 347# @DESCRIPTION:
321# Perform sanity checks and initialize environment. 348# Perform sanity checks and initialize environment.
322# 349#
326# This function can be used only in pkg_setup() phase. 353# This function can be used only in pkg_setup() phase.
327python_pkg_setup() { 354python_pkg_setup() {
328 # Check if phase is pkg_setup(). 355 # Check if phase is pkg_setup().
329 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 356 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
330 357
358 if [[ "$#" -ne 0 ]]; then
359 die "${FUNCNAME}() does not accept arguments"
360 fi
361
331 if _python_package_supporting_installation_for_multiple_python_abis; then 362 if _python_package_supporting_installation_for_multiple_python_abis; then
332 _python_calculate_PYTHON_ABIS 363 _python_calculate_PYTHON_ABIS
333 export EPYTHON="$(PYTHON -f)" 364 export EPYTHON="$(PYTHON -f)"
334 else 365 else
335 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 366 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
366 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" 397 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
367 fi 398 fi
368 } 399 }
369 400
370 if _python_package_supporting_installation_for_multiple_python_abis; then 401 if _python_package_supporting_installation_for_multiple_python_abis; then
371 python_execute_function -q python_pkg_setup_check_USE_flags 402 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
372 else 403 else
373 python_pkg_setup_check_USE_flags 404 python_pkg_setup_check_USE_flags
374 fi 405 fi
375 406
376 unset -f python_pkg_setup_check_USE_flags 407 unset -f python_pkg_setup_check_USE_flags
386# @FUNCTION: python_convert_shebangs 417# @FUNCTION: python_convert_shebangs
387# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 418# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
388# @DESCRIPTION: 419# @DESCRIPTION:
389# Convert shebangs in specified files. Directories can be specified only with --recursive option. 420# Convert shebangs in specified files. Directories can be specified only with --recursive option.
390python_convert_shebangs() { 421python_convert_shebangs() {
422 _python_check_python_pkg_setup_execution
423
391 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 424 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
392 425
393 while (($#)); do 426 while (($#)); do
394 case "$1" in 427 case "$1" in
395 -r|--recursive) 428 -r|--recursive)
464# @FUNCTION: python_clean_installation_image 497# @FUNCTION: python_clean_installation_image
465# @USAGE: [-q|--quiet] 498# @USAGE: [-q|--quiet]
466# @DESCRIPTION: 499# @DESCRIPTION:
467# Delete needless files in installation image. 500# Delete needless files in installation image.
468python_clean_installation_image() { 501python_clean_installation_image() {
502 _python_check_python_pkg_setup_execution
469 _python_initialize_prefix_variables 503 _python_initialize_prefix_variables
470 504
471 local file files=() quiet="0" 505 local file files=() quiet="0"
472 506
473 # Check if phase is src_install(). 507 # Check if phase is src_install().
536# @DESCRIPTION: 570# @DESCRIPTION:
537# Set this to export phase functions for the following ebuild phases: 571# Set this to export phase functions for the following ebuild phases:
538# src_prepare, src_configure, src_compile, src_test, src_install. 572# src_prepare, src_configure, src_compile, src_test, src_install.
539if ! has "${EAPI:-0}" 0 1; then 573if ! has "${EAPI:-0}" 0 1; then
540 python_src_prepare() { 574 python_src_prepare() {
575 _python_check_python_pkg_setup_execution
576
541 if ! _python_package_supporting_installation_for_multiple_python_abis; then 577 if ! _python_package_supporting_installation_for_multiple_python_abis; then
542 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 578 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
543 fi 579 fi
544 580
581 if [[ "$#" -ne 0 ]]; then
582 die "${FUNCNAME}() does not accept arguments"
583 fi
584
545 python_copy_sources 585 python_copy_sources
546 } 586 }
547 587
548 for python_default_function in src_configure src_compile src_test src_install; do 588 for python_default_function in src_configure src_compile src_test src_install; do
549 eval "python_${python_default_function}() { 589 eval "python_${python_default_function}() {
590 _python_check_python_pkg_setup_execution
591
550 if ! _python_package_supporting_installation_for_multiple_python_abis; then 592 if ! _python_package_supporting_installation_for_multiple_python_abis; then
551 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 593 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
552 fi 594 fi
553 595
554 python_execute_function -d -s -- \"\$@\" 596 python_execute_function -d -s -- \"\$@\"
689 fi 731 fi
690 732
691 _python_final_sanity_checks 733 _python_final_sanity_checks
692} 734}
693 735
736_python_prepare_flags() {
737 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
738
739 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
740 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
741 for prefix in PYTHON_USER_ PYTHON_; do
742 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
743 eval "array=(\"\${${prefix}${variable}[@]}\")"
744 for element in "${array[@]}"; do
745 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
746 pattern="${element%% *}"
747 element="${element#* }"
748 operator="${element%% *}"
749 flags="${element#* }"
750 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
751 if [[ "${operator}" == "+" ]]; then
752 eval "export ${variable}+=\"\${variable:+ }${flags}\""
753 elif [[ "${operator}" == "-" ]]; then
754 flags="${flags// /$'\n'}"
755 old_value="${!variable// /$'\n'}"
756 new_value=""
757 while read old_flag; do
758 while read deleted_flag; do
759 if [[ "${old_flag}" == ${deleted_flag} ]]; then
760 continue 2
761 fi
762 done <<< "${flags}"
763 new_value+="${new_value:+ }${old_flag}"
764 done <<< "${old_value}"
765 eval "export ${variable}=\"\${new_value}\""
766 fi
767 fi
768 else
769 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
770 fi
771 done
772 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
773 die "${prefix}${variable} should be indexed array"
774 fi
775 done
776 done
777}
778
779_python_restore_flags() {
780 local variable
781
782 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
783 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
784 unset _PYTHON_SAVED_${variable}
785 done
786}
787
694# @FUNCTION: python_execute_function 788# @FUNCTION: python_execute_function
695# @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] 789# @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]
696# @DESCRIPTION: 790# @DESCRIPTION:
697# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 791# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
698# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 792# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
699python_execute_function() { 793python_execute_function() {
794 _python_check_python_pkg_setup_execution
795
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 796 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" 797 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 798 fi
703 799
704 _python_set_color_variables 800 _python_set_color_variables
705 801
706 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= 802 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=
707 803
708 while (($#)); do 804 while (($#)); do
709 case "$1" in 805 case "$1" in
710 --action-message) 806 --action-message)
711 action_message_template="$2" 807 action_message_template="$2"
798 fi 894 fi
799 function="python_default_function" 895 function="python_default_function"
800 fi 896 fi
801 897
802 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 898 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
803 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 899 if _python_abi-specific_local_scope; then
804 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
805 die "${FUNCNAME}(): Invalid call stack" 900 die "${FUNCNAME}(): Invalid call stack"
806 fi 901 fi
807 done
808 902
809 if [[ "${quiet}" == "0" ]]; then 903 if [[ "${quiet}" == "0" ]]; then
810 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 904 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
811 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 905 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
812 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 906 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
825 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 919 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
826 else 920 else
827 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 921 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
828 fi 922 fi
829 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 923 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
924 _python_prepare_flags
925
830 if [[ "${quiet}" == "0" ]]; then 926 if [[ "${quiet}" == "0" ]]; then
831 if [[ -n "${action_message_template}" ]]; then 927 if [[ -n "${action_message_template}" ]]; then
832 action_message="$(eval echo -n "${action_message_template}")" 928 eval "action_message=\"${action_message_template}\""
833 else 929 else
834 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 930 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
835 fi 931 fi
836 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 932 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
837 fi 933 fi
855 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 951 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
856 else 952 else
857 EPYTHON="$(PYTHON)" "${function}" "$@" 953 EPYTHON="$(PYTHON)" "${function}" "$@"
858 fi 954 fi
859 955
860 if [[ "$?" != "0" ]]; then 956 return_code="$?"
957
958 _python_restore_flags
959
960 if [[ "${return_code}" -ne 0 ]]; then
861 if [[ -n "${failure_message_template}" ]]; then 961 if [[ -n "${failure_message_template}" ]]; then
862 failure_message="$(eval echo -n "${failure_message_template}")" 962 eval "failure_message=\"${failure_message_template}\""
863 else 963 else
864 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 964 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
865 fi 965 fi
866 966
867 if [[ "${nonfatal}" == "1" ]]; then 967 if [[ "${nonfatal}" == "1" ]]; then
868 if [[ "${quiet}" == "0" ]]; then 968 if [[ "${quiet}" == "0" ]]; then
869 ewarn "${_RED}${failure_message}${_NORMAL}" 969 ewarn "${failure_message}"
870 fi 970 fi
871 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 971 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
872 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 972 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
873 local enabled_PYTHON_ABIS= other_PYTHON_ABI 973 local enabled_PYTHON_ABIS= other_PYTHON_ABI
874 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 974 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
875 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 975 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
876 done 976 done
877 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 977 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
878 fi 978 fi
879 if [[ "${quiet}" == "0" ]]; then 979 if [[ "${quiet}" == "0" ]]; then
880 ewarn "${_RED}${failure_message}${_NORMAL}" 980 ewarn "${failure_message}"
881 fi 981 fi
882 if [[ -z "${PYTHON_ABIS}" ]]; then 982 if [[ -z "${PYTHON_ABIS}" ]]; then
883 die "${function}() function failed with all enabled Python ABIs" 983 die "${function}() function failed with all enabled Python ABIs"
884 fi 984 fi
885 else 985 else
922# @FUNCTION: python_copy_sources 1022# @FUNCTION: python_copy_sources
923# @USAGE: <directory="${S}"> [directory] 1023# @USAGE: <directory="${S}"> [directory]
924# @DESCRIPTION: 1024# @DESCRIPTION:
925# Copy unpacked sources of current package to separate build directory for each Python ABI. 1025# Copy unpacked sources of current package to separate build directory for each Python ABI.
926python_copy_sources() { 1026python_copy_sources() {
1027 _python_check_python_pkg_setup_execution
1028
927 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1029 if ! _python_package_supporting_installation_for_multiple_python_abis; then
928 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1030 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
929 fi 1031 fi
930 1032
931 local dir dirs=() PYTHON_ABI 1033 local dir dirs=() PYTHON_ABI
952# @DESCRIPTION: 1054# @DESCRIPTION:
953# Generate wrapper scripts. Existing files are overwritten only with --force option. 1055# Generate wrapper scripts. Existing files are overwritten only with --force option.
954# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1056# If --respect-EPYTHON option is specified, then generated wrapper scripts will
955# respect EPYTHON variable at run time. 1057# respect EPYTHON variable at run time.
956python_generate_wrapper_scripts() { 1058python_generate_wrapper_scripts() {
1059 _python_check_python_pkg_setup_execution
1060
957 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1061 if ! _python_package_supporting_installation_for_multiple_python_abis; then
958 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1062 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
959 fi 1063 fi
960 1064
961 _python_initialize_prefix_variables 1065 _python_initialize_prefix_variables
1155 1259
1156# ================================================================================================ 1260# ================================================================================================
1157# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1261# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1158# ================================================================================================ 1262# ================================================================================================
1159 1263
1264unset EPYTHON PYTHON_ABI
1265
1160# @FUNCTION: python_set_active_version 1266# @FUNCTION: python_set_active_version
1161# @USAGE: <CPython_ABI|2|3> 1267# @USAGE: <CPython_ABI|2|3>
1162# @DESCRIPTION: 1268# @DESCRIPTION:
1163# Set specified version of CPython as active version of Python. 1269# Set specified version of CPython as active version of Python.
1270#
1271# This function can be used only in pkg_setup() phase.
1164python_set_active_version() { 1272python_set_active_version() {
1273 # Check if phase is pkg_setup().
1274 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1275
1165 if _python_package_supporting_installation_for_multiple_python_abis; then 1276 if _python_package_supporting_installation_for_multiple_python_abis; then
1166 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1277 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1167 fi 1278 fi
1168 1279
1169 if [[ "$#" -ne 1 ]]; then 1280 if [[ "$#" -ne 1 ]]; then
1170 die "${FUNCNAME}() requires 1 argument" 1281 die "${FUNCNAME}() requires 1 argument"
1171 fi 1282 fi
1172 1283
1173 _python_initial_sanity_checks 1284 _python_initial_sanity_checks
1174 1285
1286 if [[ -z "${PYTHON_ABI}" ]]; then
1175 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1287 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1176 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1288 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
1177 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1289 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
1178 fi 1290 fi
1179 export EPYTHON="$(PYTHON "$1")" 1291 export EPYTHON="$(PYTHON "$1")"
1180 elif [[ "$1" == "2" ]]; then 1292 elif [[ "$1" == "2" ]]; then
1181 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1293 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1182 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1294 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1183 fi 1295 fi
1184 export EPYTHON="$(PYTHON -2)" 1296 export EPYTHON="$(PYTHON -2)"
1185 elif [[ "$1" == "3" ]]; then 1297 elif [[ "$1" == "3" ]]; then
1186 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1298 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1187 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1299 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1188 fi 1300 fi
1189 export EPYTHON="$(PYTHON -3)" 1301 export EPYTHON="$(PYTHON -3)"
1190 else 1302 else
1191 die "${FUNCNAME}(): Unrecognized argument '$1'" 1303 die "${FUNCNAME}(): Unrecognized argument '$1'"
1192 fi 1304 fi
1193 1305
1194 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1306 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1195 # so it does not need to be exported to subprocesses. 1307 # so it does not need to be exported to subprocesses.
1196 PYTHON_ABI="${EPYTHON#python}" 1308 PYTHON_ABI="${EPYTHON#python}"
1197 PYTHON_ABI="${PYTHON_ABI%%-*}" 1309 PYTHON_ABI="${PYTHON_ABI%%-*}"
1310 fi
1198 1311
1199 _python_final_sanity_checks 1312 _python_final_sanity_checks
1200 1313
1201 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1314 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1202 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1315 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1204 1317
1205# @FUNCTION: python_need_rebuild 1318# @FUNCTION: python_need_rebuild
1206# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1319# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1207# switching of active version of Python. 1320# switching of active version of Python.
1208python_need_rebuild() { 1321python_need_rebuild() {
1322 _python_check_python_pkg_setup_execution
1323
1209 if _python_package_supporting_installation_for_multiple_python_abis; then 1324 if _python_package_supporting_installation_for_multiple_python_abis; then
1210 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1325 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1326 fi
1327
1328 if [[ "$#" -ne 0 ]]; then
1329 die "${FUNCNAME}() does not accept arguments"
1211 fi 1330 fi
1212 1331
1213 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1332 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1214} 1333}
1215 1334
1249# If --ABI option is specified, then only specified Python ABI is printed instead of 1368# If --ABI option is specified, then only specified Python ABI is printed instead of
1250# filename of Python interpreter. 1369# filename of Python interpreter.
1251# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1370# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1252# --ABI and --absolute-path options cannot be specified simultaneously. 1371# --ABI and --absolute-path options cannot be specified simultaneously.
1253PYTHON() { 1372PYTHON() {
1373 _python_check_python_pkg_setup_execution
1374
1254 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1375 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1255 1376
1256 while (($#)); do 1377 while (($#)); do
1257 case "$1" in 1378 case "$1" in
1258 -2) 1379 -2)
1283 esac 1404 esac
1284 shift 1405 shift
1285 done 1406 done
1286 1407
1287 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1408 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1288 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1409 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1289 fi 1410 fi
1290 1411
1291 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1412 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1292 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1413 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1293 fi 1414 fi
1311 if [[ -z "${PYTHON_ABI}" ]]; then 1432 if [[ -z "${PYTHON_ABI}" ]]; then
1312 die "${FUNCNAME}(): Active version of Python 3 not set" 1433 die "${FUNCNAME}(): Active version of Python 3 not set"
1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1434 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1435 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1315 fi 1436 fi
1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1437 elif _python_package_supporting_installation_for_multiple_python_abis; then
1438 if ! _python_abi-specific_local_scope; then
1439 die "${FUNCNAME}() should be used in ABI-specific local scope"
1440 fi
1441 else
1317 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1442 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1318 if [[ -z "${PYTHON_ABI}" ]]; then 1443 if [[ -z "${PYTHON_ABI}" ]]; then
1319 die "${FUNCNAME}(): Failure of extraction of locally active version of Python" 1444 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1320 fi 1445 fi
1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1322 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1323 fi 1446 fi
1324 elif [[ "$#" -eq 1 ]]; then 1447 elif [[ "$#" -eq 1 ]]; then
1325 if [[ "${final_ABI}" == "1" ]]; then 1448 if [[ "${final_ABI}" == "1" ]]; then
1326 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1449 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1327 fi 1450 fi
1362# @USAGE: [-f|--final-ABI] 1485# @USAGE: [-f|--final-ABI]
1363# @DESCRIPTION: 1486# @DESCRIPTION:
1364# Print name of Python implementation. 1487# Print name of Python implementation.
1365# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1488# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1366python_get_implementation() { 1489python_get_implementation() {
1490 _python_check_python_pkg_setup_execution
1491
1367 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1492 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1368 1493
1369 while (($#)); do 1494 while (($#)); do
1370 case "$1" in 1495 case "$1" in
1371 -f|--final-ABI) 1496 -f|--final-ABI)
1384 if [[ "${final_ABI}" == "1" ]]; then 1509 if [[ "${final_ABI}" == "1" ]]; then
1385 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1510 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1386 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1511 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1387 fi 1512 fi
1388 PYTHON_ABI="$(PYTHON -f --ABI)" 1513 PYTHON_ABI="$(PYTHON -f --ABI)"
1389 elif [[ -z "${PYTHON_ABI}" ]]; then 1514 else
1515 if _python_package_supporting_installation_for_multiple_python_abis; then
1516 if ! _python_abi-specific_local_scope; then
1517 die "${FUNCNAME}() should be used in ABI-specific local scope"
1518 fi
1519 else
1390 PYTHON_ABI="$(PYTHON --ABI)" 1520 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1521 fi
1391 fi 1522 fi
1392 1523
1393 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1524 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1394} 1525}
1395 1526
1397# @USAGE: [-f|--final-ABI] 1528# @USAGE: [-f|--final-ABI]
1398# @DESCRIPTION: 1529# @DESCRIPTION:
1399# Print category, name and slot of package providing Python implementation. 1530# Print category, name and slot of package providing Python implementation.
1400# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1531# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1401python_get_implementational_package() { 1532python_get_implementational_package() {
1533 _python_check_python_pkg_setup_execution
1534
1402 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1535 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1403 1536
1404 while (($#)); do 1537 while (($#)); do
1405 case "$1" in 1538 case "$1" in
1406 -f|--final-ABI) 1539 -f|--final-ABI)
1419 if [[ "${final_ABI}" == "1" ]]; then 1552 if [[ "${final_ABI}" == "1" ]]; then
1420 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1553 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1421 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1554 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1422 fi 1555 fi
1423 PYTHON_ABI="$(PYTHON -f --ABI)" 1556 PYTHON_ABI="$(PYTHON -f --ABI)"
1424 elif [[ -z "${PYTHON_ABI}" ]]; then 1557 else
1558 if _python_package_supporting_installation_for_multiple_python_abis; then
1559 if ! _python_abi-specific_local_scope; then
1560 die "${FUNCNAME}() should be used in ABI-specific local scope"
1561 fi
1562 else
1425 PYTHON_ABI="$(PYTHON --ABI)" 1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi
1426 fi 1565 fi
1427 1566
1428 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1429 echo "dev-lang/python:${PYTHON_ABI}" 1568 echo "dev-lang/python:${PYTHON_ABI}"
1430 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1431 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1570 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1432 fi 1571 fi
1433} 1572}
1434 1573
1435# @FUNCTION: python_get_includedir 1574# @FUNCTION: python_get_includedir
1436# @USAGE: [-f|--final-ABI] 1575# @USAGE: [-b|--base-path] [-f|--final-ABI]
1437# @DESCRIPTION: 1576# @DESCRIPTION:
1438# Print path to Python include directory. 1577# Print path to Python include directory.
1578# If --base-path option is specified, then path not prefixed with "/" is printed.
1439# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1579# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1440python_get_includedir() { 1580python_get_includedir() {
1581 _python_check_python_pkg_setup_execution
1582
1441 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1583 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1442 1584
1443 while (($#)); do 1585 while (($#)); do
1444 case "$1" in 1586 case "$1" in
1587 -b|--base-path)
1588 base_path="1"
1589 ;;
1445 -f|--final-ABI) 1590 -f|--final-ABI)
1446 final_ABI="1" 1591 final_ABI="1"
1447 ;; 1592 ;;
1448 -*) 1593 -*)
1449 die "${FUNCNAME}(): Unrecognized option '$1'" 1594 die "${FUNCNAME}(): Unrecognized option '$1'"
1452 die "${FUNCNAME}(): Invalid usage" 1597 die "${FUNCNAME}(): Invalid usage"
1453 ;; 1598 ;;
1454 esac 1599 esac
1455 shift 1600 shift
1456 done 1601 done
1602
1603 if [[ "${base_path}" == "0" ]]; then
1604 prefix="/"
1605 fi
1457 1606
1458 if [[ "${final_ABI}" == "1" ]]; then 1607 if [[ "${final_ABI}" == "1" ]]; then
1459 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1608 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1460 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1609 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1461 fi 1610 fi
1462 PYTHON_ABI="$(PYTHON -f --ABI)" 1611 PYTHON_ABI="$(PYTHON -f --ABI)"
1463 elif [[ -z "${PYTHON_ABI}" ]]; then 1612 else
1613 if _python_package_supporting_installation_for_multiple_python_abis; then
1614 if ! _python_abi-specific_local_scope; then
1615 die "${FUNCNAME}() should be used in ABI-specific local scope"
1616 fi
1617 else
1464 PYTHON_ABI="$(PYTHON --ABI)" 1618 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1619 fi
1465 fi 1620 fi
1466 1621
1467 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1622 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1468 echo "/usr/include/python${PYTHON_ABI}" 1623 echo "${prefix}usr/include/python${PYTHON_ABI}"
1469 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1624 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1470 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1625 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1471 fi 1626 fi
1472} 1627}
1473 1628
1474# @FUNCTION: python_get_libdir 1629# @FUNCTION: python_get_libdir
1475# @USAGE: [-f|--final-ABI] 1630# @USAGE: [-b|--base-path] [-f|--final-ABI]
1476# @DESCRIPTION: 1631# @DESCRIPTION:
1477# Print path to Python library directory. 1632# Print path to Python library directory.
1633# If --base-path option is specified, then path not prefixed with "/" is printed.
1478# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1634# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1479python_get_libdir() { 1635python_get_libdir() {
1636 _python_check_python_pkg_setup_execution
1637
1480 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1638 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1481 1639
1482 while (($#)); do 1640 while (($#)); do
1483 case "$1" in 1641 case "$1" in
1642 -b|--base-path)
1643 base_path="1"
1644 ;;
1484 -f|--final-ABI) 1645 -f|--final-ABI)
1485 final_ABI="1" 1646 final_ABI="1"
1486 ;; 1647 ;;
1487 -*) 1648 -*)
1488 die "${FUNCNAME}(): Unrecognized option '$1'" 1649 die "${FUNCNAME}(): Unrecognized option '$1'"
1491 die "${FUNCNAME}(): Invalid usage" 1652 die "${FUNCNAME}(): Invalid usage"
1492 ;; 1653 ;;
1493 esac 1654 esac
1494 shift 1655 shift
1495 done 1656 done
1657
1658 if [[ "${base_path}" == "0" ]]; then
1659 prefix="/"
1660 fi
1496 1661
1497 if [[ "${final_ABI}" == "1" ]]; then 1662 if [[ "${final_ABI}" == "1" ]]; then
1498 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1663 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1499 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1664 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1500 fi 1665 fi
1501 PYTHON_ABI="$(PYTHON -f --ABI)" 1666 PYTHON_ABI="$(PYTHON -f --ABI)"
1502 elif [[ -z "${PYTHON_ABI}" ]]; then 1667 else
1668 if _python_package_supporting_installation_for_multiple_python_abis; then
1669 if ! _python_abi-specific_local_scope; then
1670 die "${FUNCNAME}() should be used in ABI-specific local scope"
1671 fi
1672 else
1503 PYTHON_ABI="$(PYTHON --ABI)" 1673 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1674 fi
1504 fi 1675 fi
1505 1676
1506 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1677 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1507 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1678 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1508 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1679 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1509 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1680 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1510 fi 1681 fi
1511} 1682}
1512 1683
1513# @FUNCTION: python_get_sitedir 1684# @FUNCTION: python_get_sitedir
1514# @USAGE: [-f|--final-ABI] 1685# @USAGE: [-b|--base-path] [-f|--final-ABI]
1515# @DESCRIPTION: 1686# @DESCRIPTION:
1516# Print path to Python site-packages directory. 1687# Print path to Python site-packages directory.
1688# If --base-path option is specified, then path not prefixed with "/" is printed.
1517# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1689# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1518python_get_sitedir() { 1690python_get_sitedir() {
1519 local options=() 1691 _python_check_python_pkg_setup_execution
1692
1693 local final_ABI="0" options=()
1520 1694
1521 while (($#)); do 1695 while (($#)); do
1522 case "$1" in 1696 case "$1" in
1697 -b|--base-path)
1698 options+=("$1")
1699 ;;
1523 -f|--final-ABI) 1700 -f|--final-ABI)
1524 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1701 final_ABI="1"
1525 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1526 fi
1527 options+=("$1") 1702 options+=("$1")
1528 ;; 1703 ;;
1529 -*) 1704 -*)
1530 die "${FUNCNAME}(): Unrecognized option '$1'" 1705 die "${FUNCNAME}(): Unrecognized option '$1'"
1531 ;; 1706 ;;
1534 ;; 1709 ;;
1535 esac 1710 esac
1536 shift 1711 shift
1537 done 1712 done
1538 1713
1714 if [[ "${final_ABI}" == "1" ]]; then
1715 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1716 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1717 fi
1718 else
1719 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1720 die "${FUNCNAME}() should be used in ABI-specific local scope"
1721 fi
1722 fi
1723
1539 echo "$(python_get_libdir "${options[@]}")/site-packages" 1724 echo "$(python_get_libdir "${options[@]}")/site-packages"
1540} 1725}
1541 1726
1542# @FUNCTION: python_get_library 1727# @FUNCTION: python_get_library
1543# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1728# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1544# @DESCRIPTION: 1729# @DESCRIPTION:
1545# Print path to Python library. 1730# Print path to Python library.
1731# If --base-path option is specified, then path not prefixed with "/" is printed.
1546# If --linker-option is specified, then "-l${library}" linker option is printed. 1732# If --linker-option is specified, then "-l${library}" linker option is printed.
1547# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1733# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1548python_get_library() { 1734python_get_library() {
1735 _python_check_python_pkg_setup_execution
1736
1549 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1737 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1550 1738
1551 while (($#)); do 1739 while (($#)); do
1552 case "$1" in 1740 case "$1" in
1741 -b|--base-path)
1742 base_path="1"
1743 ;;
1553 -f|--final-ABI) 1744 -f|--final-ABI)
1554 final_ABI="1" 1745 final_ABI="1"
1555 ;; 1746 ;;
1556 -l|--linker-option) 1747 -l|--linker-option)
1557 linker_option="1" 1748 linker_option="1"
1563 die "${FUNCNAME}(): Invalid usage" 1754 die "${FUNCNAME}(): Invalid usage"
1564 ;; 1755 ;;
1565 esac 1756 esac
1566 shift 1757 shift
1567 done 1758 done
1759
1760 if [[ "${base_path}" == "0" ]]; then
1761 prefix="/"
1762 fi
1763
1764 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1765 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1766 fi
1568 1767
1569 if [[ "${final_ABI}" == "1" ]]; then 1768 if [[ "${final_ABI}" == "1" ]]; then
1570 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1769 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1571 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1770 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1572 fi 1771 fi
1573 PYTHON_ABI="$(PYTHON -f --ABI)" 1772 PYTHON_ABI="$(PYTHON -f --ABI)"
1574 elif [[ -z "${PYTHON_ABI}" ]]; then 1773 else
1774 if _python_package_supporting_installation_for_multiple_python_abis; then
1775 if ! _python_abi-specific_local_scope; then
1776 die "${FUNCNAME}() should be used in ABI-specific local scope"
1777 fi
1778 else
1575 PYTHON_ABI="$(PYTHON --ABI)" 1779 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1780 fi
1576 fi 1781 fi
1577 1782
1578 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1783 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1579 if [[ "${linker_option}" == "1" ]]; then 1784 if [[ "${linker_option}" == "1" ]]; then
1580 echo "-lpython${PYTHON_ABI}" 1785 echo "-lpython${PYTHON_ABI}"
1581 else 1786 else
1582 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1787 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1583 fi 1788 fi
1584 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1789 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1585 die "${FUNCNAME}(): Jython does not have shared library" 1790 die "${FUNCNAME}(): Jython does not have shared library"
1586 fi 1791 fi
1587} 1792}
1592# Print Python version. 1797# Print Python version.
1593# --full, --major, --minor and --micro options cannot be specified simultaneously. 1798# --full, --major, --minor and --micro options cannot be specified simultaneously.
1594# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1799# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1595# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1800# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1596python_get_version() { 1801python_get_version() {
1802 _python_check_python_pkg_setup_execution
1803
1597 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1804 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1598 1805
1599 while (($#)); do 1806 while (($#)); do
1600 case "$1" in 1807 case "$1" in
1601 -f|--final-ABI) 1808 -f|--final-ABI)
1651 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1858 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1652 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1859 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1653 fi 1860 fi
1654 "$(PYTHON -f)" -c "${python_command}" 1861 "$(PYTHON -f)" -c "${python_command}"
1655 else 1862 else
1863 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1864 die "${FUNCNAME}() should be used in ABI-specific local scope"
1865 fi
1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1866 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1657 fi 1867 fi
1658} 1868}
1659 1869
1660# ================================================================================================ 1870# ================================================================================================
1682# @DESCRIPTION: 1892# @DESCRIPTION:
1683# Execute nosetests for all enabled Python ABIs. 1893# Execute nosetests for all enabled Python ABIs.
1684# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1894# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1685# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 1895# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1686python_execute_nosetests() { 1896python_execute_nosetests() {
1897 _python_check_python_pkg_setup_execution
1687 _python_set_color_variables 1898 _python_set_color_variables
1688 1899
1689 local PYTHONPATH_template= separate_build_dirs= 1900 local PYTHONPATH_template= separate_build_dirs=
1690 1901
1691 while (($#)); do 1902 while (($#)); do
1710 esac 1921 esac
1711 shift 1922 shift
1712 done 1923 done
1713 1924
1714 python_test_function() { 1925 python_test_function() {
1715 local evaluated_PYTHONPATH= 1926 local evaluated_PYTHONPATH
1716 1927
1717 if [[ -n "${PYTHONPATH_template}" ]]; then
1718 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1928 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1719 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1720 unset evaluated_PYTHONPATH
1721 fi
1722 fi
1723 1929
1724 _python_test_hook pre 1930 _python_test_hook pre
1725 1931
1726 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1932 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1727 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1933 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1750# @DESCRIPTION: 1956# @DESCRIPTION:
1751# Execute py.test for all enabled Python ABIs. 1957# Execute py.test for all enabled Python ABIs.
1752# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1958# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1753# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 1959# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1754python_execute_py.test() { 1960python_execute_py.test() {
1961 _python_check_python_pkg_setup_execution
1755 _python_set_color_variables 1962 _python_set_color_variables
1756 1963
1757 local PYTHONPATH_template= separate_build_dirs= 1964 local PYTHONPATH_template= separate_build_dirs=
1758 1965
1759 while (($#)); do 1966 while (($#)); do
1778 esac 1985 esac
1779 shift 1986 shift
1780 done 1987 done
1781 1988
1782 python_test_function() { 1989 python_test_function() {
1783 local evaluated_PYTHONPATH= 1990 local evaluated_PYTHONPATH
1784 1991
1785 if [[ -n "${PYTHONPATH_template}" ]]; then
1786 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1992 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1787 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1788 unset evaluated_PYTHONPATH
1789 fi
1790 fi
1791 1993
1792 _python_test_hook pre 1994 _python_test_hook pre
1793 1995
1794 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1996 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1795 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1997 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1818# @DESCRIPTION: 2020# @DESCRIPTION:
1819# Execute trial for all enabled Python ABIs. 2021# Execute trial for all enabled Python ABIs.
1820# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2022# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1821# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2023# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1822python_execute_trial() { 2024python_execute_trial() {
2025 _python_check_python_pkg_setup_execution
1823 _python_set_color_variables 2026 _python_set_color_variables
1824 2027
1825 local PYTHONPATH_template= separate_build_dirs= 2028 local PYTHONPATH_template= separate_build_dirs=
1826 2029
1827 while (($#)); do 2030 while (($#)); do
1846 esac 2049 esac
1847 shift 2050 shift
1848 done 2051 done
1849 2052
1850 python_test_function() { 2053 python_test_function() {
1851 local evaluated_PYTHONPATH= 2054 local evaluated_PYTHONPATH
1852 2055
1853 if [[ -n "${PYTHONPATH_template}" ]]; then
1854 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2056 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1855 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1856 unset evaluated_PYTHONPATH
1857 fi
1858 fi
1859 2057
1860 _python_test_hook pre 2058 _python_test_hook pre
1861 2059
1862 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2060 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1863 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2061 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1888# @FUNCTION: python_enable_pyc 2086# @FUNCTION: python_enable_pyc
1889# @DESCRIPTION: 2087# @DESCRIPTION:
1890# Tell Python to automatically recompile modules to .pyc/.pyo if the 2088# Tell Python to automatically recompile modules to .pyc/.pyo if the
1891# timestamps/version stamps have changed. 2089# timestamps/version stamps have changed.
1892python_enable_pyc() { 2090python_enable_pyc() {
2091 _python_check_python_pkg_setup_execution
2092
2093 if [[ "$#" -ne 0 ]]; then
2094 die "${FUNCNAME}() does not accept arguments"
2095 fi
2096
1893 unset PYTHONDONTWRITEBYTECODE 2097 unset PYTHONDONTWRITEBYTECODE
1894} 2098}
1895 2099
1896# @FUNCTION: python_disable_pyc 2100# @FUNCTION: python_disable_pyc
1897# @DESCRIPTION: 2101# @DESCRIPTION:
1898# Tell Python not to automatically recompile modules to .pyc/.pyo 2102# Tell Python not to automatically recompile modules to .pyc/.pyo
1899# even if the timestamps/version stamps do not match. This is done 2103# even if the timestamps/version stamps do not match. This is done
1900# to protect sandbox. 2104# to protect sandbox.
1901python_disable_pyc() { 2105python_disable_pyc() {
2106 _python_check_python_pkg_setup_execution
2107
2108 if [[ "$#" -ne 0 ]]; then
2109 die "${FUNCNAME}() does not accept arguments"
2110 fi
2111
1902 export PYTHONDONTWRITEBYTECODE="1" 2112 export PYTHONDONTWRITEBYTECODE="1"
1903} 2113}
1904 2114
1905_python_clean_compiled_modules() { 2115_python_clean_compiled_modules() {
1906 _python_initialize_prefix_variables 2116 _python_initialize_prefix_variables
1921 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) 2131 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1922 2132
1923 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2133 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1924 # Delete empty child directories. 2134 # Delete empty child directories.
1925 find "${path}" -type d | sort -r | while read -r dir; do 2135 find "${path}" -type d | sort -r | while read -r dir; do
1926 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" 2136 if rmdir "${dir}" 2> /dev/null; then
2137 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2138 fi
1927 done 2139 done
1928 fi 2140 fi
1929 elif [[ "${path}" == *.py ]]; then 2141 elif [[ "${path}" == *.py ]]; then
1930 base_module_name="${path##*/}" 2142 base_module_name="${path##*/}"
1931 base_module_name="${base_module_name%.py}" 2143 base_module_name="${base_module_name%.py}"
1977 fi 2189 fi
1978 2190
1979 # Delete empty parent directories. 2191 # Delete empty parent directories.
1980 dir="${compiled_file%/*}" 2192 dir="${compiled_file%/*}"
1981 while [[ "${dir}" != "${root}" ]]; do 2193 while [[ "${dir}" != "${root}" ]]; do
1982 if rmdir "${compiled_file%/*}" 2> /dev/null; then 2194 if rmdir "${dir}" 2> /dev/null; then
1983 echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}" 2195 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1984 else 2196 else
1985 break 2197 break
1986 fi 2198 fi
1987 dir="${dir%/*}" 2199 dir="${dir%/*}"
1988 done 2200 done
2001# 2213#
2002# Options passed to this function are passed to compileall.py. 2214# Options passed to this function are passed to compileall.py.
2003# 2215#
2004# This function can be used only in pkg_postinst() phase. 2216# This function can be used only in pkg_postinst() phase.
2005python_mod_optimize() { 2217python_mod_optimize() {
2218 _python_check_python_pkg_setup_execution
2006 _python_initialize_prefix_variables 2219 _python_initialize_prefix_variables
2007 2220
2008 # Check if phase is pkg_postinst(). 2221 # Check if phase is pkg_postinst().
2009 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2222 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2010 2223
2011 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2224 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2012 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2225 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2013 local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 2226 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=()
2014 2227
2015 if _python_package_supporting_installation_for_multiple_python_abis; then 2228 if _python_package_supporting_installation_for_multiple_python_abis; then
2016 if [[ -z "${PYTHON_ABIS}" ]]; then 2229 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2017 die "${FUNCNAME}(): Environment not initialized" 2230 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2018 fi 2231 fi
2019 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2232 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2020 else 2233 else
2234 if has "${EAPI:-0}" 0 1 2 3; then
2021 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}" 2235 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2236 else
2237 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2238 fi
2022 fi 2239 fi
2023 2240
2024 # Strip trailing slash from EROOT. 2241 # Strip trailing slash from EROOT.
2025 root="${EROOT%/}" 2242 root="${EROOT%/}"
2026 2243
2027 while (($#)); do 2244 while (($#)); do
2028 case "$1" in 2245 case "$1" in
2246 --allow-evaluated-non-sitedir-paths)
2247 allow_evaluated_non_sitedir_paths="1"
2248 ;;
2029 -l|-f|-q) 2249 -l|-f|-q)
2030 options+=("$1") 2250 options+=("$1")
2031 ;; 2251 ;;
2032 -d|-x) 2252 -d|-x)
2033 options+=("$1" "$2") 2253 options+=("$1" "$2")
2034 shift 2254 shift
2035 ;; 2255 ;;
2256 --)
2257 shift
2258 break
2259 ;;
2036 -*) 2260 -*)
2037 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2261 die "${FUNCNAME}(): Unrecognized option '$1'"
2038 ;; 2262 ;;
2039 *) 2263 *)
2040 break 2264 break
2041 ;; 2265 ;;
2042 esac 2266 esac
2043 shift 2267 shift
2044 done 2268 done
2045 2269
2270 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2271 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2272 fi
2273
2046 if [[ "$#" -eq 0 ]]; then 2274 if [[ "$#" -eq 0 ]]; then
2047 _python_set_color_variables 2275 ewarn
2048
2049 echo
2050 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2051 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2052 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2053 echo
2054
2055 einfo &> /dev/null
2056 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null 2276 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2057 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null 2277 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2058 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2278 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2059 einfo &> /dev/null 2279 ewarn
2060 fi 2280 fi
2061 2281
2062 while (($#)); do 2282 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'"
2063 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2285 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2064 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2286 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2065 elif [[ "$1" =~ ^/ ]]; then 2287 elif [[ "$1" =~ ^/ ]]; then
2066 if _python_package_supporting_installation_for_multiple_python_abis; then 2288 if _python_package_supporting_installation_for_multiple_python_abis; then
2289 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2067 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2290 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2068 fi 2291 fi
2069 if [[ -d "${root}$1" ]]; then 2292 if [[ "$1" != *\$* ]]; then
2070 other_dirs+=("${root}$1") 2293 die "${FUNCNAME}(): '$1' has invalid syntax"
2071 elif [[ -f "${root}$1" ]]; then 2294 fi
2072 other_files+=("${root}$1") 2295 if [[ "$1" == *.py ]]; then
2073 elif [[ -e "${root}$1" ]]; then 2296 evaluated_files+=("$1")
2074 eerror "'${root}$1' is not a file or a directory!" 2297 else
2298 evaluated_dirs+=("$1")
2299 fi
2075 else 2300 else
2301 if [[ -d "${root}$1" ]]; then
2302 other_dirs+=("${root}$1")
2303 elif [[ -f "${root}$1" ]]; then
2304 other_files+=("${root}$1")
2305 elif [[ -e "${root}$1" ]]; then
2306 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2307 else
2076 eerror "'${root}$1' does not exist!" 2308 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2309 fi
2077 fi 2310 fi
2078 else 2311 else
2079 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2312 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2080 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 2313 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2081 site_packages_dirs+=("$1") 2314 site_packages_dirs+=("$1")
2082 break 2315 break
2083 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then 2316 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2084 site_packages_files+=("$1") 2317 site_packages_files+=("$1")
2085 break 2318 break
2086 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then 2319 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2087 eerror "'$1' is not a file or a directory!" 2320 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2088 else 2321 else
2089 eerror "'$1' does not exist!" 2322 eerror "${FUNCNAME}(): '$1' does not exist"
2090 fi 2323 fi
2091 done 2324 done
2092 fi 2325 fi
2093 shift 2326 shift
2094 done 2327 done
2095 2328
2096 # Set additional options. 2329 # Set additional options.
2097 options+=("-q") 2330 options+=("-q")
2098 2331
2099 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2332 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2100 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2333 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2101 return_code="0" 2334 return_code="0"
2102 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2335 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
2103 if ((${#site_packages_dirs[@]})); then 2336 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2104 for dir in "${site_packages_dirs[@]}"; do 2337 for dir in "${site_packages_dirs[@]}"; do
2105 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2338 dirs+=("${root}$(python_get_sitedir)/${dir}")
2106 done 2339 done
2340 for dir in "${evaluated_dirs[@]}"; do
2341 eval "dirs+=(\"\${root}${dir}\")"
2342 done
2107 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2343 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
2108 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2344 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2109 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2345 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2110 fi 2346 fi
2111 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" 2347 _python_clean_compiled_modules "${dirs[@]}"
2112 fi 2348 fi
2113 if ((${#site_packages_files[@]})); then 2349 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2114 for file in "${site_packages_files[@]}"; do 2350 for file in "${site_packages_files[@]}"; do
2115 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2351 files+=("${root}$(python_get_sitedir)/${file}")
2116 done 2352 done
2353 for file in "${evaluated_files[@]}"; do
2354 eval "files+=(\"\${root}${file}\")"
2355 done
2117 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2356 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
2118 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2357 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2119 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2358 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2120 fi 2359 fi
2121 _python_clean_compiled_modules "${site_packages_absolute_files[@]}" 2360 _python_clean_compiled_modules "${files[@]}"
2122 fi 2361 fi
2123 eend "${return_code}" 2362 eend "${return_code}"
2124 fi 2363 fi
2125 unset site_packages_absolute_dirs site_packages_absolute_files 2364 unset dirs files
2126 done 2365 done
2127 2366
2128 if _python_package_supporting_installation_for_multiple_python_abis; then 2367 if _python_package_supporting_installation_for_multiple_python_abis; then
2129 # Restore previous value of PYTHON_ABI. 2368 # Restore previous value of PYTHON_ABI.
2130 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2369 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2169 ;; 2408 ;;
2170 -d|-x) 2409 -d|-x)
2171 myopts+=("$1" "$2") 2410 myopts+=("$1" "$2")
2172 shift 2411 shift
2173 ;; 2412 ;;
2413 --)
2414 shift
2415 break
2416 ;;
2174 -*) 2417 -*)
2175 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2418 die "${FUNCNAME}(): Unrecognized option '$1'"
2176 ;; 2419 ;;
2177 *) 2420 *)
2178 break 2421 break
2179 ;; 2422 ;;
2180 esac 2423 esac
2181 shift 2424 shift
2182 done 2425 done
2183 2426
2184 if [[ "$#" -eq 0 ]]; then 2427 if [[ "$#" -eq 0 ]]; then
2185 _python_set_color_variables 2428 ewarn
2186
2187 echo
2188 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2189 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2190 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2191 echo
2192
2193 einfo &> /dev/null
2194 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null 2429 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2195 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null 2430 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2196 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2431 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2197 einfo &> /dev/null 2432 ewarn
2198 fi 2433 fi
2199 2434
2200 while (($#)); do 2435 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'"
2201 if [[ -d "${myroot}/${1#/}" ]]; then 2438 elif [[ -d "${myroot}/${1#/}" ]]; then
2202 mydirs+=("${myroot}/${1#/}") 2439 mydirs+=("${myroot}/${1#/}")
2203 elif [[ -f "${myroot}/${1#/}" ]]; then 2440 elif [[ -f "${myroot}/${1#/}" ]]; then
2204 # Files are passed to python_mod_compile which is EROOT-aware 2441 # Files are passed to python_mod_compile which is EROOT-aware
2205 myfiles+=("$1") 2442 myfiles+=("$1")
2206 elif [[ -e "${myroot}/${1#/}" ]]; then 2443 elif [[ -e "${myroot}/${1#/}" ]]; then
2207 eerror "${myroot}/${1#/} is not a file or directory!" 2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2208 else 2445 else
2209 eerror "${myroot}/${1#/} does not exist!" 2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2210 fi 2447 fi
2211 shift 2448 shift
2212 done 2449 done
2213 2450
2214 # set additional opts 2451 # set additional opts
2241# determine if they are orphaned (i.e. their corresponding .py files are missing.) 2478# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2242# If they are, then it will remove their corresponding .pyc and .pyo files. 2479# If they are, then it will remove their corresponding .pyc and .pyo files.
2243# 2480#
2244# This function can be used only in pkg_postrm() phase. 2481# This function can be used only in pkg_postrm() phase.
2245python_mod_cleanup() { 2482python_mod_cleanup() {
2483 _python_check_python_pkg_setup_execution
2246 _python_initialize_prefix_variables 2484 _python_initialize_prefix_variables
2247 2485
2248 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2486 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2249 2487
2250 # Check if phase is pkg_postrm(). 2488 # Check if phase is pkg_postrm().
2251 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2489 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2252 2490
2253 if _python_package_supporting_installation_for_multiple_python_abis; then 2491 if _python_package_supporting_installation_for_multiple_python_abis; then
2254 if [[ -z "${PYTHON_ABIS}" ]]; then 2492 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2255 die "${FUNCNAME}(): Environment not initialized" 2493 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2256 fi 2494 fi
2257 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2495 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2258 else 2496 else
2497 if has "${EAPI:-0}" 0 1 2 3; then
2259 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}" 2498 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2499 else
2500 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2501 fi
2260 fi 2502 fi
2261 2503
2262 # Strip trailing slash from EROOT. 2504 # Strip trailing slash from EROOT.
2263 root="${EROOT%/}" 2505 root="${EROOT%/}"
2506
2507 while (($#)); do
2508 case "$1" in
2509 --allow-evaluated-non-sitedir-paths)
2510 allow_evaluated_non_sitedir_paths="1"
2511 ;;
2512 --)
2513 shift
2514 break
2515 ;;
2516 -*)
2517 die "${FUNCNAME}(): Unrecognized option '$1'"
2518 ;;
2519 *)
2520 break
2521 ;;
2522 esac
2523 shift
2524 done
2525
2526 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2527 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2528 fi
2264 2529
2265 if [[ "$#" -gt 0 ]]; then 2530 if [[ "$#" -gt 0 ]]; then
2266 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2531 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2267 while (($#)); do 2532 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'"
2268 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2535 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2269 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2536 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2270 elif [[ "$1" =~ ^/ ]]; then 2537 elif [[ "$1" =~ ^/ ]]; then
2271 if _python_package_supporting_installation_for_multiple_python_abis; then 2538 if _python_package_supporting_installation_for_multiple_python_abis; then
2539 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2272 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2540 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2541 fi
2542 if [[ "$1" != *\$* ]]; then
2543 die "${FUNCNAME}(): '$1' has invalid syntax"
2544 fi
2545 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2546 eval "search_paths+=(\"\${root}$1\")"
2547 done
2548 else
2549 search_paths+=("${root}$1")
2273 fi 2550 fi
2274 search_paths+=("${root}$1")
2275 else 2551 else
2276 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2277 search_paths+=("${root}$(python_get_sitedir)/$1") 2553 search_paths+=("${root}$(python_get_sitedir)/$1")
2278 done 2554 done
2279 fi 2555 fi
2284 2560
2285 search_paths=("${@#/}") 2561 search_paths=("${@#/}")
2286 search_paths=("${search_paths[@]/#/${root}/}") 2562 search_paths=("${search_paths[@]/#/${root}/}")
2287 fi 2563 fi
2288 else 2564 else
2289 _python_set_color_variables 2565 ewarn
2290
2291 echo
2292 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2293 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2294 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2295 echo
2296
2297 einfo &> /dev/null
2298 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null 2566 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2299 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null 2567 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2300 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2568 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2301 einfo &> /dev/null 2569 ewarn
2302 2570
2303 for dir in "${root}"/usr/lib*; do 2571 for dir in "${root}"/usr/lib*; do
2304 if [[ -d "${dir}" && ! -L "${dir}" ]]; then 2572 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2305 for sitedir in "${dir}"/python*/site-packages; do 2573 for sitedir in "${dir}"/python*/site-packages; do
2306 if [[ -d "${sitedir}" ]]; then 2574 if [[ -d "${sitedir}" ]]; then
2321 2589
2322# ================================================================================================ 2590# ================================================================================================
2323# ===================================== DEPRECATED FUNCTIONS ===================================== 2591# ===================================== DEPRECATED FUNCTIONS =====================================
2324# ================================================================================================ 2592# ================================================================================================
2325 2593
2326# @FUNCTION: python_version 2594# Scheduled for deletion on 2011-01-01.
2327# @DESCRIPTION:
2328# Run without arguments and it will export the version of python
2329# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2330python_version() { 2595python_version() {
2331 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2332 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2333 die "${FUNCNAME}() cannot be used in this EAPI"
2334 fi
2335
2336 _python_set_color_variables
2337
2338 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2339 echo
2340 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2341 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2342 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2343 echo
2344
2345 einfo &> /dev/null
2346 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2347 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null 2596 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2348 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2597 die "${FUNCNAME}() is banned"
2349 einfo &> /dev/null
2350 fi
2351
2352 [[ -n "${PYVER}" ]] && return 0
2353 local tmpstr
2354 python="${python:-${EPREFIX}/usr/bin/python}"
2355 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2356 export PYVER_ALL="${tmpstr#Python }"
2357 export PYVER_MAJOR="${PYVER_ALL:0:1}"
2358 export PYVER_MINOR="${PYVER_ALL:2:1}"
2359 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2360 export PYVER_MICRO="${PYVER_ALL:4}"
2361 fi
2362 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2363} 2598}
2364 2599
2365# @FUNCTION: python_mod_exists 2600# Scheduled for deletion on 2011-01-01.
2366# @USAGE: <module>
2367# @DESCRIPTION:
2368# Run with the module name as an argument. It will check if a
2369# Python module is installed and loadable. It will return
2370# TRUE(0) if the module exists, and FALSE(1) if the module does
2371# not exist.
2372#
2373# Example:
2374# if python_mod_exists gtk; then
2375# echo "gtk support enabled"
2376# fi
2377python_mod_exists() { 2601python_mod_exists() {
2378 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2379 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2602 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2380 die "${FUNCNAME}() cannot be used in this EAPI" 2603 die "${FUNCNAME}() is banned"
2381 fi
2382
2383 _python_set_color_variables
2384
2385 echo
2386 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2387 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2388 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2389 echo
2390
2391 eerror &> /dev/null
2392 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2393 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2394 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2395 eerror &> /dev/null
2396
2397 if [[ "$#" -ne 1 ]]; then
2398 die "${FUNCNAME}() requires 1 argument"
2399 fi
2400 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2401} 2604}
2402 2605
2403# @FUNCTION: python_tkinter_exists 2606# Scheduled for deletion on 2011-01-01.
2404# @DESCRIPTION:
2405# Run without arguments, checks if Python was compiled with Tkinter
2406# support. If not, prints an error message and dies.
2407python_tkinter_exists() { 2607python_tkinter_exists() {
2408 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2409 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2608 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2410 die "${FUNCNAME}() cannot be used in this EAPI" 2609 die "${FUNCNAME}() is banned"
2411 fi
2412
2413 _python_set_color_variables
2414
2415 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2416 echo
2417 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2418 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2419 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2420 echo
2421
2422 eerror &> /dev/null
2423 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2424 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2425 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2426 eerror &> /dev/null
2427 fi
2428
2429 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2430if version_info[0] == 3:
2431 import tkinter
2432else:
2433 import Tkinter" &> /dev/null; then
2434 eerror "Python needs to be rebuilt with tkinter support enabled."
2435 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2436 eerror "dev-lang/python tk"
2437 die "Python installed without support for tkinter"
2438 fi
2439} 2610}
2440 2611
2441# @FUNCTION: python_mod_compile 2612# @FUNCTION: python_mod_compile
2442# @USAGE: <file> [more files ...] 2613# @USAGE: <file> [more files ...]
2443# @DESCRIPTION: 2614# @DESCRIPTION:
2454 fi 2625 fi
2455 2626
2456 _python_initialize_prefix_variables 2627 _python_initialize_prefix_variables
2457 _python_set_color_variables 2628 _python_set_color_variables
2458 2629
2459 echo 2630 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2460 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}" 2631 ewarn
2461 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2462 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2463 echo
2464
2465 einfo &> /dev/null
2466 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null 2632 ewarn "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01."
2467 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null 2633 ewarn "Use python_mod_optimize() instead of ${FUNCNAME}()."
2468 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2634 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2469 einfo &> /dev/null 2635 ewarn
2636 fi
2470 2637
2471 local f myroot myfiles=() 2638 local f myroot myfiles=()
2472 2639
2473 # Check if phase is pkg_postinst() 2640 # Check if phase is pkg_postinst()
2474 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2641 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.103

  ViewVC Help
Powered by ViewVC 1.1.20