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

Diff of /eclass/python.eclass

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

Revision 1.103 Revision 1.115
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2011 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.103 2010/10/03 00:38:13 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.115 2011/07/04 11:27:29 djc 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
13 13
14if ! has "${EAPI:-0}" 0 1 2 3; then 14if ! has "${EAPI:-0}" 0 1 2 3; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) 19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.0 3.1 3.2 3.3)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
26
27_python_check_python_abi_matching() {
28 local pattern patterns patterns_list="0" PYTHON_ABI
29
30 while (($#)); do
31 case "$1" in
32 --patterns-list)
33 patterns_list="1"
34 ;;
35 --)
36 shift
37 break
38 ;;
39 -*)
40 die "${FUNCNAME}(): Unrecognized option '$1'"
41 ;;
42 *)
43 break
44 ;;
45 esac
46 shift
47 done
48
49 if [[ "$#" -ne 2 ]]; then
50 die "${FUNCNAME}() requires 2 arguments"
51 fi
52
53 PYTHON_ABI="$1"
54
55 if [[ "${patterns_list}" == "0" ]]; then
56 pattern="$2"
57
58 if [[ "${pattern}" == *"-cpython" ]]; then
59 [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]]
60 elif [[ "${pattern}" == *"-jython" ]]; then
61 [[ "${PYTHON_ABI}" == ${pattern} ]]
62 else
63 if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
64 [[ "${PYTHON_ABI}" == ${pattern} ]]
65 elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
66 [[ "${PYTHON_ABI%-jython}" == ${pattern} ]]
67 else
68 die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'"
69 fi
70 fi
71 else
72 patterns="${2// /$'\n'}"
73
74 while read pattern; do
75 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
76 return 0
77 fi
78 done <<< "${patterns}"
79
80 return 1
81 fi
82}
21 83
22# @ECLASS-VARIABLE: PYTHON_DEPEND 84# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 85# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 86# Specification of dependency on dev-lang/python.
25# Syntax: 87# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 89# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 90# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 91# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 92# maximal_version: <maximal_major_version.maximal_minor_version>
31 93
32_parse_PYTHON_DEPEND() { 94_python_parse_PYTHON_DEPEND() {
33 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups 95 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
34 96
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 97 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 98 version_components_groups="${PYTHON_DEPEND}"
37 99
60 fi 122 fi
61 fi 123 fi
62 124
63 if [[ "${major_version}" == "2" ]]; then 125 if [[ "${major_version}" == "2" ]]; then
64 python2="1" 126 python2="1"
65 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 127 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
66 python2_minimal_version="${minimal_version}" 128 python2_minimal_version="${minimal_version}"
67 python2_maximal_version="${maximal_version}" 129 python2_maximal_version="${maximal_version}"
68 elif [[ "${major_version}" == "3" ]]; then 130 elif [[ "${major_version}" == "3" ]]; then
69 python3="1" 131 python3="1"
70 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 132 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
71 python3_minimal_version="${minimal_version}" 133 python3_minimal_version="${minimal_version}"
72 python3_maximal_version="${maximal_version}" 134 python3_maximal_version="${maximal_version}"
73 else 135 else
74 python_all="1" 136 python_all="1"
75 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 137 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
76 python_minimal_version="${minimal_version}" 138 python_minimal_version="${minimal_version}"
77 python_maximal_version="${maximal_version}" 139 python_maximal_version="${maximal_version}"
78 fi 140 fi
79 141
80 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then 142 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
108 170
109 if [[ "${python_all}" == "1" ]]; then 171 if [[ "${python_all}" == "1" ]]; then
110 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then 172 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
111 _PYTHON_ATOMS+=("dev-lang/python") 173 _PYTHON_ATOMS+=("dev-lang/python")
112 else 174 else
113 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 175 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
114 python_minimal_version="${python_minimal_version:-${python_versions[0]}}" 176 python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
115 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 177 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
116 _append_accepted_versions_range 178 _append_accepted_versions_range
117 fi 179 fi
118 else 180 else
119 if [[ "${python3}" == "1" ]]; then 181 if [[ "${python3}" == "1" ]]; then
120 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then 182 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
121 _PYTHON_ATOMS+=("=dev-lang/python-3*") 183 _PYTHON_ATOMS+=("=dev-lang/python-3*")
122 else 184 else
123 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 185 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
124 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}" 186 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
125 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 187 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
126 _append_accepted_versions_range 188 _append_accepted_versions_range
127 fi 189 fi
128 fi 190 fi
129 if [[ "${python2}" == "1" ]]; then 191 if [[ "${python2}" == "1" ]]; then
130 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then 192 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
131 _PYTHON_ATOMS+=("=dev-lang/python-2*") 193 _PYTHON_ATOMS+=("=dev-lang/python-2*")
132 else 194 else
133 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 195 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
134 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}" 196 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
135 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 197 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
136 _append_accepted_versions_range 198 _append_accepted_versions_range
137 fi 199 fi
138 fi 200 fi
153} 215}
154 216
155DEPEND=">=app-admin/eselect-python-20091230" 217DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 218RDEPEND="${DEPEND}"
157 219
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 220if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 221 _python_parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
165 die "NEED_PYTHON variable cannot be used in this EAPI"
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
177 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
178 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
179 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
180else 222else
181 _PYTHON_ATOMS=("dev-lang/python") 223 _PYTHON_ATOMS=("dev-lang/python")
224fi
225unset -f _python_parse_PYTHON_DEPEND
226
227if [[ -n "${NEED_PYTHON}" ]]; then
228 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
229 die "NEED_PYTHON variable is banned"
182fi 230fi
183 231
184# @ECLASS-VARIABLE: PYTHON_USE_WITH 232# @ECLASS-VARIABLE: PYTHON_USE_WITH
185# @DESCRIPTION: 233# @DESCRIPTION:
186# Set this to a space separated list of USE flags the Python slot in use must be built with. 234# Set this to a space separated list of USE flags the Python slot in use must be built with.
347# @DESCRIPTION: 395# @DESCRIPTION:
348# Perform sanity checks and initialize environment. 396# Perform sanity checks and initialize environment.
349# 397#
350# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable 398# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
351# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. 399# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
352#
353# This function can be used only in pkg_setup() phase.
354python_pkg_setup() { 400python_pkg_setup() {
355 # Check if phase is pkg_setup(). 401 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
356 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 402 die "${FUNCNAME}() can be used only in pkg_setup() phase"
403 fi
357 404
358 if [[ "$#" -ne 0 ]]; then 405 if [[ "$#" -ne 0 ]]; then
359 die "${FUNCNAME}() does not accept arguments" 406 die "${FUNCNAME}() does not accept arguments"
360 fi 407 fi
408
409 export JYTHON_SYSTEM_CACHEDIR="1"
410 addwrite "${EPREFIX}/var/cache/jython"
361 411
362 if _python_package_supporting_installation_for_multiple_python_abis; then 412 if _python_package_supporting_installation_for_multiple_python_abis; then
363 _python_calculate_PYTHON_ABIS 413 _python_calculate_PYTHON_ABIS
364 export EPYTHON="$(PYTHON -f)" 414 export EPYTHON="$(PYTHON -f)"
365 else 415 else
408 fi 458 fi
409 459
410 PYTHON_PKG_SETUP_EXECUTED="1" 460 PYTHON_PKG_SETUP_EXECUTED="1"
411} 461}
412 462
413if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 463if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
414 EXPORT_FUNCTIONS pkg_setup 464 EXPORT_FUNCTIONS pkg_setup
415fi 465fi
416 466
467_PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|python)'
468
417# @FUNCTION: python_convert_shebangs 469# @FUNCTION: python_convert_shebangs
418# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 470# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories]
419# @DESCRIPTION: 471# @DESCRIPTION:
420# Convert shebangs in specified files. Directories can be specified only with --recursive option. 472# Convert shebangs in specified files. Directories can be specified only with --recursive option.
421python_convert_shebangs() { 473python_convert_shebangs() {
422 _python_check_python_pkg_setup_execution 474 _python_check_python_pkg_setup_execution
423 475
424 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 476 local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0"
425 477
426 while (($#)); do 478 while (($#)); do
427 case "$1" in 479 case "$1" in
428 -r|--recursive) 480 -r|--recursive)
429 recursive="1" 481 recursive="1"
452 die "${FUNCNAME}(): Missing Python version and files or directories" 504 die "${FUNCNAME}(): Missing Python version and files or directories"
453 elif [[ "$#" -eq 1 ]]; then 505 elif [[ "$#" -eq 1 ]]; then
454 die "${FUNCNAME}(): Missing files or directories" 506 die "${FUNCNAME}(): Missing files or directories"
455 fi 507 fi
456 508
457 python_version="$1" 509 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
510 python_interpreter="$(PYTHON "$1")"
511 else
512 python_interpreter="python$1"
513 fi
458 shift 514 shift
459 515
460 for argument in "$@"; do 516 for argument in "$@"; do
461 if [[ ! -e "${argument}" ]]; then 517 if [[ ! -e "${argument}" ]]; then
462 die "${FUNCNAME}(): '${argument}' does not exist" 518 die "${FUNCNAME}(): '${argument}' does not exist"
477 533
478 for file in "${files[@]}"; do 534 for file in "${files[@]}"; do
479 file="${file#./}" 535 file="${file#./}"
480 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 536 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
481 537
482 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 538 if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
483 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue 539 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
484 540
485 if [[ "${quiet}" == "0" ]]; then 541 if [[ "${quiet}" == "0" ]]; then
486 einfo "Converting shebang in '${file}'" 542 einfo "Converting shebang in '${file}'"
487 fi 543 fi
488 544
489 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 545 sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed"
490
491 # Delete potential whitespace after "#!".
492 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
493 fi 546 fi
494 done 547 done
495} 548}
496 549
497# @FUNCTION: python_clean_installation_image 550# @FUNCTION: python_clean_installation_image
498# @USAGE: [-q|--quiet] 551# @USAGE: [-q|--quiet]
499# @DESCRIPTION: 552# @DESCRIPTION:
500# Delete needless files in installation image. 553# Delete needless files in installation image.
554#
555# This function can be used only in src_install() phase.
501python_clean_installation_image() { 556python_clean_installation_image() {
557 if [[ "${EBUILD_PHASE}" != "install" ]]; then
558 die "${FUNCNAME}() can be used only in src_install() phase"
559 fi
560
502 _python_check_python_pkg_setup_execution 561 _python_check_python_pkg_setup_execution
503 _python_initialize_prefix_variables 562 _python_initialize_prefix_variables
504 563
505 local file files=() quiet="0" 564 local file files=() quiet="0"
506
507 # Check if phase is src_install().
508 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
509 565
510 while (($#)); do 566 while (($#)); do
511 case "$1" in 567 case "$1" in
512 -q|--quiet) 568 -q|--quiet)
513 quiet="1" 569 quiet="1"
567# multiple Python ABIs. 623# multiple Python ABIs.
568 624
569# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 625# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
570# @DESCRIPTION: 626# @DESCRIPTION:
571# Set this to export phase functions for the following ebuild phases: 627# Set this to export phase functions for the following ebuild phases:
572# src_prepare, src_configure, src_compile, src_test, src_install. 628# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
573if ! has "${EAPI:-0}" 0 1; then 629if ! has "${EAPI:-0}" 0 1; then
574 python_src_prepare() { 630 python_src_prepare() {
575 _python_check_python_pkg_setup_execution 631 if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
632 die "${FUNCNAME}() can be used only in src_prepare() phase"
633 fi
576 634
577 if ! _python_package_supporting_installation_for_multiple_python_abis; then 635 if ! _python_package_supporting_installation_for_multiple_python_abis; then
578 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 636 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
579 fi 637 fi
580 638
639 _python_check_python_pkg_setup_execution
640
581 if [[ "$#" -ne 0 ]]; then 641 if [[ "$#" -ne 0 ]]; then
582 die "${FUNCNAME}() does not accept arguments" 642 die "${FUNCNAME}() does not accept arguments"
583 fi 643 fi
584 644
585 python_copy_sources 645 python_copy_sources
586 } 646 }
587 647
588 for python_default_function in src_configure src_compile src_test src_install; do 648 for python_default_function in src_configure src_compile src_test; do
589 eval "python_${python_default_function}() { 649 eval "python_${python_default_function}() {
590 _python_check_python_pkg_setup_execution 650 if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
651 die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
652 fi
591 653
592 if ! _python_package_supporting_installation_for_multiple_python_abis; then 654 if ! _python_package_supporting_installation_for_multiple_python_abis; then
593 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 655 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
594 fi 656 fi
595 657
658 _python_check_python_pkg_setup_execution
659
596 python_execute_function -d -s -- \"\$@\" 660 python_execute_function -d -s -- \"\$@\"
597 }" 661 }"
598 done 662 done
599 unset python_default_function 663 unset python_default_function
600 664
665 python_src_install() {
666 if [[ "${EBUILD_PHASE}" != "install" ]]; then
667 die "${FUNCNAME}() can be used only in src_install() phase"
668 fi
669
670 if ! _python_package_supporting_installation_for_multiple_python_abis; then
671 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
672 fi
673
674 _python_check_python_pkg_setup_execution
675
676 if has "${EAPI:-0}" 0 1 2 3; then
677 python_execute_function -d -s -- "$@"
678 else
679 python_installation() {
680 emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
681 }
682 python_execute_function -s python_installation "$@"
683 unset python_installation
684
685 python_merge_intermediate_installation_images "${T}/images"
686 fi
687 }
688
601 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 689 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
602 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 690 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
603 fi 691 fi
604fi 692fi
605 693
694if has "${EAPI:-0}" 0 1 2 3 4; then
606unset PYTHON_ABIS 695 unset PYTHON_ABIS
696fi
607 697
608_python_calculate_PYTHON_ABIS() { 698_python_calculate_PYTHON_ABIS() {
609 if ! _python_package_supporting_installation_for_multiple_python_abis; then 699 if ! _python_package_supporting_installation_for_multiple_python_abis; then
610 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 700 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
611 fi 701 fi
612 702
613 _python_initial_sanity_checks 703 _python_initial_sanity_checks
614 704
615 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
616 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 705 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
617 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 706 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
618 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 707
708 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
619 709
620 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 710 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
621 local cpython_enabled="0" 711 local cpython_enabled="0"
622 712
623 if [[ -z "${USE_PYTHON}" ]]; then 713 if [[ -z "${USE_PYTHON}" ]]; then
624 die "USE_PYTHON variable is empty" 714 die "USE_PYTHON variable is empty"
625 fi 715 fi
626 716
627 for PYTHON_ABI in ${USE_PYTHON}; do 717 for PYTHON_ABI in ${USE_PYTHON}; do
628 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 718 if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
629 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 719 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
630 fi 720 fi
631 721
632 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 722 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
633 cpython_enabled="1" 723 cpython_enabled="1"
634 fi 724 fi
635 725
636 support_ABI="1" 726 support_ABI="1"
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 727 while read restricted_ABI; do
638 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 728 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
639 support_ABI="0" 729 support_ABI="0"
640 break 730 break
641 fi 731 fi
642 done 732 done <<< "${restricted_ABIs}"
643 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 733 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
644 done 734 done
645 735
646 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 736 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
647 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 737 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
649 739
650 if [[ "${cpython_enabled}" == "0" ]]; then 740 if [[ "${cpython_enabled}" == "0" ]]; then
651 die "USE_PYTHON variable does not enable any CPython ABI" 741 die "USE_PYTHON variable does not enable any CPython ABI"
652 fi 742 fi
653 else 743 else
654 local python_version python2_version= python3_version= support_python_major_version 744 local python_version python2_version python3_version support_python_major_version
655 745
656 if ! has_version "dev-lang/python"; then 746 if ! has_version "dev-lang/python"; then
657 die "${FUNCNAME}(): 'dev-lang/python' is not installed" 747 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
658 fi 748 fi
659 749
664 die "'${EPREFIX}/usr/bin/python2' is not valid symlink" 754 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
665 fi 755 fi
666 756
667 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 757 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
668 758
669 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 759 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
670 support_python_major_version="1" 760 support_python_major_version="1"
671 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 761 while read restricted_ABI; do
672 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 762 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
673 support_python_major_version="0" 763 support_python_major_version="0"
674 fi 764 fi
675 done 765 done <<< "${restricted_ABIs}"
676 [[ "${support_python_major_version}" == "1" ]] && break 766 [[ "${support_python_major_version}" == "1" ]] && break
677 done 767 done
678 if [[ "${support_python_major_version}" == "1" ]]; then 768 if [[ "${support_python_major_version}" == "1" ]]; then
679 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 769 while read restricted_ABI; do
680 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 770 if _python_check_python_abi_matching "${python2_version}" "${restricted_ABI}"; then
681 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 771 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
682 fi 772 fi
683 done 773 done <<< "${restricted_ABIs}"
684 else 774 else
685 python2_version="" 775 python2_version=""
686 fi 776 fi
687 fi 777 fi
688 778
691 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 781 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
692 fi 782 fi
693 783
694 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 784 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
695 785
696 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 786 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
697 support_python_major_version="1" 787 support_python_major_version="1"
698 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 788 while read restricted_ABI; do
699 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 789 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
700 support_python_major_version="0" 790 support_python_major_version="0"
701 fi 791 fi
702 done 792 done <<< "${restricted_ABIs}"
703 [[ "${support_python_major_version}" == "1" ]] && break 793 [[ "${support_python_major_version}" == "1" ]] && break
704 done 794 done
705 if [[ "${support_python_major_version}" == "1" ]]; then 795 if [[ "${support_python_major_version}" == "1" ]]; then
706 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 796 while read restricted_ABI; do
707 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 797 if _python_check_python_abi_matching "${python3_version}" "${restricted_ABI}"; then
708 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 798 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
709 fi 799 fi
710 done 800 done <<< "${restricted_ABIs}"
711 else 801 else
712 python3_version="" 802 python3_version=""
713 fi 803 fi
714 fi 804 fi
715 805
745 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then 835 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
746 pattern="${element%% *}" 836 pattern="${element%% *}"
747 element="${element#* }" 837 element="${element#* }"
748 operator="${element%% *}" 838 operator="${element%% *}"
749 flags="${element#* }" 839 flags="${element#* }"
750 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then 840 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
751 if [[ "${operator}" == "+" ]]; then 841 if [[ "${operator}" == "+" ]]; then
752 eval "export ${variable}+=\"\${variable:+ }${flags}\"" 842 eval "export ${variable}+=\"\${variable:+ }${flags}\""
753 elif [[ "${operator}" == "-" ]]; then 843 elif [[ "${operator}" == "-" ]]; then
754 flags="${flags// /$'\n'}" 844 flags="${flags// /$'\n'}"
755 old_value="${!variable// /$'\n'}" 845 old_value="${!variable// /$'\n'}"
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] 879# @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]
790# @DESCRIPTION: 880# @DESCRIPTION:
791# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 881# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
792# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 882# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
793python_execute_function() { 883python_execute_function() {
794 _python_check_python_pkg_setup_execution
795
796 if ! _python_package_supporting_installation_for_multiple_python_abis; then 884 if ! _python_package_supporting_installation_for_multiple_python_abis; then
797 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 885 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
798 fi 886 fi
799 887
888 _python_check_python_pkg_setup_execution
800 _python_set_color_variables 889 _python_set_color_variables
801 890
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= 891 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
803 892
804 while (($#)); do 893 while (($#)); do
805 case "$1" in 894 case "$1" in
806 --action-message) 895 --action-message)
807 action_message_template="$2" 896 action_message_template="$2"
1022# @FUNCTION: python_copy_sources 1111# @FUNCTION: python_copy_sources
1023# @USAGE: <directory="${S}"> [directory] 1112# @USAGE: <directory="${S}"> [directory]
1024# @DESCRIPTION: 1113# @DESCRIPTION:
1025# Copy unpacked sources of current package to separate build directory for each Python ABI. 1114# Copy unpacked sources of current package to separate build directory for each Python ABI.
1026python_copy_sources() { 1115python_copy_sources() {
1027 _python_check_python_pkg_setup_execution
1028
1029 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1116 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1030 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1117 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1031 fi 1118 fi
1119
1120 _python_check_python_pkg_setup_execution
1032 1121
1033 local dir dirs=() PYTHON_ABI 1122 local dir dirs=() PYTHON_ABI
1034 1123
1035 if [[ "$#" -eq 0 ]]; then 1124 if [[ "$#" -eq 0 ]]; then
1036 if [[ "${WORKDIR}" == "${S}" ]]; then 1125 if [[ "${WORKDIR}" == "${S}" ]]; then
1053# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1142# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1054# @DESCRIPTION: 1143# @DESCRIPTION:
1055# Generate wrapper scripts. Existing files are overwritten only with --force option. 1144# Generate wrapper scripts. Existing files are overwritten only with --force option.
1056# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1145# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1057# respect EPYTHON variable at run time. 1146# respect EPYTHON variable at run time.
1147#
1148# This function can be used only in src_install() phase.
1058python_generate_wrapper_scripts() { 1149python_generate_wrapper_scripts() {
1059 _python_check_python_pkg_setup_execution 1150 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1151 die "${FUNCNAME}() can be used only in src_install() phase"
1152 fi
1060 1153
1061 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1154 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1062 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1155 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1063 fi 1156 fi
1064 1157
1158 _python_check_python_pkg_setup_execution
1065 _python_initialize_prefix_variables 1159 _python_initialize_prefix_variables
1066 1160
1067 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 1161 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1068 1162
1069 while (($#)); do 1163 while (($#)); do
1070 case "$1" in 1164 case "$1" in
1071 -E|--respect-EPYTHON) 1165 -E|--respect-EPYTHON)
1072 respect_EPYTHON="1" 1166 respect_EPYTHON="1"
1094 if [[ "$#" -eq 0 ]]; then 1188 if [[ "$#" -eq 0 ]]; then
1095 die "${FUNCNAME}(): Missing arguments" 1189 die "${FUNCNAME}(): Missing arguments"
1096 fi 1190 fi
1097 1191
1098 _python_calculate_PYTHON_ABIS 1192 _python_calculate_PYTHON_ABIS
1099 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1193 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1100 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1194 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1101 python2_enabled="1" 1195 python2_enabled="1"
1102 fi 1196 fi
1103 done 1197 done
1104 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 1198 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1105 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1199 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1106 python3_enabled="1" 1200 python3_enabled="1"
1107 fi 1201 fi
1108 done 1202 done
1109 1203
1115 eselect_python_option="--python3" 1209 eselect_python_option="--python3"
1116 else 1210 else
1117 die "${FUNCNAME}(): Unsupported environment" 1211 die "${FUNCNAME}(): Unsupported environment"
1118 fi 1212 fi
1119 1213
1214 PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")"
1215
1120 for file in "$@"; do 1216 for file in "$@"; do
1121 if [[ -f "${file}" && "${force}" == "0" ]]; then 1217 if [[ -f "${file}" && "${force}" == "0" ]]; then
1122 die "${FUNCNAME}(): '$1' already exists" 1218 die "${FUNCNAME}(): '${file}' already exists"
1123 fi 1219 fi
1124 1220
1125 if [[ "${quiet}" == "0" ]]; then 1221 if [[ "${quiet}" == "0" ]]; then
1126 einfo "Generating '${file#${ED%/}}' wrapper script" 1222 einfo "Generating '${file#${ED%/}}' wrapper script"
1127 fi 1223 fi
1133import os 1229import os
1134import re 1230import re
1135import subprocess 1231import subprocess
1136import sys 1232import sys
1137 1233
1138EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 1234cpython_re = re.compile(r"^python(\d+\.\d+)$")
1235jython_re = re.compile(r"^jython(\d+\.\d+)$")
1139python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") 1236python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
1140python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") 1237python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1238
1239def get_PYTHON_ABI(EPYTHON):
1240 cpython_matched = cpython_re.match(EPYTHON)
1241 jython_matched = jython_re.match(EPYTHON)
1242 if cpython_matched is not None:
1243 PYTHON_ABI = cpython_matched.group(1)
1244 elif jython_matched is not None:
1245 PYTHON_ABI = jython_matched.group(1) + "-jython"
1246 else:
1247 PYTHON_ABI = None
1248 return PYTHON_ABI
1141 1249
1142EOF 1250EOF
1143 if [[ "$?" != "0" ]]; then 1251 if [[ "$?" != "0" ]]; then
1144 die "${FUNCNAME}(): Generation of '$1' failed" 1252 die "${FUNCNAME}(): Generation of '$1' failed"
1145 fi 1253 fi
1146 if [[ "${respect_EPYTHON}" == "1" ]]; then 1254 if [[ "${respect_EPYTHON}" == "1" ]]; then
1147 cat << EOF >> "${file}" 1255 cat << EOF >> "${file}"
1148EPYTHON = os.environ.get("EPYTHON") 1256EPYTHON = os.environ.get("EPYTHON")
1149if EPYTHON: 1257if EPYTHON:
1150 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1258 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1151 if EPYTHON_matched: 1259 if PYTHON_ABI is None:
1152 PYTHON_ABI = EPYTHON_matched.group(1)
1153 else:
1154 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) 1260 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON)
1155 sys.exit(1) 1261 sys.exit(1)
1156else: 1262else:
1157 try: 1263 try:
1158 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1264 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
1166 if not isinstance(EPYTHON, str): 1272 if not isinstance(EPYTHON, str):
1167 # Python 3 1273 # Python 3
1168 EPYTHON = EPYTHON.decode() 1274 EPYTHON = EPYTHON.decode()
1169 EPYTHON = EPYTHON.rstrip("\n") 1275 EPYTHON = EPYTHON.rstrip("\n")
1170 1276
1171 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1277 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1172 if EPYTHON_matched: 1278 if PYTHON_ABI is None:
1173 PYTHON_ABI = EPYTHON_matched.group(1)
1174 else:
1175 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1279 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1176 sys.exit(1) 1280 sys.exit(1)
1281
1282wrapper_script_path = os.path.realpath(sys.argv[0])
1283target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1284if not os.path.exists(target_executable_path):
1285 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
1286 sys.exit(1)
1177EOF 1287EOF
1178 if [[ "$?" != "0" ]]; then 1288 if [[ "$?" != "0" ]]; then
1179 die "${FUNCNAME}(): Generation of '$1' failed" 1289 die "${FUNCNAME}(): Generation of '$1' failed"
1180 fi 1290 fi
1181 else 1291 else
1192if not isinstance(EPYTHON, str): 1302if not isinstance(EPYTHON, str):
1193 # Python 3 1303 # Python 3
1194 EPYTHON = EPYTHON.decode() 1304 EPYTHON = EPYTHON.decode()
1195EPYTHON = EPYTHON.rstrip("\n") 1305EPYTHON = EPYTHON.rstrip("\n")
1196 1306
1197EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1307PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1198if EPYTHON_matched: 1308if PYTHON_ABI is None:
1199 PYTHON_ABI = EPYTHON_matched.group(1) 1309 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1310 sys.exit(1)
1311
1312wrapper_script_path = os.path.realpath(sys.argv[0])
1313for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1314 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1315 if os.path.exists(target_executable_path):
1316 break
1200else: 1317else:
1201 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1318 sys.stderr.write("No target script exists for '%s'\n" % wrapper_script_path)
1202 sys.exit(1) 1319 sys.exit(1)
1203EOF 1320EOF
1204 if [[ "$?" != "0" ]]; then 1321 if [[ "$?" != "0" ]]; then
1205 die "${FUNCNAME}(): Generation of '$1' failed" 1322 die "${FUNCNAME}(): Generation of '$1' failed"
1206 fi 1323 fi
1207 fi 1324 fi
1208 cat << EOF >> "${file}" 1325 cat << EOF >> "${file}"
1209
1210wrapper_script_path = os.path.realpath(sys.argv[0])
1211target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1212os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1213os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1214os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1215if not os.path.exists(target_executable_path):
1216 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
1217 sys.exit(1)
1218 1326
1219target_executable = open(target_executable_path, "rb") 1327target_executable = open(target_executable_path, "rb")
1220target_executable_first_line = target_executable.readline() 1328target_executable_first_line = target_executable.readline()
1221if not isinstance(target_executable_first_line, str): 1329if not isinstance(target_executable_first_line, str):
1222 # Python 3 1330 # Python 3
1223 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1331 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1224 1332
1225python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1333python_shebang_matched = python_shebang_re.match(target_executable_first_line)
1226target_executable.close() 1334target_executable.close()
1227 1335
1228if python_shebang_matched: 1336if python_shebang_matched is not None:
1229 try: 1337 try:
1230 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1338 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1231 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1339 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1232 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1340 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1233 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1341 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1240 python_verification_output = python_verification_output.decode() 1348 python_verification_output = python_verification_output.decode()
1241 1349
1242 if not python_verification_output_re.match(python_verification_output): 1350 if not python_verification_output_re.match(python_verification_output):
1243 raise ValueError 1351 raise ValueError
1244 1352
1353 if cpython_re.match(EPYTHON) is not None:
1354 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1355 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1356 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1357
1358 if hasattr(os, "execv"):
1245 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1359 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
1360 else:
1361 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait())
1362 except (KeyboardInterrupt, SystemExit):
1363 raise
1246 except: 1364 except:
1247 pass 1365 pass
1248 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: 1366 for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
1249 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1367 if variable in os.environ:
1368 del os.environ[variable]
1250 1369
1370if hasattr(os, "execv"):
1251os.execv(target_executable_path, sys.argv) 1371 os.execv(target_executable_path, sys.argv)
1372else:
1373 sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
1252EOF 1374EOF
1253 if [[ "$?" != "0" ]]; then 1375 if [[ "$?" != "0" ]]; then
1254 die "${FUNCNAME}(): Generation of '$1' failed" 1376 die "${FUNCNAME}(): Generation of '$1' failed"
1255 fi 1377 fi
1256 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 1378 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
1257 done 1379 done
1258} 1380}
1259 1381
1382# @ECLASS-VARIABLE: PYTHON_VERSIONED_SCRIPTS
1383# @DESCRIPTION:
1384# Array of regular expressions of paths to versioned Python scripts.
1385# Python scripts in /usr/bin and /usr/sbin are versioned by default.
1386
1387# @ECLASS-VARIABLE: PYTHON_VERSIONED_EXECUTABLES
1388# @DESCRIPTION:
1389# Array of regular expressions of paths to versioned executables (including Python scripts).
1390
1391# @ECLASS-VARIABLE: PYTHON_NONVERSIONED_EXECUTABLES
1392# @DESCRIPTION:
1393# Array of regular expressions of paths to nonversioned executables (including Python scripts).
1394
1395# @FUNCTION: python_merge_intermediate_installation_images
1396# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
1397# @DESCRIPTION:
1398# Merge intermediate installation images into installation image.
1399#
1400# This function can be used only in src_install() phase.
1401python_merge_intermediate_installation_images() {
1402 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1403 die "${FUNCNAME}() can be used only in src_install() phase"
1404 fi
1405
1406 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1407 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1408 fi
1409
1410 _python_check_python_pkg_setup_execution
1411 _python_initialize_prefix_variables
1412
1413 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1414
1415 while (($#)); do
1416 case "$1" in
1417 -q|--quiet)
1418 quiet="1"
1419 ;;
1420 --)
1421 shift
1422 break
1423 ;;
1424 -*)
1425 die "${FUNCNAME}(): Unrecognized option '$1'"
1426 ;;
1427 *)
1428 break
1429 ;;
1430 esac
1431 shift
1432 done
1433
1434 if [[ "$#" -ne 1 ]]; then
1435 die "${FUNCNAME}() requires 1 argument"
1436 fi
1437
1438 intermediate_installation_images_directory="$1"
1439
1440 if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
1441 die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist"
1442 fi
1443
1444 _python_calculate_PYTHON_ABIS
1445 if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
1446 b="b"
1447 fi
1448
1449 while read -d $'\0' -r file; do
1450 files+=("${file}")
1451 done < <("$(PYTHON -f)" -c \
1452"import os
1453import sys
1454
1455if hasattr(sys.stdout, 'buffer'):
1456 # Python 3
1457 stdout = sys.stdout.buffer
1458else:
1459 # Python 2
1460 stdout = sys.stdout
1461
1462files_set = set()
1463
1464os.chdir(${b}'${intermediate_installation_images_directory}')
1465
1466for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
1467 for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
1468 root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
1469 files_set.update(root + ${b}'/' + file for file in files)
1470
1471for file in sorted(files_set):
1472 stdout.write(file)
1473 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images")
1474
1475 for PYTHON_ABI in ${PYTHON_ABIS}; do
1476 if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
1477 die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist"
1478 fi
1479
1480 pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed"
1481
1482 for file in "${files[@]}"; do
1483 version_executable="0"
1484 for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}"; do
1485 if [[ "/${file}" =~ ^${regex}$ ]]; then
1486 version_executable="1"
1487 break
1488 fi
1489 done
1490 for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}"; do
1491 if [[ "/${file}" =~ ^${regex}$ ]]; then
1492 version_executable="2"
1493 break
1494 fi
1495 done
1496 if [[ "${version_executable}" != "0" ]]; then
1497 for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}"; do
1498 if [[ "/${file}" =~ ^${regex}$ ]]; then
1499 version_executable="0"
1500 break
1501 fi
1502 done
1503 fi
1504
1505 [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue
1506
1507 shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed"
1508
1509 if [[ "${version_executable}" == "2" ]]; then
1510 wrapper_scripts+=("${ED}${file}")
1511 elif [[ "${version_executable}" == "1" ]]; then
1512 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
1513 wrapper_scripts+=("${ED}${file}")
1514 else
1515 version_executable="0"
1516 fi
1517 fi
1518
1519 [[ "${version_executable}" == "0" ]] && continue
1520
1521 if [[ -e "${file}-${PYTHON_ABI}" ]]; then
1522 die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists"
1523 fi
1524
1525 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
1526
1527 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
1528 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
1529 fi
1530 done
1531
1532 popd > /dev/null || die "popd failed"
1533
1534 if ROOT="/" has_version sys-apps/coreutils; then
1535 cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1536 else
1537 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1538 fi
1539 done
1540
1541 rm -fr "${intermediate_installation_images_directory}"
1542
1543 if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
1544 rm -f "${T}/python_wrapper_scripts"
1545
1546 for file in "${wrapper_scripts[@]}"; do
1547 echo -n "${file}" >> "${T}/python_wrapper_scripts"
1548 echo -en "\x00" >> "${T}/python_wrapper_scripts"
1549 done
1550
1551 while read -d $'\0' -r file; do
1552 wrapper_scripts_set+=("${file}")
1553 done < <("$(PYTHON -f)" -c \
1554"import sys
1555
1556if hasattr(sys.stdout, 'buffer'):
1557 # Python 3
1558 stdout = sys.stdout.buffer
1559else:
1560 # Python 2
1561 stdout = sys.stdout
1562
1563files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00'))
1564
1565for file in sorted(files):
1566 stdout.write(file)
1567 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1568
1569 python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}"
1570 fi
1571}
1572
1260# ================================================================================================ 1573# ================================================================================================
1261# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1574# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1262# ================================================================================================ 1575# ================================================================================================
1263 1576
1264unset EPYTHON PYTHON_ABI 1577unset EPYTHON PYTHON_ABI
1265 1578
1266# @FUNCTION: python_set_active_version 1579# @FUNCTION: python_set_active_version
1267# @USAGE: <CPython_ABI|2|3> 1580# @USAGE: <Python_ABI|2|3>
1268# @DESCRIPTION: 1581# @DESCRIPTION:
1269# Set specified version of CPython as active version of Python. 1582# Set locally active version of Python.
1583# If Python_ABI argument is specified, then version of Python corresponding to Python_ABI is used.
1584# If 2 argument is specified, then active version of CPython 2 is used.
1585# If 3 argument is specified, then active version of CPython 3 is used.
1270# 1586#
1271# This function can be used only in pkg_setup() phase. 1587# This function can be used only in pkg_setup() phase.
1272python_set_active_version() { 1588python_set_active_version() {
1273 # Check if phase is pkg_setup(). 1589 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1274 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 1590 die "${FUNCNAME}() can be used only in pkg_setup() phase"
1591 fi
1275 1592
1276 if _python_package_supporting_installation_for_multiple_python_abis; then 1593 if _python_package_supporting_installation_for_multiple_python_abis; then
1277 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1594 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1278 fi 1595 fi
1279 1596
1282 fi 1599 fi
1283 1600
1284 _python_initial_sanity_checks 1601 _python_initial_sanity_checks
1285 1602
1286 if [[ -z "${PYTHON_ABI}" ]]; then 1603 if [[ -z "${PYTHON_ABI}" ]]; then
1287 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1604 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
1288 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1605 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1289 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1606 # so it does not need to be exported to subprocesses.
1607 PYTHON_ABI="$1"
1608 if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
1609 die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed"
1290 fi 1610 fi
1291 export EPYTHON="$(PYTHON "$1")" 1611 export EPYTHON="$(PYTHON "$1")"
1292 elif [[ "$1" == "2" ]]; then 1612 elif [[ "$1" == "2" ]]; then
1293 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1613 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1294 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1614 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1295 fi 1615 fi
1296 export EPYTHON="$(PYTHON -2)" 1616 export EPYTHON="$(PYTHON -2)"
1617 PYTHON_ABI="${EPYTHON#python}"
1618 PYTHON_ABI="${PYTHON_ABI%%-*}"
1297 elif [[ "$1" == "3" ]]; then 1619 elif [[ "$1" == "3" ]]; then
1298 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1620 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1299 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1621 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1300 fi 1622 fi
1301 export EPYTHON="$(PYTHON -3)" 1623 export EPYTHON="$(PYTHON -3)"
1624 PYTHON_ABI="${EPYTHON#python}"
1625 PYTHON_ABI="${PYTHON_ABI%%-*}"
1302 else 1626 else
1303 die "${FUNCNAME}(): Unrecognized argument '$1'" 1627 die "${FUNCNAME}(): Unrecognized argument '$1'"
1304 fi 1628 fi
1305
1306 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1307 # so it does not need to be exported to subprocesses.
1308 PYTHON_ABI="${EPYTHON#python}"
1309 PYTHON_ABI="${PYTHON_ABI%%-*}"
1310 fi 1629 fi
1311 1630
1312 _python_final_sanity_checks 1631 _python_final_sanity_checks
1313 1632
1314 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1633 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1317 1636
1318# @FUNCTION: python_need_rebuild 1637# @FUNCTION: python_need_rebuild
1319# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1638# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1320# switching of active version of Python. 1639# switching of active version of Python.
1321python_need_rebuild() { 1640python_need_rebuild() {
1322 _python_check_python_pkg_setup_execution
1323
1324 if _python_package_supporting_installation_for_multiple_python_abis; then 1641 if _python_package_supporting_installation_for_multiple_python_abis; then
1325 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1642 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1326 fi 1643 fi
1644
1645 _python_check_python_pkg_setup_execution
1327 1646
1328 if [[ "$#" -ne 0 ]]; then 1647 if [[ "$#" -ne 0 ]]; then
1329 die "${FUNCNAME}() does not accept arguments" 1648 die "${FUNCNAME}() does not accept arguments"
1330 fi 1649 fi
1331 1650
1341sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) 1660sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
1342if platform.system()[:4] == "Java": 1661if platform.system()[:4] == "Java":
1343 sys.stdout.write("-jython")' 1662 sys.stdout.write("-jython")'
1344 1663
1345_python_get_implementation() { 1664_python_get_implementation() {
1665 local ignore_invalid="0"
1666
1667 while (($#)); do
1668 case "$1" in
1669 --ignore-invalid)
1670 ignore_invalid="1"
1671 ;;
1672 --)
1673 shift
1674 break
1675 ;;
1676 -*)
1677 die "${FUNCNAME}(): Unrecognized option '$1'"
1678 ;;
1679 *)
1680 break
1681 ;;
1682 esac
1683 shift
1684 done
1685
1346 if [[ "$#" -ne 1 ]]; then 1686 if [[ "$#" -ne 1 ]]; then
1347 die "${FUNCNAME}() requires 1 argument" 1687 die "${FUNCNAME}() requires 1 argument"
1348 fi 1688 fi
1349 1689
1350 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1690 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1351 echo "CPython" 1691 echo "CPython"
1352 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then 1692 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
1353 echo "Jython" 1693 echo "Jython"
1354 else 1694 else
1695 if [[ "${ignore_invalid}" == "0" ]]; then
1355 die "${FUNCNAME}(): Unrecognized Python ABI '$1'" 1696 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
1697 fi
1356 fi 1698 fi
1357} 1699}
1358 1700
1359# @FUNCTION: PYTHON 1701# @FUNCTION: PYTHON
1360# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 1702# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
1361# @DESCRIPTION: 1703# @DESCRIPTION:
1362# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument 1704# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument
1363# is ommitted, then PYTHON_ABI environment variable must be set and is used. 1705# is ommitted, then PYTHON_ABI environment variable must be set and is used.
1364# If -2 option is specified, then active version of Python 2 is used. 1706# If -2 option is specified, then active version of CPython 2 is used.
1365# If -3 option is specified, then active version of Python 3 is used. 1707# If -3 option is specified, then active version of CPython 3 is used.
1366# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1708# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1367# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously. 1709# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
1368# If --ABI option is specified, then only specified Python ABI is printed instead of 1710# If --ABI option is specified, then only specified Python ABI is printed instead of
1369# filename of Python interpreter. 1711# filename of Python interpreter.
1370# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1712# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1421 _python_calculate_PYTHON_ABIS 1763 _python_calculate_PYTHON_ABIS
1422 PYTHON_ABI="${PYTHON_ABIS##* }" 1764 PYTHON_ABI="${PYTHON_ABIS##* }"
1423 elif [[ "${python2}" == "1" ]]; then 1765 elif [[ "${python2}" == "1" ]]; then
1424 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1766 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1425 if [[ -z "${PYTHON_ABI}" ]]; then 1767 if [[ -z "${PYTHON_ABI}" ]]; then
1426 die "${FUNCNAME}(): Active version of Python 2 not set" 1768 die "${FUNCNAME}(): Active version of CPython 2 not set"
1427 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1769 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1428 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1770 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1429 fi 1771 fi
1430 elif [[ "${python3}" == "1" ]]; then 1772 elif [[ "${python3}" == "1" ]]; then
1431 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1773 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1432 if [[ -z "${PYTHON_ABI}" ]]; then 1774 if [[ -z "${PYTHON_ABI}" ]]; then
1433 die "${FUNCNAME}(): Active version of Python 3 not set" 1775 die "${FUNCNAME}(): Active version of CPython 3 not set"
1434 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1776 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1435 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1777 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1436 fi 1778 fi
1437 elif _python_package_supporting_installation_for_multiple_python_abis; then 1779 elif _python_package_supporting_installation_for_multiple_python_abis; then
1438 if ! _python_abi-specific_local_scope; then 1780 if ! _python_abi-specific_local_scope; then
1464 return 1806 return
1465 else 1807 else
1466 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1808 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1467 python_interpreter="python${PYTHON_ABI}" 1809 python_interpreter="python${PYTHON_ABI}"
1468 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1810 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1469 python_interpreter="jython-${PYTHON_ABI%-jython}" 1811 python_interpreter="jython${PYTHON_ABI%-jython}"
1470 fi 1812 fi
1471 1813
1472 if [[ "${absolute_path_output}" == "1" ]]; then 1814 if [[ "${absolute_path_output}" == "1" ]]; then
1473 echo -n "${EPREFIX}/usr/bin/${python_interpreter}" 1815 echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
1474 else 1816 else
1562 else 1904 else
1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 1905 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi 1906 fi
1565 fi 1907 fi
1566 1908
1909 if [[ "${EAPI:-0}" == "0" ]]; then
1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1910 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1568 echo "dev-lang/python:${PYTHON_ABI}" 1911 echo "=dev-lang/python-${PYTHON_ABI}*"
1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1912 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1913 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1914 fi
1915 else
1916 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1917 echo "dev-lang/python:${PYTHON_ABI}"
1918 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1570 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1919 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1920 fi
1571 fi 1921 fi
1572} 1922}
1573 1923
1574# @FUNCTION: python_get_includedir 1924# @FUNCTION: python_get_includedir
1575# @USAGE: [-b|--base-path] [-f|--final-ABI] 1925# @USAGE: [-b|--base-path] [-f|--final-ABI]
1895# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2245# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1896python_execute_nosetests() { 2246python_execute_nosetests() {
1897 _python_check_python_pkg_setup_execution 2247 _python_check_python_pkg_setup_execution
1898 _python_set_color_variables 2248 _python_set_color_variables
1899 2249
1900 local PYTHONPATH_template= separate_build_dirs= 2250 local PYTHONPATH_template separate_build_dirs
1901 2251
1902 while (($#)); do 2252 while (($#)); do
1903 case "$1" in 2253 case "$1" in
1904 -P|--PYTHONPATH) 2254 -P|--PYTHONPATH)
1905 PYTHONPATH_template="$2" 2255 PYTHONPATH_template="$2"
1959# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2309# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1960python_execute_py.test() { 2310python_execute_py.test() {
1961 _python_check_python_pkg_setup_execution 2311 _python_check_python_pkg_setup_execution
1962 _python_set_color_variables 2312 _python_set_color_variables
1963 2313
1964 local PYTHONPATH_template= separate_build_dirs= 2314 local PYTHONPATH_template separate_build_dirs
1965 2315
1966 while (($#)); do 2316 while (($#)); do
1967 case "$1" in 2317 case "$1" in
1968 -P|--PYTHONPATH) 2318 -P|--PYTHONPATH)
1969 PYTHONPATH_template="$2" 2319 PYTHONPATH_template="$2"
2023# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2373# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2024python_execute_trial() { 2374python_execute_trial() {
2025 _python_check_python_pkg_setup_execution 2375 _python_check_python_pkg_setup_execution
2026 _python_set_color_variables 2376 _python_set_color_variables
2027 2377
2028 local PYTHONPATH_template= separate_build_dirs= 2378 local PYTHONPATH_template separate_build_dirs
2029 2379
2030 while (($#)); do 2380 while (($#)); do
2031 case "$1" in 2381 case "$1" in
2032 -P|--PYTHONPATH) 2382 -P|--PYTHONPATH)
2033 PYTHONPATH_template="$2" 2383 PYTHONPATH_template="$2"
2114 2464
2115_python_clean_compiled_modules() { 2465_python_clean_compiled_modules() {
2116 _python_initialize_prefix_variables 2466 _python_initialize_prefix_variables
2117 _python_set_color_variables 2467 _python_set_color_variables
2118 2468
2119 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2469 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2120 2470
2121 local base_module_name compiled_file compiled_files=() dir path py_file root 2471 local base_module_name compiled_file compiled_files=() dir path py_file root
2122 2472
2123 # Strip trailing slash from EROOT. 2473 # Strip trailing slash from EROOT.
2124 root="${EROOT%/}" 2474 root="${EROOT%/}"
2173 if [[ "${dir}" == "__pycache__" ]]; then 2523 if [[ "${dir}" == "__pycache__" ]]; then
2174 base_module_name="${compiled_file##*/}" 2524 base_module_name="${compiled_file##*/}"
2175 base_module_name="${base_module_name%\$py.class}" 2525 base_module_name="${base_module_name%\$py.class}"
2176 py_file="${compiled_file%__pycache__/*}${base_module_name}.py" 2526 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2177 else 2527 else
2178 py_file="${compiled_file%\$py.class}" 2528 py_file="${compiled_file%\$py.class}.py"
2179 fi 2529 fi
2180 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2530 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2181 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2531 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2182 else 2532 else
2183 [[ -f "${py_file}" ]] && continue 2533 [[ -f "${py_file}" ]] && continue
2201 done 2551 done
2202 done 2552 done
2203} 2553}
2204 2554
2205# @FUNCTION: python_mod_optimize 2555# @FUNCTION: python_mod_optimize
2206# @USAGE: [options] [directory|file] 2556# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
2207# @DESCRIPTION: 2557# @DESCRIPTION:
2208# If no arguments supplied, it will recompile not recursively all modules 2558# Byte-compile specified Python modules.
2209# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
2210#
2211# If supplied with arguments, it will recompile all modules recursively
2212# in the supplied directory.
2213#
2214# Options passed to this function are passed to compileall.py. 2559# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2215# 2560#
2216# This function can be used only in pkg_postinst() phase. 2561# This function can be used only in pkg_postinst() phase.
2217python_mod_optimize() { 2562python_mod_optimize() {
2563 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
2564 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2565 fi
2566
2218 _python_check_python_pkg_setup_execution 2567 _python_check_python_pkg_setup_execution
2219 _python_initialize_prefix_variables 2568 _python_initialize_prefix_variables
2220 2569
2221 # Check if phase is pkg_postinst(). 2570 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2222 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2223
2224 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2225 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2571 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
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=() 2572 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=()
2227 2573
2228 if _python_package_supporting_installation_for_multiple_python_abis; then 2574 if _python_package_supporting_installation_for_multiple_python_abis; then
2229 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2575 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2270 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2616 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" 2617 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2272 fi 2618 fi
2273 2619
2274 if [[ "$#" -eq 0 ]]; then 2620 if [[ "$#" -eq 0 ]]; then
2275 ewarn 2621 die "${FUNCNAME}(): Missing files or directories"
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 2622 fi
2281 2623
2282 while (($#)); do 2624 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2625 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'" 2626 die "${FUNCNAME}(): Invalid argument '$1'"
2386 if ((${#other_files[@]})); then 2728 if ((${#other_files[@]})); then
2387 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2729 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2388 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2730 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2389 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2731 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2390 fi 2732 fi
2391 _python_clean_compiled_modules "${other_dirs[@]}" 2733 _python_clean_compiled_modules "${other_files[@]}"
2392 fi 2734 fi
2393 eend "${return_code}" 2735 eend "${return_code}"
2394 fi 2736 fi
2395 else 2737 else
2396 # Deprecated part of python_mod_optimize() 2738 # Deprecated part of python_mod_optimize()
2739 ewarn
2740 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2741 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2742 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2743 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2744 ewarn
2397 2745
2398 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2746 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2399 2747
2400 # strip trailing slash 2748 # strip trailing slash
2401 myroot="${EROOT%/}" 2749 myroot="${EROOT%/}"
2423 esac 2771 esac
2424 shift 2772 shift
2425 done 2773 done
2426 2774
2427 if [[ "$#" -eq 0 ]]; then 2775 if [[ "$#" -eq 0 ]]; then
2428 ewarn 2776 die "${FUNCNAME}(): Missing files or directories"
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 2777 fi
2434 2778
2435 while (($#)); do 2779 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2780 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'" 2781 die "${FUNCNAME}(): Invalid argument '$1'"
2438 elif [[ -d "${myroot}/${1#/}" ]]; then 2782 elif [[ -d "${myroot}/${1#/}" ]]; then
2439 mydirs+=("${myroot}/${1#/}") 2783 mydirs+=("${myroot}/${1#/}")
2440 elif [[ -f "${myroot}/${1#/}" ]]; then 2784 elif [[ -f "${myroot}/${1#/}" ]]; then
2441 # Files are passed to python_mod_compile which is EROOT-aware 2785 myfiles+=("${myroot}/${1#/}")
2442 myfiles+=("$1")
2443 elif [[ -e "${myroot}/${1#/}" ]]; then 2786 elif [[ -e "${myroot}/${1#/}" ]]; then
2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" 2787 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2445 else 2788 else
2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" 2789 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2447 fi 2790 fi
2459 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2802 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2460 _python_clean_compiled_modules "${mydirs[@]}" 2803 _python_clean_compiled_modules "${mydirs[@]}"
2461 fi 2804 fi
2462 2805
2463 if ((${#myfiles[@]})); then 2806 if ((${#myfiles[@]})); then
2807 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2808 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2464 python_mod_compile "${myfiles[@]}" 2809 _python_clean_compiled_modules "${myfiles[@]}"
2465 fi 2810 fi
2466 2811
2467 eend "${return_code}" 2812 eend "${return_code}"
2468 fi 2813 fi
2469} 2814}
2470 2815
2471# @FUNCTION: python_mod_cleanup 2816# @FUNCTION: python_mod_cleanup
2472# @USAGE: [directory|file] 2817# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2473# @DESCRIPTION: 2818# @DESCRIPTION:
2474# Run with optional arguments, where arguments are Python modules. If none given, 2819# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2475# it will look in /usr/lib/python[0-9].[0-9].
2476#
2477# It will recursively scan all compiled Python modules in the directories and
2478# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2479# If they are, then it will remove their corresponding .pyc and .pyo files.
2480# 2820#
2481# This function can be used only in pkg_postrm() phase. 2821# This function can be used only in pkg_postrm() phase.
2482python_mod_cleanup() { 2822python_mod_cleanup() {
2823 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
2824 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2825 fi
2826
2483 _python_check_python_pkg_setup_execution 2827 _python_check_python_pkg_setup_execution
2484 _python_initialize_prefix_variables 2828 _python_initialize_prefix_variables
2485 2829
2486 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2830 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2487
2488 # Check if phase is pkg_postrm().
2489 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2490 2831
2491 if _python_package_supporting_installation_for_multiple_python_abis; then 2832 if _python_package_supporting_installation_for_multiple_python_abis; then
2492 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2833 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2493 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2834 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2494 fi 2835 fi
2525 2866
2526 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2867 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" 2868 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2528 fi 2869 fi
2529 2870
2530 if [[ "$#" -gt 0 ]]; then 2871 if [[ "$#" -eq 0 ]]; then
2531 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2872 die "${FUNCNAME}(): Missing files or directories"
2873 fi
2874
2875 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2532 while (($#)); do 2876 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2877 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'" 2878 die "${FUNCNAME}(): Invalid argument '$1'"
2535 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2879 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2536 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2880 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2537 elif [[ "$1" =~ ^/ ]]; then 2881 elif [[ "$1" =~ ^/ ]]; then
2538 if _python_package_supporting_installation_for_multiple_python_abis; then 2882 if _python_package_supporting_installation_for_multiple_python_abis; then
2539 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then 2883 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2540 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2884 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")
2550 fi 2885 fi
2886 if [[ "$1" != *\$* ]]; then
2887 die "${FUNCNAME}(): '$1' has invalid syntax"
2888 fi
2889 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2890 eval "search_paths+=(\"\${root}$1\")"
2891 done
2551 else 2892 else
2893 search_paths+=("${root}$1")
2894 fi
2895 else
2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2896 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2553 search_paths+=("${root}$(python_get_sitedir)/$1") 2897 search_paths+=("${root}$(python_get_sitedir)/$1")
2554 done 2898 done
2555 fi 2899 fi
2556 shift 2900 shift
2557 done 2901 done
2558 else 2902 else
2559 # Deprecated part of python_mod_cleanup() 2903 # Deprecated part of python_mod_cleanup()
2560
2561 search_paths=("${@#/}")
2562 search_paths=("${search_paths[@]/#/${root}/}")
2563 fi
2564 else
2565 ewarn 2904 ewarn
2566 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" 2905 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2567 ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." 2906 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2907 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2568 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." 2908 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2569 ewarn 2909 ewarn
2570 2910
2571 for dir in "${root}"/usr/lib*; do
2572 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2573 for sitedir in "${dir}"/python*/site-packages; do
2574 if [[ -d "${sitedir}" ]]; then
2575 search_paths+=("${sitedir}")
2576 fi
2577 done
2578 fi
2579 done
2580 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do
2581 if [[ -d "${sitedir}" ]]; then
2582 search_paths+=("${sitedir}") 2911 search_paths=("${@#/}")
2583 fi 2912 search_paths=("${search_paths[@]/#/${root}/}")
2584 done
2585 fi 2913 fi
2586 2914
2587 _python_clean_compiled_modules "${search_paths[@]}" 2915 _python_clean_compiled_modules "${search_paths[@]}"
2588} 2916}
2589 2917
2590# ================================================================================================ 2918# ================================================================================================
2591# ===================================== DEPRECATED FUNCTIONS ===================================== 2919# ===================================== DEPRECATED FUNCTIONS =====================================
2592# ================================================================================================ 2920# ================================================================================================
2593
2594# Scheduled for deletion on 2011-01-01.
2595python_version() {
2596 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2597 die "${FUNCNAME}() is banned"
2598}
2599
2600# Scheduled for deletion on 2011-01-01.
2601python_mod_exists() {
2602 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2603 die "${FUNCNAME}() is banned"
2604}
2605
2606# Scheduled for deletion on 2011-01-01.
2607python_tkinter_exists() {
2608 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2609 die "${FUNCNAME}() is banned"
2610}
2611
2612# @FUNCTION: python_mod_compile
2613# @USAGE: <file> [more files ...]
2614# @DESCRIPTION:
2615# Given filenames, it will pre-compile the module's .pyc and .pyo.
2616# This function can be used only in pkg_postinst() phase.
2617#
2618# Example:
2619# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2620#
2621python_mod_compile() {
2622 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2623 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2624 die "${FUNCNAME}() cannot be used in this EAPI"
2625 fi
2626
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
2637
2638 local f myroot myfiles=()
2639
2640 # Check if phase is pkg_postinst()
2641 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2642
2643 # strip trailing slash
2644 myroot="${EROOT%/}"
2645
2646 # respect EROOT
2647 for f in "$@"; do
2648 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2649 done
2650
2651 PYTHON_ABI="$(PYTHON --ABI)"
2652
2653 if ((${#myfiles[@]})); then
2654 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2655 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2656 _python_clean_compiled_modules "${myfiles[@]}"
2657 else
2658 ewarn "No files to compile!"
2659 fi
2660}

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

  ViewVC Help
Powered by ViewVC 1.1.20