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

Diff of /eclass/python.eclass

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

Revision 1.97 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.97 2010/05/17 18:01:59 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 validate_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)" 366 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
336 fi 367 fi
337 368
338 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 369 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
339 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then 370 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
340 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then 371 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
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().
499 for file in "${files[@]}"; do 533 for file in "${files[@]}"; do
500 if [[ "${quiet}" == "0" ]]; then 534 if [[ "${quiet}" == "0" ]]; then
501 ewarn " ${file}" 535 ewarn " ${file}"
502 fi 536 fi
503 rm -f "${file}" 537 rm -f "${file}"
538
539 # Delete empty __pycache__ directories.
540 if [[ "${file%/*}" == *"/__pycache__" ]]; then
541 rmdir "${file%/*}" 2> /dev/null
542 fi
504 done 543 done
505 fi 544 fi
506 545
507 python_clean_sitedirs() { 546 python_clean_sitedirs() {
547 if [[ -d "${ED}$(python_get_sitedir)" ]]; then
508 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f 548 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
549 fi
509 } 550 }
510 if _python_package_supporting_installation_for_multiple_python_abis; then 551 if _python_package_supporting_installation_for_multiple_python_abis; then
511 python_execute_function -q python_clean_sitedirs 552 python_execute_function -q python_clean_sitedirs
512 else 553 else
513 python_clean_sitedirs 554 python_clean_sitedirs
529# @DESCRIPTION: 570# @DESCRIPTION:
530# Set this to export phase functions for the following ebuild phases: 571# Set this to export phase functions for the following ebuild phases:
531# src_prepare, src_configure, src_compile, src_test, src_install. 572# src_prepare, src_configure, src_compile, src_test, src_install.
532if ! has "${EAPI:-0}" 0 1; then 573if ! has "${EAPI:-0}" 0 1; then
533 python_src_prepare() { 574 python_src_prepare() {
575 _python_check_python_pkg_setup_execution
576
534 if ! _python_package_supporting_installation_for_multiple_python_abis; then 577 if ! _python_package_supporting_installation_for_multiple_python_abis; then
535 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"
536 fi 579 fi
537 580
581 if [[ "$#" -ne 0 ]]; then
582 die "${FUNCNAME}() does not accept arguments"
583 fi
584
538 python_copy_sources 585 python_copy_sources
539 } 586 }
540 587
541 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
542 eval "python_${python_default_function}() { 589 eval "python_${python_default_function}() {
590 _python_check_python_pkg_setup_execution
591
543 if ! _python_package_supporting_installation_for_multiple_python_abis; then 592 if ! _python_package_supporting_installation_for_multiple_python_abis; then
544 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\"
545 fi 594 fi
546 595
547 python_execute_function -d -s -- \"\$@\" 596 python_execute_function -d -s -- \"\$@\"
554 fi 603 fi
555fi 604fi
556 605
557unset PYTHON_ABIS 606unset PYTHON_ABIS
558 607
559# @FUNCTION: validate_PYTHON_ABIS 608_python_calculate_PYTHON_ABIS() {
560# @DESCRIPTION:
561# Ensure that PYTHON_ABIS variable has valid value.
562# This function usually should not be directly called in ebuilds.
563validate_PYTHON_ABIS() {
564 if ! _python_package_supporting_installation_for_multiple_python_abis; then 609 if ! _python_package_supporting_installation_for_multiple_python_abis; then
565 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 610 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
566 fi 611 fi
567 612
568 _python_initial_sanity_checks 613 _python_initial_sanity_checks
686 fi 731 fi
687 732
688 _python_final_sanity_checks 733 _python_final_sanity_checks
689} 734}
690 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
691# @FUNCTION: python_execute_function 788# @FUNCTION: python_execute_function
692# @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]
693# @DESCRIPTION: 790# @DESCRIPTION:
694# 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
695# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 792# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
696python_execute_function() { 793python_execute_function() {
794 _python_check_python_pkg_setup_execution
795
697 if ! _python_package_supporting_installation_for_multiple_python_abis; then 796 if ! _python_package_supporting_installation_for_multiple_python_abis; then
698 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"
699 fi 798 fi
700 799
701 _python_set_color_variables 800 _python_set_color_variables
702 801
703 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=
704 803
705 while (($#)); do 804 while (($#)); do
706 case "$1" in 805 case "$1" in
707 --action-message) 806 --action-message)
708 action_message_template="$2" 807 action_message_template="$2"
795 fi 894 fi
796 function="python_default_function" 895 function="python_default_function"
797 fi 896 fi
798 897
799 # 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().
800 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 899 if _python_abi-specific_local_scope; then
801 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
802 die "${FUNCNAME}(): Invalid call stack" 900 die "${FUNCNAME}(): Invalid call stack"
803 fi 901 fi
804 done
805 902
806 if [[ "${quiet}" == "0" ]]; then 903 if [[ "${quiet}" == "0" ]]; then
807 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 904 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
808 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 905 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
809 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 906 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
815 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 912 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
816 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 913 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
817 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 914 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
818 fi 915 fi
819 916
820 validate_PYTHON_ABIS 917 _python_calculate_PYTHON_ABIS
821 if [[ "${final_ABI}" == "1" ]]; then 918 if [[ "${final_ABI}" == "1" ]]; then
822 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 919 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
823 else 920 else
824 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 921 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
825 fi 922 fi
826 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 923 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
924 _python_prepare_flags
925
827 if [[ "${quiet}" == "0" ]]; then 926 if [[ "${quiet}" == "0" ]]; then
828 if [[ -n "${action_message_template}" ]]; then 927 if [[ -n "${action_message_template}" ]]; then
829 action_message="$(eval echo -n "${action_message_template}")" 928 eval "action_message=\"${action_message_template}\""
830 else 929 else
831 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)..."
832 fi 931 fi
833 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 932 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
834 fi 933 fi
852 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 951 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
853 else 952 else
854 EPYTHON="$(PYTHON)" "${function}" "$@" 953 EPYTHON="$(PYTHON)" "${function}" "$@"
855 fi 954 fi
856 955
857 if [[ "$?" != "0" ]]; then 956 return_code="$?"
957
958 _python_restore_flags
959
960 if [[ "${return_code}" -ne 0 ]]; then
858 if [[ -n "${failure_message_template}" ]]; then 961 if [[ -n "${failure_message_template}" ]]; then
859 failure_message="$(eval echo -n "${failure_message_template}")" 962 eval "failure_message=\"${failure_message_template}\""
860 else 963 else
861 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"
862 fi 965 fi
863 966
864 if [[ "${nonfatal}" == "1" ]]; then 967 if [[ "${nonfatal}" == "1" ]]; then
865 if [[ "${quiet}" == "0" ]]; then 968 if [[ "${quiet}" == "0" ]]; then
866 ewarn "${_RED}${failure_message}${_NORMAL}" 969 ewarn "${failure_message}"
867 fi 970 fi
868 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
869 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 972 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
870 local enabled_PYTHON_ABIS= other_PYTHON_ABI 973 local enabled_PYTHON_ABIS= other_PYTHON_ABI
871 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 974 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
872 [[ "${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}"
873 done 976 done
874 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 977 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
875 fi 978 fi
876 if [[ "${quiet}" == "0" ]]; then 979 if [[ "${quiet}" == "0" ]]; then
877 ewarn "${_RED}${failure_message}${_NORMAL}" 980 ewarn "${failure_message}"
878 fi 981 fi
879 if [[ -z "${PYTHON_ABIS}" ]]; then 982 if [[ -z "${PYTHON_ABIS}" ]]; then
880 die "${function}() function failed with all enabled Python ABIs" 983 die "${function}() function failed with all enabled Python ABIs"
881 fi 984 fi
882 else 985 else
919# @FUNCTION: python_copy_sources 1022# @FUNCTION: python_copy_sources
920# @USAGE: <directory="${S}"> [directory] 1023# @USAGE: <directory="${S}"> [directory]
921# @DESCRIPTION: 1024# @DESCRIPTION:
922# 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.
923python_copy_sources() { 1026python_copy_sources() {
1027 _python_check_python_pkg_setup_execution
1028
924 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1029 if ! _python_package_supporting_installation_for_multiple_python_abis; then
925 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"
926 fi 1031 fi
927 1032
928 local dir dirs=() PYTHON_ABI 1033 local dir dirs=() PYTHON_ABI
934 dirs=("${S%/}") 1039 dirs=("${S%/}")
935 else 1040 else
936 dirs=("$@") 1041 dirs=("$@")
937 fi 1042 fi
938 1043
939 validate_PYTHON_ABIS 1044 _python_calculate_PYTHON_ABIS
940 for PYTHON_ABI in ${PYTHON_ABIS}; do 1045 for PYTHON_ABI in ${PYTHON_ABIS}; do
941 for dir in "${dirs[@]}"; do 1046 for dir in "${dirs[@]}"; do
942 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 1047 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
943 done 1048 done
944 done 1049 done
949# @DESCRIPTION: 1054# @DESCRIPTION:
950# Generate wrapper scripts. Existing files are overwritten only with --force option. 1055# Generate wrapper scripts. Existing files are overwritten only with --force option.
951# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1056# If --respect-EPYTHON option is specified, then generated wrapper scripts will
952# respect EPYTHON variable at run time. 1057# respect EPYTHON variable at run time.
953python_generate_wrapper_scripts() { 1058python_generate_wrapper_scripts() {
1059 _python_check_python_pkg_setup_execution
1060
954 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1061 if ! _python_package_supporting_installation_for_multiple_python_abis; then
955 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"
956 fi 1063 fi
957 1064
958 _python_initialize_prefix_variables 1065 _python_initialize_prefix_variables
986 1093
987 if [[ "$#" -eq 0 ]]; then 1094 if [[ "$#" -eq 0 ]]; then
988 die "${FUNCNAME}(): Missing arguments" 1095 die "${FUNCNAME}(): Missing arguments"
989 fi 1096 fi
990 1097
991 validate_PYTHON_ABIS 1098 _python_calculate_PYTHON_ABIS
992 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1099 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
993 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1100 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
994 python2_enabled="1" 1101 python2_enabled="1"
995 fi 1102 fi
996 done 1103 done
1152 1259
1153# ================================================================================================ 1260# ================================================================================================
1154# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1261# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1155# ================================================================================================ 1262# ================================================================================================
1156 1263
1264unset EPYTHON PYTHON_ABI
1265
1157# @FUNCTION: python_set_active_version 1266# @FUNCTION: python_set_active_version
1158# @USAGE: <CPython_ABI|2|3> 1267# @USAGE: <CPython_ABI|2|3>
1159# @DESCRIPTION: 1268# @DESCRIPTION:
1160# 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.
1161python_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
1162 if _python_package_supporting_installation_for_multiple_python_abis; then 1276 if _python_package_supporting_installation_for_multiple_python_abis; then
1163 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"
1164 fi 1278 fi
1165 1279
1166 if [[ -n "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
1167 die "${FUNCNAME}() should be called before python_pkg_setup()"
1168 fi
1169
1170 if [[ "$#" -ne 1 ]]; then 1280 if [[ "$#" -ne 1 ]]; then
1171 die "${FUNCNAME}() requires 1 argument" 1281 die "${FUNCNAME}() requires 1 argument"
1172 fi 1282 fi
1173 1283
1174 _python_initial_sanity_checks 1284 _python_initial_sanity_checks
1175 1285
1286 if [[ -z "${PYTHON_ABI}" ]]; then
1176 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1287 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1177 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1288 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
1178 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1289 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
1179 fi 1290 fi
1180 export EPYTHON="$(PYTHON "$1")" 1291 export EPYTHON="$(PYTHON "$1")"
1181 elif [[ "$1" == "2" ]]; then 1292 elif [[ "$1" == "2" ]]; then
1182 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1293 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1183 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1294 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1184 fi 1295 fi
1185 export EPYTHON="$(PYTHON -2)" 1296 export EPYTHON="$(PYTHON -2)"
1186 elif [[ "$1" == "3" ]]; then 1297 elif [[ "$1" == "3" ]]; then
1187 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1298 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1188 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1299 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1189 fi 1300 fi
1190 export EPYTHON="$(PYTHON -3)" 1301 export EPYTHON="$(PYTHON -3)"
1191 else 1302 else
1192 die "${FUNCNAME}(): Unrecognized argument '$1'" 1303 die "${FUNCNAME}(): Unrecognized argument '$1'"
1193 fi 1304 fi
1194 1305
1195 # 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,
1196 # so it does not need to be exported to subprocesses. 1307 # so it does not need to be exported to subprocesses.
1197 PYTHON_ABI="${EPYTHON#python}" 1308 PYTHON_ABI="${EPYTHON#python}"
1198 PYTHON_ABI="${PYTHON_ABI%%-*}" 1309 PYTHON_ABI="${PYTHON_ABI%%-*}"
1310 fi
1199 1311
1200 _python_final_sanity_checks 1312 _python_final_sanity_checks
1201 1313
1202 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1314 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1203 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1315 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1205 1317
1206# @FUNCTION: python_need_rebuild 1318# @FUNCTION: python_need_rebuild
1207# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1319# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1208# switching of active version of Python. 1320# switching of active version of Python.
1209python_need_rebuild() { 1321python_need_rebuild() {
1322 _python_check_python_pkg_setup_execution
1323
1210 if _python_package_supporting_installation_for_multiple_python_abis; then 1324 if _python_package_supporting_installation_for_multiple_python_abis; then
1211 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"
1212 fi 1330 fi
1213 1331
1214 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1332 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1215} 1333}
1216 1334
1250# 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
1251# filename of Python interpreter. 1369# filename of Python interpreter.
1252# 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.
1253# --ABI and --absolute-path options cannot be specified simultaneously. 1371# --ABI and --absolute-path options cannot be specified simultaneously.
1254PYTHON() { 1372PYTHON() {
1373 _python_check_python_pkg_setup_execution
1374
1255 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"
1256 1376
1257 while (($#)); do 1377 while (($#)); do
1258 case "$1" in 1378 case "$1" in
1259 -2) 1379 -2)
1284 esac 1404 esac
1285 shift 1405 shift
1286 done 1406 done
1287 1407
1288 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1408 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1289 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1409 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1290 fi 1410 fi
1291 1411
1292 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1412 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1293 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"
1294 fi 1414 fi
1296 if [[ "$#" -eq 0 ]]; then 1416 if [[ "$#" -eq 0 ]]; then
1297 if [[ "${final_ABI}" == "1" ]]; then 1417 if [[ "${final_ABI}" == "1" ]]; then
1298 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1418 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1299 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1419 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1300 fi 1420 fi
1301 validate_PYTHON_ABIS 1421 _python_calculate_PYTHON_ABIS
1302 PYTHON_ABI="${PYTHON_ABIS##* }" 1422 PYTHON_ABI="${PYTHON_ABIS##* }"
1303 elif [[ "${python2}" == "1" ]]; then 1423 elif [[ "${python2}" == "1" ]]; then
1304 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1424 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1305 if [[ -z "${PYTHON_ABI}" ]]; then 1425 if [[ -z "${PYTHON_ABI}" ]]; then
1306 die "${FUNCNAME}(): Active version of Python 2 not set" 1426 die "${FUNCNAME}(): Active version of Python 2 not set"
1312 if [[ -z "${PYTHON_ABI}" ]]; then 1432 if [[ -z "${PYTHON_ABI}" ]]; then
1313 die "${FUNCNAME}(): Active version of Python 3 not set" 1433 die "${FUNCNAME}(): Active version of Python 3 not set"
1314 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1434 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1315 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1435 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1316 fi 1436 fi
1317 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
1318 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1442 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1319 if [[ -z "${PYTHON_ABI}" ]]; then 1443 if [[ -z "${PYTHON_ABI}" ]]; then
1320 die "${FUNCNAME}(): Main active version of Python not set" 1444 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1321 fi 1445 fi
1322 elif [[ -z "${PYTHON_ABI}" ]]; then
1323 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1324 fi 1446 fi
1325 elif [[ "$#" -eq 1 ]]; then 1447 elif [[ "$#" -eq 1 ]]; then
1326 if [[ "${final_ABI}" == "1" ]]; then 1448 if [[ "${final_ABI}" == "1" ]]; then
1327 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"
1328 fi 1450 fi
1363# @USAGE: [-f|--final-ABI] 1485# @USAGE: [-f|--final-ABI]
1364# @DESCRIPTION: 1486# @DESCRIPTION:
1365# Print name of Python implementation. 1487# Print name of Python implementation.
1366# 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.
1367python_get_implementation() { 1489python_get_implementation() {
1490 _python_check_python_pkg_setup_execution
1491
1368 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1492 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1369 1493
1370 while (($#)); do 1494 while (($#)); do
1371 case "$1" in 1495 case "$1" in
1372 -f|--final-ABI) 1496 -f|--final-ABI)
1385 if [[ "${final_ABI}" == "1" ]]; then 1509 if [[ "${final_ABI}" == "1" ]]; then
1386 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1510 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1387 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"
1388 fi 1512 fi
1389 PYTHON_ABI="$(PYTHON -f --ABI)" 1513 PYTHON_ABI="$(PYTHON -f --ABI)"
1390 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
1391 PYTHON_ABI="$(PYTHON --ABI)" 1520 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1521 fi
1392 fi 1522 fi
1393 1523
1394 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1524 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1395} 1525}
1396 1526
1398# @USAGE: [-f|--final-ABI] 1528# @USAGE: [-f|--final-ABI]
1399# @DESCRIPTION: 1529# @DESCRIPTION:
1400# Print category, name and slot of package providing Python implementation. 1530# Print category, name and slot of package providing Python implementation.
1401# 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.
1402python_get_implementational_package() { 1532python_get_implementational_package() {
1533 _python_check_python_pkg_setup_execution
1534
1403 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1535 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1404 1536
1405 while (($#)); do 1537 while (($#)); do
1406 case "$1" in 1538 case "$1" in
1407 -f|--final-ABI) 1539 -f|--final-ABI)
1420 if [[ "${final_ABI}" == "1" ]]; then 1552 if [[ "${final_ABI}" == "1" ]]; then
1421 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1553 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1422 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"
1423 fi 1555 fi
1424 PYTHON_ABI="$(PYTHON -f --ABI)" 1556 PYTHON_ABI="$(PYTHON -f --ABI)"
1425 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
1426 PYTHON_ABI="$(PYTHON --ABI)" 1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi
1427 fi 1565 fi
1428 1566
1429 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1430 echo "dev-lang/python:${PYTHON_ABI}" 1568 echo "dev-lang/python:${PYTHON_ABI}"
1431 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1432 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1570 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1433 fi 1571 fi
1434} 1572}
1435 1573
1436# @FUNCTION: python_get_includedir 1574# @FUNCTION: python_get_includedir
1437# @USAGE: [-f|--final-ABI] 1575# @USAGE: [-b|--base-path] [-f|--final-ABI]
1438# @DESCRIPTION: 1576# @DESCRIPTION:
1439# 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.
1440# 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.
1441python_get_includedir() { 1580python_get_includedir() {
1581 _python_check_python_pkg_setup_execution
1582
1442 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1583 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1443 1584
1444 while (($#)); do 1585 while (($#)); do
1445 case "$1" in 1586 case "$1" in
1587 -b|--base-path)
1588 base_path="1"
1589 ;;
1446 -f|--final-ABI) 1590 -f|--final-ABI)
1447 final_ABI="1" 1591 final_ABI="1"
1448 ;; 1592 ;;
1449 -*) 1593 -*)
1450 die "${FUNCNAME}(): Unrecognized option '$1'" 1594 die "${FUNCNAME}(): Unrecognized option '$1'"
1453 die "${FUNCNAME}(): Invalid usage" 1597 die "${FUNCNAME}(): Invalid usage"
1454 ;; 1598 ;;
1455 esac 1599 esac
1456 shift 1600 shift
1457 done 1601 done
1602
1603 if [[ "${base_path}" == "0" ]]; then
1604 prefix="/"
1605 fi
1458 1606
1459 if [[ "${final_ABI}" == "1" ]]; then 1607 if [[ "${final_ABI}" == "1" ]]; then
1460 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1608 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1461 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"
1462 fi 1610 fi
1463 PYTHON_ABI="$(PYTHON -f --ABI)" 1611 PYTHON_ABI="$(PYTHON -f --ABI)"
1464 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
1465 PYTHON_ABI="$(PYTHON --ABI)" 1618 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1619 fi
1466 fi 1620 fi
1467 1621
1468 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1622 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1469 echo "/usr/include/python${PYTHON_ABI}" 1623 echo "${prefix}usr/include/python${PYTHON_ABI}"
1470 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1624 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1471 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1625 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1472 fi 1626 fi
1473} 1627}
1474 1628
1475# @FUNCTION: python_get_libdir 1629# @FUNCTION: python_get_libdir
1476# @USAGE: [-f|--final-ABI] 1630# @USAGE: [-b|--base-path] [-f|--final-ABI]
1477# @DESCRIPTION: 1631# @DESCRIPTION:
1478# 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.
1479# 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.
1480python_get_libdir() { 1635python_get_libdir() {
1636 _python_check_python_pkg_setup_execution
1637
1481 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1638 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1482 1639
1483 while (($#)); do 1640 while (($#)); do
1484 case "$1" in 1641 case "$1" in
1642 -b|--base-path)
1643 base_path="1"
1644 ;;
1485 -f|--final-ABI) 1645 -f|--final-ABI)
1486 final_ABI="1" 1646 final_ABI="1"
1487 ;; 1647 ;;
1488 -*) 1648 -*)
1489 die "${FUNCNAME}(): Unrecognized option '$1'" 1649 die "${FUNCNAME}(): Unrecognized option '$1'"
1492 die "${FUNCNAME}(): Invalid usage" 1652 die "${FUNCNAME}(): Invalid usage"
1493 ;; 1653 ;;
1494 esac 1654 esac
1495 shift 1655 shift
1496 done 1656 done
1657
1658 if [[ "${base_path}" == "0" ]]; then
1659 prefix="/"
1660 fi
1497 1661
1498 if [[ "${final_ABI}" == "1" ]]; then 1662 if [[ "${final_ABI}" == "1" ]]; then
1499 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1663 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1500 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"
1501 fi 1665 fi
1502 PYTHON_ABI="$(PYTHON -f --ABI)" 1666 PYTHON_ABI="$(PYTHON -f --ABI)"
1503 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
1504 PYTHON_ABI="$(PYTHON --ABI)" 1673 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1674 fi
1505 fi 1675 fi
1506 1676
1507 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1677 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1508 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1678 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1509 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1679 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1510 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1680 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1511 fi 1681 fi
1512} 1682}
1513 1683
1514# @FUNCTION: python_get_sitedir 1684# @FUNCTION: python_get_sitedir
1515# @USAGE: [-f|--final-ABI] 1685# @USAGE: [-b|--base-path] [-f|--final-ABI]
1516# @DESCRIPTION: 1686# @DESCRIPTION:
1517# 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.
1518# 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.
1519python_get_sitedir() { 1690python_get_sitedir() {
1520 local options=() 1691 _python_check_python_pkg_setup_execution
1692
1693 local final_ABI="0" options=()
1521 1694
1522 while (($#)); do 1695 while (($#)); do
1523 case "$1" in 1696 case "$1" in
1697 -b|--base-path)
1698 options+=("$1")
1699 ;;
1524 -f|--final-ABI) 1700 -f|--final-ABI)
1525 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1701 final_ABI="1"
1526 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1527 fi
1528 options+=("$1") 1702 options+=("$1")
1529 ;; 1703 ;;
1530 -*) 1704 -*)
1531 die "${FUNCNAME}(): Unrecognized option '$1'" 1705 die "${FUNCNAME}(): Unrecognized option '$1'"
1532 ;; 1706 ;;
1535 ;; 1709 ;;
1536 esac 1710 esac
1537 shift 1711 shift
1538 done 1712 done
1539 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
1540 echo "$(python_get_libdir "${options[@]}")/site-packages" 1724 echo "$(python_get_libdir "${options[@]}")/site-packages"
1541} 1725}
1542 1726
1543# @FUNCTION: python_get_library 1727# @FUNCTION: python_get_library
1544# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1728# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1545# @DESCRIPTION: 1729# @DESCRIPTION:
1546# 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.
1547# 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.
1548# 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.
1549python_get_library() { 1734python_get_library() {
1735 _python_check_python_pkg_setup_execution
1736
1550 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}"
1551 1738
1552 while (($#)); do 1739 while (($#)); do
1553 case "$1" in 1740 case "$1" in
1741 -b|--base-path)
1742 base_path="1"
1743 ;;
1554 -f|--final-ABI) 1744 -f|--final-ABI)
1555 final_ABI="1" 1745 final_ABI="1"
1556 ;; 1746 ;;
1557 -l|--linker-option) 1747 -l|--linker-option)
1558 linker_option="1" 1748 linker_option="1"
1564 die "${FUNCNAME}(): Invalid usage" 1754 die "${FUNCNAME}(): Invalid usage"
1565 ;; 1755 ;;
1566 esac 1756 esac
1567 shift 1757 shift
1568 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
1569 1767
1570 if [[ "${final_ABI}" == "1" ]]; then 1768 if [[ "${final_ABI}" == "1" ]]; then
1571 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1769 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1572 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"
1573 fi 1771 fi
1574 PYTHON_ABI="$(PYTHON -f --ABI)" 1772 PYTHON_ABI="$(PYTHON -f --ABI)"
1575 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
1576 PYTHON_ABI="$(PYTHON --ABI)" 1779 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1780 fi
1577 fi 1781 fi
1578 1782
1579 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1783 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1580 if [[ "${linker_option}" == "1" ]]; then 1784 if [[ "${linker_option}" == "1" ]]; then
1581 echo "-lpython${PYTHON_ABI}" 1785 echo "-lpython${PYTHON_ABI}"
1582 else 1786 else
1583 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1787 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1584 fi 1788 fi
1585 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1789 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1586 die "${FUNCNAME}(): Jython does not have shared library" 1790 die "${FUNCNAME}(): Jython does not have shared library"
1587 fi 1791 fi
1588} 1792}
1593# Print Python version. 1797# Print Python version.
1594# --full, --major, --minor and --micro options cannot be specified simultaneously. 1798# --full, --major, --minor and --micro options cannot be specified simultaneously.
1595# 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.
1596# 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.
1597python_get_version() { 1801python_get_version() {
1802 _python_check_python_pkg_setup_execution
1803
1598 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
1599 1805
1600 while (($#)); do 1806 while (($#)); do
1601 case "$1" in 1807 case "$1" in
1602 -f|--final-ABI) 1808 -f|--final-ABI)
1652 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1858 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1653 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"
1654 fi 1860 fi
1655 "$(PYTHON -f)" -c "${python_command}" 1861 "$(PYTHON -f)" -c "${python_command}"
1656 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
1657 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1866 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1658 fi 1867 fi
1659} 1868}
1660 1869
1661# ================================================================================================ 1870# ================================================================================================
1683# @DESCRIPTION: 1892# @DESCRIPTION:
1684# Execute nosetests for all enabled Python ABIs. 1893# Execute nosetests for all enabled Python ABIs.
1685# 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
1686# 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.
1687python_execute_nosetests() { 1896python_execute_nosetests() {
1897 _python_check_python_pkg_setup_execution
1688 _python_set_color_variables 1898 _python_set_color_variables
1689 1899
1690 local PYTHONPATH_template= separate_build_dirs= 1900 local PYTHONPATH_template= separate_build_dirs=
1691 1901
1692 while (($#)); do 1902 while (($#)); do
1711 esac 1921 esac
1712 shift 1922 shift
1713 done 1923 done
1714 1924
1715 python_test_function() { 1925 python_test_function() {
1716 local evaluated_PYTHONPATH= 1926 local evaluated_PYTHONPATH
1717 1927
1718 if [[ -n "${PYTHONPATH_template}" ]]; then
1719 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1928 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1720 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1721 unset evaluated_PYTHONPATH
1722 fi
1723 fi
1724 1929
1725 _python_test_hook pre 1930 _python_test_hook pre
1726 1931
1727 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1932 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1728 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1933 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1751# @DESCRIPTION: 1956# @DESCRIPTION:
1752# Execute py.test for all enabled Python ABIs. 1957# Execute py.test for all enabled Python ABIs.
1753# 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
1754# 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.
1755python_execute_py.test() { 1960python_execute_py.test() {
1961 _python_check_python_pkg_setup_execution
1756 _python_set_color_variables 1962 _python_set_color_variables
1757 1963
1758 local PYTHONPATH_template= separate_build_dirs= 1964 local PYTHONPATH_template= separate_build_dirs=
1759 1965
1760 while (($#)); do 1966 while (($#)); do
1779 esac 1985 esac
1780 shift 1986 shift
1781 done 1987 done
1782 1988
1783 python_test_function() { 1989 python_test_function() {
1784 local evaluated_PYTHONPATH= 1990 local evaluated_PYTHONPATH
1785 1991
1786 if [[ -n "${PYTHONPATH_template}" ]]; then
1787 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1992 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1788 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1789 unset evaluated_PYTHONPATH
1790 fi
1791 fi
1792 1993
1793 _python_test_hook pre 1994 _python_test_hook pre
1794 1995
1795 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1996 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1796 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}
1819# @DESCRIPTION: 2020# @DESCRIPTION:
1820# Execute trial for all enabled Python ABIs. 2021# Execute trial for all enabled Python ABIs.
1821# 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
1822# 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.
1823python_execute_trial() { 2024python_execute_trial() {
2025 _python_check_python_pkg_setup_execution
1824 _python_set_color_variables 2026 _python_set_color_variables
1825 2027
1826 local PYTHONPATH_template= separate_build_dirs= 2028 local PYTHONPATH_template= separate_build_dirs=
1827 2029
1828 while (($#)); do 2030 while (($#)); do
1847 esac 2049 esac
1848 shift 2050 shift
1849 done 2051 done
1850 2052
1851 python_test_function() { 2053 python_test_function() {
1852 local evaluated_PYTHONPATH= 2054 local evaluated_PYTHONPATH
1853 2055
1854 if [[ -n "${PYTHONPATH_template}" ]]; then
1855 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2056 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1856 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1857 unset evaluated_PYTHONPATH
1858 fi
1859 fi
1860 2057
1861 _python_test_hook pre 2058 _python_test_hook pre
1862 2059
1863 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2060 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1864 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}
1889# @FUNCTION: python_enable_pyc 2086# @FUNCTION: python_enable_pyc
1890# @DESCRIPTION: 2087# @DESCRIPTION:
1891# Tell Python to automatically recompile modules to .pyc/.pyo if the 2088# Tell Python to automatically recompile modules to .pyc/.pyo if the
1892# timestamps/version stamps have changed. 2089# timestamps/version stamps have changed.
1893python_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
1894 unset PYTHONDONTWRITEBYTECODE 2097 unset PYTHONDONTWRITEBYTECODE
1895} 2098}
1896 2099
1897# @FUNCTION: python_disable_pyc 2100# @FUNCTION: python_disable_pyc
1898# @DESCRIPTION: 2101# @DESCRIPTION:
1899# Tell Python not to automatically recompile modules to .pyc/.pyo 2102# Tell Python not to automatically recompile modules to .pyc/.pyo
1900# 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
1901# to protect sandbox. 2104# to protect sandbox.
1902python_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
1903 export PYTHONDONTWRITEBYTECODE="1" 2112 export PYTHONDONTWRITEBYTECODE="1"
1904} 2113}
1905 2114
1906_python_clean_compiled_modules() { 2115_python_clean_compiled_modules() {
1907 _python_initialize_prefix_variables 2116 _python_initialize_prefix_variables
1922 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) 2131 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1923 2132
1924 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2133 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1925 # Delete empty child directories. 2134 # Delete empty child directories.
1926 find "${path}" -type d | sort -r | while read -r dir; do 2135 find "${path}" -type d | sort -r | while read -r dir; do
1927 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" 2136 if rmdir "${dir}" 2> /dev/null; then
2137 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2138 fi
1928 done 2139 done
1929 fi 2140 fi
1930 elif [[ "${path}" == *.py ]]; then 2141 elif [[ "${path}" == *.py ]]; then
1931 base_module_name="${path##*/}" 2142 base_module_name="${path##*/}"
1932 base_module_name="${base_module_name%.py}" 2143 base_module_name="${base_module_name%.py}"
1943 dir="${compiled_file%/*}" 2154 dir="${compiled_file%/*}"
1944 dir="${dir##*/}" 2155 dir="${dir##*/}"
1945 if [[ "${compiled_file}" == *.py[co] ]]; then 2156 if [[ "${compiled_file}" == *.py[co] ]]; then
1946 if [[ "${dir}" == "__pycache__" ]]; then 2157 if [[ "${dir}" == "__pycache__" ]]; then
1947 base_module_name="${compiled_file##*/}" 2158 base_module_name="${compiled_file##*/}"
1948 base_module_name="${base_module_name%%.*py[co]}" 2159 base_module_name="${base_module_name%.*py[co]}"
2160 base_module_name="${base_module_name%.*}"
1949 py_file="${compiled_file%__pycache__/*}${base_module_name}.py" 2161 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
1950 else 2162 else
1951 py_file="${compiled_file%[co]}" 2163 py_file="${compiled_file%[co]}"
1952 fi 2164 fi
1953 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2165 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
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 # Respect EROOT and options passed to compileall.py.
2028 while (($#)); do 2244 while (($#)); do
2029 case "$1" in 2245 case "$1" in
2246 --allow-evaluated-non-sitedir-paths)
2247 allow_evaluated_non_sitedir_paths="1"
2248 ;;
2030 -l|-f|-q) 2249 -l|-f|-q)
2031 options+=("$1") 2250 options+=("$1")
2032 ;; 2251 ;;
2033 -d|-x) 2252 -d|-x)
2034 options+=("$1" "$2") 2253 options+=("$1" "$2")
2035 shift 2254 shift
2036 ;; 2255 ;;
2256 --)
2257 shift
2258 break
2259 ;;
2037 -*) 2260 -*)
2038 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2261 die "${FUNCNAME}(): Unrecognized option '$1'"
2039 ;; 2262 ;;
2040 *) 2263 *)
2041 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2042 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2043 elif [[ "$1" =~ ^/ ]]; then
2044 if _python_package_supporting_installation_for_multiple_python_abis; then
2045 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2046 fi
2047 if [[ -d "${root}$1" ]]; then
2048 other_dirs+=("${root}$1")
2049 elif [[ -f "${root}$1" ]]; then
2050 other_files+=("${root}$1")
2051 elif [[ -e "${root}$1" ]]; then
2052 ewarn "'${root}$1' is not a file or a directory!"
2053 else
2054 ewarn "'${root}$1' does not exist!"
2055 fi
2056 else
2057 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2058 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2059 site_packages_dirs+=("$1")
2060 break 2264 break
2061 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2062 site_packages_files+=("$1")
2063 break
2064 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2065 ewarn "'$1' is not a file or a directory!"
2066 else
2067 ewarn "'$1' does not exist!"
2068 fi
2069 done
2070 fi
2071 ;; 2265 ;;
2072 esac 2266 esac
2073 shift 2267 shift
2074 done 2268 done
2075 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
2274 if [[ "$#" -eq 0 ]]; then
2275 ewarn
2276 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2277 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2278 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2279 ewarn
2280 fi
2281
2282 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'"
2285 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2286 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2287 elif [[ "$1" =~ ^/ ]]; then
2288 if _python_package_supporting_installation_for_multiple_python_abis; then
2289 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2290 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2291 fi
2292 if [[ "$1" != *\$* ]]; then
2293 die "${FUNCNAME}(): '$1' has invalid syntax"
2294 fi
2295 if [[ "$1" == *.py ]]; then
2296 evaluated_files+=("$1")
2297 else
2298 evaluated_dirs+=("$1")
2299 fi
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
2308 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2309 fi
2310 fi
2311 else
2312 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2313 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2314 site_packages_dirs+=("$1")
2315 break
2316 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2317 site_packages_files+=("$1")
2318 break
2319 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2320 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2321 else
2322 eerror "${FUNCNAME}(): '$1' does not exist"
2323 fi
2324 done
2325 fi
2326 shift
2327 done
2328
2076 # Set additional options. 2329 # Set additional options.
2077 options+=("-q") 2330 options+=("-q")
2078 2331
2079 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2332 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2080 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2333 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2081 return_code="0" 2334 return_code="0"
2082 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)"
2083 if ((${#site_packages_dirs[@]})); then 2336 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2084 for dir in "${site_packages_dirs[@]}"; do 2337 for dir in "${site_packages_dirs[@]}"; do
2085 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2338 dirs+=("${root}$(python_get_sitedir)/${dir}")
2086 done 2339 done
2340 for dir in "${evaluated_dirs[@]}"; do
2341 eval "dirs+=(\"\${root}${dir}\")"
2342 done
2087 "$(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"
2088 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2344 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2089 "$(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"
2090 fi 2346 fi
2091 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" 2347 _python_clean_compiled_modules "${dirs[@]}"
2092 fi 2348 fi
2093 if ((${#site_packages_files[@]})); then 2349 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2094 for file in "${site_packages_files[@]}"; do 2350 for file in "${site_packages_files[@]}"; do
2095 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2351 files+=("${root}$(python_get_sitedir)/${file}")
2096 done 2352 done
2353 for file in "${evaluated_files[@]}"; do
2354 eval "files+=(\"\${root}${file}\")"
2355 done
2097 "$(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"
2098 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2357 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2099 "$(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"
2100 fi 2359 fi
2101 _python_clean_compiled_modules "${site_packages_absolute_files[@]}" 2360 _python_clean_compiled_modules "${files[@]}"
2102 fi 2361 fi
2103 eend "${return_code}" 2362 eend "${return_code}"
2104 fi 2363 fi
2105 unset site_packages_absolute_dirs site_packages_absolute_files 2364 unset dirs files
2106 done 2365 done
2107 2366
2108 if _python_package_supporting_installation_for_multiple_python_abis; then 2367 if _python_package_supporting_installation_for_multiple_python_abis; then
2109 # Restore previous value of PYTHON_ABI. 2368 # Restore previous value of PYTHON_ABI.
2110 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2369 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2117 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2376 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
2118 return_code="0" 2377 return_code="0"
2119 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2378 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
2120 if ((${#other_dirs[@]})); then 2379 if ((${#other_dirs[@]})); then
2121 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2380 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
2122 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2381 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2123 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2382 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2124 fi 2383 fi
2125 _python_clean_compiled_modules "${other_dirs[@]}" 2384 _python_clean_compiled_modules "${other_dirs[@]}"
2126 fi 2385 fi
2127 if ((${#other_files[@]})); then 2386 if ((${#other_files[@]})); then
2128 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2387 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2129 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2388 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2130 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2389 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2131 fi 2390 fi
2132 _python_clean_compiled_modules "${other_dirs[@]}" 2391 _python_clean_compiled_modules "${other_dirs[@]}"
2133 fi 2392 fi
2134 eend "${return_code}" 2393 eend "${return_code}"
2135 fi 2394 fi
2136 else 2395 else
2396 # Deprecated part of python_mod_optimize()
2397
2137 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2398 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2138 2399
2139 # strip trailing slash 2400 # strip trailing slash
2140 myroot="${EROOT%/}" 2401 myroot="${EROOT%/}"
2141 2402
2147 ;; 2408 ;;
2148 -d|-x) 2409 -d|-x)
2149 myopts+=("$1" "$2") 2410 myopts+=("$1" "$2")
2150 shift 2411 shift
2151 ;; 2412 ;;
2413 --)
2414 shift
2415 break
2416 ;;
2152 -*) 2417 -*)
2153 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2418 die "${FUNCNAME}(): Unrecognized option '$1'"
2154 ;; 2419 ;;
2155 *) 2420 *)
2156 if [[ -d "${myroot}/${1#/}" ]]; then 2421 break
2157 mydirs+=("${myroot}/${1#/}")
2158 elif [[ -f "${myroot}/${1#/}" ]]; then
2159 # Files are passed to python_mod_compile which is EROOT-aware
2160 myfiles+=("$1")
2161 elif [[ -e "${myroot}/${1#/}" ]]; then
2162 ewarn "${myroot}/${1#/} is not a file or directory!"
2163 else
2164 ewarn "${myroot}/${1#/} does not exist!"
2165 fi
2166 ;; 2422 ;;
2167 esac 2423 esac
2168 shift 2424 shift
2169 done 2425 done
2170 2426
2427 if [[ "$#" -eq 0 ]]; then
2428 ewarn
2429 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2430 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2431 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2432 ewarn
2433 fi
2434
2435 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'"
2438 elif [[ -d "${myroot}/${1#/}" ]]; then
2439 mydirs+=("${myroot}/${1#/}")
2440 elif [[ -f "${myroot}/${1#/}" ]]; then
2441 # Files are passed to python_mod_compile which is EROOT-aware
2442 myfiles+=("$1")
2443 elif [[ -e "${myroot}/${1#/}" ]]; then
2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2445 else
2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2447 fi
2448 shift
2449 done
2450
2171 # set additional opts 2451 # set additional opts
2172 myopts+=(-q) 2452 myopts+=(-q)
2173 2453
2174 PYTHON_ABI="$(PYTHON --ABI)" 2454 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2175 2455
2176 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2456 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
2177 if ((${#mydirs[@]})); then 2457 if ((${#mydirs[@]})); then
2178 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2458 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
2179 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2459 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2198# 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.)
2199# 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.
2200# 2480#
2201# This function can be used only in pkg_postrm() phase. 2481# This function can be used only in pkg_postrm() phase.
2202python_mod_cleanup() { 2482python_mod_cleanup() {
2483 _python_check_python_pkg_setup_execution
2203 _python_initialize_prefix_variables 2484 _python_initialize_prefix_variables
2204 2485
2205 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
2206 2487
2207 # Check if phase is pkg_postrm(). 2488 # Check if phase is pkg_postrm().
2208 [[ "${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"
2209 2490
2210 if _python_package_supporting_installation_for_multiple_python_abis; then 2491 if _python_package_supporting_installation_for_multiple_python_abis; then
2211 if [[ -z "${PYTHON_ABIS}" ]]; then 2492 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2212 die "${FUNCNAME}(): Environment not initialized" 2493 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2213 fi 2494 fi
2214 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2495 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2215 else 2496 else
2497 if has "${EAPI:-0}" 0 1 2 3; then
2216 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
2217 fi 2502 fi
2218 2503
2219 # Strip trailing slash from EROOT. 2504 # Strip trailing slash from EROOT.
2220 root="${EROOT%/}" 2505 root="${EROOT%/}"
2221 2506
2222 if (($#)); then 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
2529
2530 if [[ "$#" -gt 0 ]]; then
2223 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
2224 while (($#)); do 2532 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'"
2225 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
2226 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"
2227 elif [[ "$1" =~ ^/ ]]; then 2537 elif [[ "$1" =~ ^/ ]]; then
2228 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
2229 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")
2230 fi 2550 fi
2231 search_paths+=("${root}$1")
2232 else 2551 else
2233 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2234 search_paths+=("${root}$(python_get_sitedir)/$1") 2553 search_paths+=("${root}$(python_get_sitedir)/$1")
2235 done 2554 done
2236 fi 2555 fi
2237 shift 2556 shift
2238 done 2557 done
2239 else 2558 else
2559 # Deprecated part of python_mod_cleanup()
2560
2240 search_paths=("${@#/}") 2561 search_paths=("${@#/}")
2241 search_paths=("${search_paths[@]/#/${root}/}") 2562 search_paths=("${search_paths[@]/#/${root}/}")
2242 fi 2563 fi
2243 else 2564 else
2565 ewarn
2566 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
2567 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules."
2568 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2569 ewarn
2570
2244 for dir in "${root}"/usr/lib*; do 2571 for dir in "${root}"/usr/lib*; do
2245 if [[ -d "${dir}" && ! -L "${dir}" ]]; then 2572 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2246 for sitedir in "${dir}"/python*/site-packages; do 2573 for sitedir in "${dir}"/python*/site-packages; do
2247 if [[ -d "${sitedir}" ]]; then 2574 if [[ -d "${sitedir}" ]]; then
2248 search_paths+=("${sitedir}") 2575 search_paths+=("${sitedir}")
2262 2589
2263# ================================================================================================ 2590# ================================================================================================
2264# ===================================== DEPRECATED FUNCTIONS ===================================== 2591# ===================================== DEPRECATED FUNCTIONS =====================================
2265# ================================================================================================ 2592# ================================================================================================
2266 2593
2267# @FUNCTION: python_version 2594# Scheduled for deletion on 2011-01-01.
2268# @DESCRIPTION:
2269# Run without arguments and it will export the version of python
2270# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2271python_version() { 2595python_version() {
2272 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2273 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2274 die "${FUNCNAME}() cannot be used in this EAPI"
2275 fi
2276
2277 _python_set_color_variables
2278
2279 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2280 echo
2281 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2282 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2283 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2284 echo
2285
2286 einfo &> /dev/null
2287 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2288 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."
2289 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"
2290 einfo &> /dev/null
2291 fi
2292
2293 [[ -n "${PYVER}" ]] && return 0
2294 local tmpstr
2295 python="${python:-${EPREFIX}/usr/bin/python}"
2296 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2297 export PYVER_ALL="${tmpstr#Python }"
2298 export PYVER_MAJOR="${PYVER_ALL:0:1}"
2299 export PYVER_MINOR="${PYVER_ALL:2:1}"
2300 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2301 export PYVER_MICRO="${PYVER_ALL:4}"
2302 fi
2303 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2304} 2598}
2305 2599
2306# @FUNCTION: python_mod_exists 2600# Scheduled for deletion on 2011-01-01.
2307# @USAGE: <module>
2308# @DESCRIPTION:
2309# Run with the module name as an argument. It will check if a
2310# Python module is installed and loadable. It will return
2311# TRUE(0) if the module exists, and FALSE(1) if the module does
2312# not exist.
2313#
2314# Example:
2315# if python_mod_exists gtk; then
2316# echo "gtk support enabled"
2317# fi
2318python_mod_exists() { 2601python_mod_exists() {
2319 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2320 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2602 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2321 die "${FUNCNAME}() cannot be used in this EAPI" 2603 die "${FUNCNAME}() is banned"
2322 fi
2323
2324 _python_set_color_variables
2325
2326 echo
2327 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2328 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2329 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2330 echo
2331
2332 einfo &> /dev/null
2333 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2334 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2335 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2336 einfo &> /dev/null
2337
2338 if [[ "$#" -ne 1 ]]; then
2339 die "${FUNCNAME}() requires 1 argument"
2340 fi
2341 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2342} 2604}
2343 2605
2344# @FUNCTION: python_tkinter_exists 2606# Scheduled for deletion on 2011-01-01.
2345# @DESCRIPTION:
2346# Run without arguments, checks if Python was compiled with Tkinter
2347# support. If not, prints an error message and dies.
2348python_tkinter_exists() { 2607python_tkinter_exists() {
2349 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2350 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}()."
2351 die "${FUNCNAME}() cannot be used in this EAPI" 2609 die "${FUNCNAME}() is banned"
2352 fi
2353
2354 _python_set_color_variables
2355
2356 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2357 echo
2358 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2359 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2360 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2361 echo
2362
2363 einfo &> /dev/null
2364 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2365 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2366 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2367 einfo &> /dev/null
2368 fi
2369
2370 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2371if version_info[0] == 3:
2372 import tkinter
2373else:
2374 import Tkinter" &> /dev/null; then
2375 eerror "Python needs to be rebuilt with tkinter support enabled."
2376 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2377 eerror "dev-lang/python tk"
2378 die "Python installed without support for tkinter"
2379 fi
2380} 2610}
2381 2611
2382# @FUNCTION: python_mod_compile 2612# @FUNCTION: python_mod_compile
2383# @USAGE: <file> [more files ...] 2613# @USAGE: <file> [more files ...]
2384# @DESCRIPTION: 2614# @DESCRIPTION:
2393 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2623 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2394 die "${FUNCNAME}() cannot be used in this EAPI" 2624 die "${FUNCNAME}() cannot be used in this EAPI"
2395 fi 2625 fi
2396 2626
2397 _python_initialize_prefix_variables 2627 _python_initialize_prefix_variables
2628 _python_set_color_variables
2629
2630 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2631 ewarn
2632 ewarn "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01."
2633 ewarn "Use python_mod_optimize() instead of ${FUNCNAME}()."
2634 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2635 ewarn
2636 fi
2398 2637
2399 local f myroot myfiles=() 2638 local f myroot myfiles=()
2400 2639
2401 # Check if phase is pkg_postinst() 2640 # Check if phase is pkg_postinst()
2402 [[ "${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.97  
changed lines
  Added in v.1.103

  ViewVC Help
Powered by ViewVC 1.1.20