/[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.118
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.118 2011/07/08 07:37:49 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"
564# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 620# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
565# @DESCRIPTION: 621# @DESCRIPTION:
566# Set this in EAPI <= 4 to indicate that current package supports installation for 622# Set this in EAPI <= 4 to indicate that current package supports installation for
567# multiple Python ABIs. 623# multiple Python ABIs.
568 624
625# @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS
626# @DESCRIPTION:
627# Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI
628# patterns specified in this list is skipped.
629
569# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 630# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
570# @DESCRIPTION: 631# @DESCRIPTION:
571# Set this to export phase functions for the following ebuild phases: 632# Set this to export phase functions for the following ebuild phases:
572# src_prepare, src_configure, src_compile, src_test, src_install. 633# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
573if ! has "${EAPI:-0}" 0 1; then 634if ! has "${EAPI:-0}" 0 1; then
574 python_src_prepare() { 635 python_src_prepare() {
575 _python_check_python_pkg_setup_execution 636 if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
637 die "${FUNCNAME}() can be used only in src_prepare() phase"
638 fi
576 639
577 if ! _python_package_supporting_installation_for_multiple_python_abis; then 640 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" 641 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
579 fi 642 fi
580 643
644 _python_check_python_pkg_setup_execution
645
581 if [[ "$#" -ne 0 ]]; then 646 if [[ "$#" -ne 0 ]]; then
582 die "${FUNCNAME}() does not accept arguments" 647 die "${FUNCNAME}() does not accept arguments"
583 fi 648 fi
584 649
585 python_copy_sources 650 python_copy_sources
586 } 651 }
587 652
588 for python_default_function in src_configure src_compile src_test src_install; do 653 for python_default_function in src_configure src_compile src_test; do
589 eval "python_${python_default_function}() { 654 eval "python_${python_default_function}() {
590 _python_check_python_pkg_setup_execution 655 if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
656 die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
657 fi
591 658
592 if ! _python_package_supporting_installation_for_multiple_python_abis; then 659 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\" 660 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
594 fi 661 fi
595 662
663 _python_check_python_pkg_setup_execution
664
596 python_execute_function -d -s -- \"\$@\" 665 python_execute_function -d -s -- \"\$@\"
597 }" 666 }"
598 done 667 done
599 unset python_default_function 668 unset python_default_function
600 669
670 python_src_install() {
671 if [[ "${EBUILD_PHASE}" != "install" ]]; then
672 die "${FUNCNAME}() can be used only in src_install() phase"
673 fi
674
675 if ! _python_package_supporting_installation_for_multiple_python_abis; then
676 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
677 fi
678
679 _python_check_python_pkg_setup_execution
680
681 if has "${EAPI:-0}" 0 1 2 3; then
682 python_execute_function -d -s -- "$@"
683 else
684 python_installation() {
685 emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
686 }
687 python_execute_function -s python_installation "$@"
688 unset python_installation
689
690 python_merge_intermediate_installation_images "${T}/images"
691 fi
692 }
693
601 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 694 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
602 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 695 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
603 fi 696 fi
604fi 697fi
605 698
699if has "${EAPI:-0}" 0 1 2 3 4; then
606unset PYTHON_ABIS 700 unset PYTHON_ABIS
701fi
607 702
608_python_calculate_PYTHON_ABIS() { 703_python_calculate_PYTHON_ABIS() {
609 if ! _python_package_supporting_installation_for_multiple_python_abis; then 704 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" 705 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
611 fi 706 fi
612 707
613 _python_initial_sanity_checks 708 _python_initial_sanity_checks
614 709
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 710 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= 711 local PYTHON_ABI
618 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
619 712
620 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 713 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
621 local cpython_enabled="0" 714 local cpython_enabled="0"
622 715
623 if [[ -z "${USE_PYTHON}" ]]; then 716 if [[ -z "${USE_PYTHON}" ]]; then
624 die "USE_PYTHON variable is empty" 717 die "USE_PYTHON variable is empty"
625 fi 718 fi
626 719
627 for PYTHON_ABI in ${USE_PYTHON}; do 720 for PYTHON_ABI in ${USE_PYTHON}; do
628 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 721 if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
629 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 722 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
630 fi 723 fi
631 724
632 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 725 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
633 cpython_enabled="1" 726 cpython_enabled="1"
634 fi 727 fi
635 728
636 support_ABI="1" 729 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 730 export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
638 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 731 fi
639 support_ABI="0" 732 done
733
734 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
735 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
736 fi
737
738 if [[ "${cpython_enabled}" == "0" ]]; then
739 die "USE_PYTHON variable does not enable any CPython ABI"
740 fi
741 else
742 local python_version python2_version python3_version support_python_major_version
743
744 if ! has_version "dev-lang/python"; then
745 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
746 fi
747
748 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
749
750 if has_version "=dev-lang/python-2*"; then
751 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
752 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
753 fi
754
755 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
756
757 support_python_major_version="0"
758 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
759 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
760 support_python_major_version="1"
640 break 761 break
641 fi 762 fi
642 done 763 done
643 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
644 done
645
646 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
647 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
648 fi
649
650 if [[ "${cpython_enabled}" == "0" ]]; then
651 die "USE_PYTHON variable does not enable any CPython ABI"
652 fi
653 else
654 local python_version python2_version= python3_version= support_python_major_version
655
656 if ! has_version "dev-lang/python"; then
657 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
658 fi
659
660 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
661
662 if has_version "=dev-lang/python-2*"; then
663 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
664 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
665 fi
666
667 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
668
669 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
670 support_python_major_version="1"
671 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
672 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
673 support_python_major_version="0"
674 fi
675 done
676 [[ "${support_python_major_version}" == "1" ]] && break
677 done
678 if [[ "${support_python_major_version}" == "1" ]]; then 764 if [[ "${support_python_major_version}" == "1" ]]; then
679 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 765 if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
680 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
681 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 766 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
682 fi 767 fi
683 done
684 else 768 else
685 python2_version="" 769 python2_version=""
686 fi 770 fi
687 fi 771 fi
688 772
691 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 775 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
692 fi 776 fi
693 777
694 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 778 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
695 779
780 support_python_major_version="0"
696 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 781 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
782 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
697 support_python_major_version="1" 783 support_python_major_version="1"
698 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 784 break
699 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
700 support_python_major_version="0"
701 fi 785 fi
702 done
703 [[ "${support_python_major_version}" == "1" ]] && break
704 done 786 done
705 if [[ "${support_python_major_version}" == "1" ]]; then 787 if [[ "${support_python_major_version}" == "1" ]]; then
706 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 788 if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
707 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
708 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 789 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
709 fi 790 fi
710 done
711 else 791 else
712 python3_version="" 792 python3_version=""
713 fi 793 fi
714 fi 794 fi
715 795
745 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then 825 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
746 pattern="${element%% *}" 826 pattern="${element%% *}"
747 element="${element#* }" 827 element="${element#* }"
748 operator="${element%% *}" 828 operator="${element%% *}"
749 flags="${element#* }" 829 flags="${element#* }"
750 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then 830 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
751 if [[ "${operator}" == "+" ]]; then 831 if [[ "${operator}" == "+" ]]; then
752 eval "export ${variable}+=\"\${variable:+ }${flags}\"" 832 eval "export ${variable}+=\"\${variable:+ }${flags}\""
753 elif [[ "${operator}" == "-" ]]; then 833 elif [[ "${operator}" == "-" ]]; then
754 flags="${flags// /$'\n'}" 834 flags="${flags// /$'\n'}"
755 old_value="${!variable// /$'\n'}" 835 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] 869# @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: 870# @DESCRIPTION:
791# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 871# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
792# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 872# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
793python_execute_function() { 873python_execute_function() {
794 _python_check_python_pkg_setup_execution
795
796 if ! _python_package_supporting_installation_for_multiple_python_abis; then 874 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" 875 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
798 fi 876 fi
799 877
878 _python_check_python_pkg_setup_execution
800 _python_set_color_variables 879 _python_set_color_variables
801 880
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= 881 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 882
804 while (($#)); do 883 while (($#)); do
805 case "$1" in 884 case "$1" in
806 --action-message) 885 --action-message)
807 action_message_template="$2" 886 action_message_template="$2"
919 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 998 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
920 else 999 else
921 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 1000 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
922 fi 1001 fi
923 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1002 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1003 if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
1004 if [[ "${quiet}" == "0" ]]; then
1005 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version) skipped${_NORMAL}"
1006 fi
1007 continue
1008 fi
1009
924 _python_prepare_flags 1010 _python_prepare_flags
925 1011
926 if [[ "${quiet}" == "0" ]]; then 1012 if [[ "${quiet}" == "0" ]]; then
927 if [[ -n "${action_message_template}" ]]; then 1013 if [[ -n "${action_message_template}" ]]; then
928 eval "action_message=\"${action_message_template}\"" 1014 eval "action_message=\"${action_message_template}\""
1022# @FUNCTION: python_copy_sources 1108# @FUNCTION: python_copy_sources
1023# @USAGE: <directory="${S}"> [directory] 1109# @USAGE: <directory="${S}"> [directory]
1024# @DESCRIPTION: 1110# @DESCRIPTION:
1025# Copy unpacked sources of current package to separate build directory for each Python ABI. 1111# Copy unpacked sources of current package to separate build directory for each Python ABI.
1026python_copy_sources() { 1112python_copy_sources() {
1027 _python_check_python_pkg_setup_execution
1028
1029 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1113 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" 1114 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1031 fi 1115 fi
1116
1117 _python_check_python_pkg_setup_execution
1032 1118
1033 local dir dirs=() PYTHON_ABI 1119 local dir dirs=() PYTHON_ABI
1034 1120
1035 if [[ "$#" -eq 0 ]]; then 1121 if [[ "$#" -eq 0 ]]; then
1036 if [[ "${WORKDIR}" == "${S}" ]]; then 1122 if [[ "${WORKDIR}" == "${S}" ]]; then
1053# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1139# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1054# @DESCRIPTION: 1140# @DESCRIPTION:
1055# Generate wrapper scripts. Existing files are overwritten only with --force option. 1141# Generate wrapper scripts. Existing files are overwritten only with --force option.
1056# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1142# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1057# respect EPYTHON variable at run time. 1143# respect EPYTHON variable at run time.
1144#
1145# This function can be used only in src_install() phase.
1058python_generate_wrapper_scripts() { 1146python_generate_wrapper_scripts() {
1059 _python_check_python_pkg_setup_execution 1147 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1148 die "${FUNCNAME}() can be used only in src_install() phase"
1149 fi
1060 1150
1061 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1151 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" 1152 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1063 fi 1153 fi
1064 1154
1155 _python_check_python_pkg_setup_execution
1065 _python_initialize_prefix_variables 1156 _python_initialize_prefix_variables
1066 1157
1067 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 1158 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1068 1159
1069 while (($#)); do 1160 while (($#)); do
1070 case "$1" in 1161 case "$1" in
1071 -E|--respect-EPYTHON) 1162 -E|--respect-EPYTHON)
1072 respect_EPYTHON="1" 1163 respect_EPYTHON="1"
1094 if [[ "$#" -eq 0 ]]; then 1185 if [[ "$#" -eq 0 ]]; then
1095 die "${FUNCNAME}(): Missing arguments" 1186 die "${FUNCNAME}(): Missing arguments"
1096 fi 1187 fi
1097 1188
1098 _python_calculate_PYTHON_ABIS 1189 _python_calculate_PYTHON_ABIS
1099 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1190 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1100 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1191 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1101 python2_enabled="1" 1192 python2_enabled="1"
1102 fi 1193 fi
1103 done 1194 done
1104 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 1195 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1105 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1196 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1106 python3_enabled="1" 1197 python3_enabled="1"
1107 fi 1198 fi
1108 done 1199 done
1109 1200
1115 eselect_python_option="--python3" 1206 eselect_python_option="--python3"
1116 else 1207 else
1117 die "${FUNCNAME}(): Unsupported environment" 1208 die "${FUNCNAME}(): Unsupported environment"
1118 fi 1209 fi
1119 1210
1211 PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")"
1212
1120 for file in "$@"; do 1213 for file in "$@"; do
1121 if [[ -f "${file}" && "${force}" == "0" ]]; then 1214 if [[ -f "${file}" && "${force}" == "0" ]]; then
1122 die "${FUNCNAME}(): '$1' already exists" 1215 die "${FUNCNAME}(): '${file}' already exists"
1123 fi 1216 fi
1124 1217
1125 if [[ "${quiet}" == "0" ]]; then 1218 if [[ "${quiet}" == "0" ]]; then
1126 einfo "Generating '${file#${ED%/}}' wrapper script" 1219 einfo "Generating '${file#${ED%/}}' wrapper script"
1127 fi 1220 fi
1133import os 1226import os
1134import re 1227import re
1135import subprocess 1228import subprocess
1136import sys 1229import sys
1137 1230
1138EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 1231cpython_re = re.compile(r"^python(\d+\.\d+)$")
1232jython_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)") 1233python_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$") 1234python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1235
1236def get_PYTHON_ABI(EPYTHON):
1237 cpython_matched = cpython_re.match(EPYTHON)
1238 jython_matched = jython_re.match(EPYTHON)
1239 if cpython_matched is not None:
1240 PYTHON_ABI = cpython_matched.group(1)
1241 elif jython_matched is not None:
1242 PYTHON_ABI = jython_matched.group(1) + "-jython"
1243 else:
1244 PYTHON_ABI = None
1245 return PYTHON_ABI
1141 1246
1142EOF 1247EOF
1143 if [[ "$?" != "0" ]]; then 1248 if [[ "$?" != "0" ]]; then
1144 die "${FUNCNAME}(): Generation of '$1' failed" 1249 die "${FUNCNAME}(): Generation of '$1' failed"
1145 fi 1250 fi
1146 if [[ "${respect_EPYTHON}" == "1" ]]; then 1251 if [[ "${respect_EPYTHON}" == "1" ]]; then
1147 cat << EOF >> "${file}" 1252 cat << EOF >> "${file}"
1148EPYTHON = os.environ.get("EPYTHON") 1253EPYTHON = os.environ.get("EPYTHON")
1149if EPYTHON: 1254if EPYTHON:
1150 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1255 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1151 if EPYTHON_matched: 1256 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) 1257 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON)
1155 sys.exit(1) 1258 sys.exit(1)
1156else: 1259else:
1157 try: 1260 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) 1261 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): 1269 if not isinstance(EPYTHON, str):
1167 # Python 3 1270 # Python 3
1168 EPYTHON = EPYTHON.decode() 1271 EPYTHON = EPYTHON.decode()
1169 EPYTHON = EPYTHON.rstrip("\n") 1272 EPYTHON = EPYTHON.rstrip("\n")
1170 1273
1171 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1274 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1172 if EPYTHON_matched: 1275 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) 1276 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1176 sys.exit(1) 1277 sys.exit(1)
1278
1279wrapper_script_path = os.path.realpath(sys.argv[0])
1280target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1281if not os.path.exists(target_executable_path):
1282 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
1283 sys.exit(1)
1177EOF 1284EOF
1178 if [[ "$?" != "0" ]]; then 1285 if [[ "$?" != "0" ]]; then
1179 die "${FUNCNAME}(): Generation of '$1' failed" 1286 die "${FUNCNAME}(): Generation of '$1' failed"
1180 fi 1287 fi
1181 else 1288 else
1192if not isinstance(EPYTHON, str): 1299if not isinstance(EPYTHON, str):
1193 # Python 3 1300 # Python 3
1194 EPYTHON = EPYTHON.decode() 1301 EPYTHON = EPYTHON.decode()
1195EPYTHON = EPYTHON.rstrip("\n") 1302EPYTHON = EPYTHON.rstrip("\n")
1196 1303
1197EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1304PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1198if EPYTHON_matched: 1305if PYTHON_ABI is None:
1199 PYTHON_ABI = EPYTHON_matched.group(1) 1306 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1307 sys.exit(1)
1308
1309wrapper_script_path = os.path.realpath(sys.argv[0])
1310for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1311 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1312 if os.path.exists(target_executable_path):
1313 break
1200else: 1314else:
1201 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1315 sys.stderr.write("No target script exists for '%s'\n" % wrapper_script_path)
1202 sys.exit(1) 1316 sys.exit(1)
1203EOF 1317EOF
1204 if [[ "$?" != "0" ]]; then 1318 if [[ "$?" != "0" ]]; then
1205 die "${FUNCNAME}(): Generation of '$1' failed" 1319 die "${FUNCNAME}(): Generation of '$1' failed"
1206 fi 1320 fi
1207 fi 1321 fi
1208 cat << EOF >> "${file}" 1322 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 1323
1219target_executable = open(target_executable_path, "rb") 1324target_executable = open(target_executable_path, "rb")
1220target_executable_first_line = target_executable.readline() 1325target_executable_first_line = target_executable.readline()
1221if not isinstance(target_executable_first_line, str): 1326if not isinstance(target_executable_first_line, str):
1222 # Python 3 1327 # Python 3
1223 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1328 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1224 1329
1225python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1330python_shebang_matched = python_shebang_re.match(target_executable_first_line)
1226target_executable.close() 1331target_executable.close()
1227 1332
1228if python_shebang_matched: 1333if python_shebang_matched is not None:
1229 try: 1334 try:
1230 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1335 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1231 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1336 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1232 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1337 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1233 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1338 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1240 python_verification_output = python_verification_output.decode() 1345 python_verification_output = python_verification_output.decode()
1241 1346
1242 if not python_verification_output_re.match(python_verification_output): 1347 if not python_verification_output_re.match(python_verification_output):
1243 raise ValueError 1348 raise ValueError
1244 1349
1350 if cpython_re.match(EPYTHON) is not None:
1351 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1352 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1353 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1354
1355 if hasattr(os, "execv"):
1245 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1356 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
1357 else:
1358 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait())
1359 except (KeyboardInterrupt, SystemExit):
1360 raise
1246 except: 1361 except:
1247 pass 1362 pass
1248 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: 1363 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"] 1364 if variable in os.environ:
1365 del os.environ[variable]
1250 1366
1367if hasattr(os, "execv"):
1251os.execv(target_executable_path, sys.argv) 1368 os.execv(target_executable_path, sys.argv)
1369else:
1370 sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
1252EOF 1371EOF
1253 if [[ "$?" != "0" ]]; then 1372 if [[ "$?" != "0" ]]; then
1254 die "${FUNCNAME}(): Generation of '$1' failed" 1373 die "${FUNCNAME}(): Generation of '$1' failed"
1255 fi 1374 fi
1256 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 1375 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
1257 done 1376 done
1258} 1377}
1259 1378
1379# @ECLASS-VARIABLE: PYTHON_VERSIONED_SCRIPTS
1380# @DESCRIPTION:
1381# Array of regular expressions of paths to versioned Python scripts.
1382# Python scripts in /usr/bin and /usr/sbin are versioned by default.
1383
1384# @ECLASS-VARIABLE: PYTHON_VERSIONED_EXECUTABLES
1385# @DESCRIPTION:
1386# Array of regular expressions of paths to versioned executables (including Python scripts).
1387
1388# @ECLASS-VARIABLE: PYTHON_NONVERSIONED_EXECUTABLES
1389# @DESCRIPTION:
1390# Array of regular expressions of paths to nonversioned executables (including Python scripts).
1391
1392# @FUNCTION: python_merge_intermediate_installation_images
1393# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
1394# @DESCRIPTION:
1395# Merge intermediate installation images into installation image.
1396#
1397# This function can be used only in src_install() phase.
1398python_merge_intermediate_installation_images() {
1399 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1400 die "${FUNCNAME}() can be used only in src_install() phase"
1401 fi
1402
1403 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1404 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1405 fi
1406
1407 _python_check_python_pkg_setup_execution
1408 _python_initialize_prefix_variables
1409
1410 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1411
1412 while (($#)); do
1413 case "$1" in
1414 -q|--quiet)
1415 quiet="1"
1416 ;;
1417 --)
1418 shift
1419 break
1420 ;;
1421 -*)
1422 die "${FUNCNAME}(): Unrecognized option '$1'"
1423 ;;
1424 *)
1425 break
1426 ;;
1427 esac
1428 shift
1429 done
1430
1431 if [[ "$#" -ne 1 ]]; then
1432 die "${FUNCNAME}() requires 1 argument"
1433 fi
1434
1435 intermediate_installation_images_directory="$1"
1436
1437 if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
1438 die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist"
1439 fi
1440
1441 _python_calculate_PYTHON_ABIS
1442 if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
1443 b="b"
1444 fi
1445
1446 while read -d $'\0' -r file; do
1447 files+=("${file}")
1448 done < <("$(PYTHON -f)" -c \
1449"import os
1450import sys
1451
1452if hasattr(sys.stdout, 'buffer'):
1453 # Python 3
1454 stdout = sys.stdout.buffer
1455else:
1456 # Python 2
1457 stdout = sys.stdout
1458
1459files_set = set()
1460
1461os.chdir(${b}'${intermediate_installation_images_directory}')
1462
1463for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
1464 for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
1465 root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
1466 files_set.update(root + ${b}'/' + file for file in files)
1467
1468for file in sorted(files_set):
1469 stdout.write(file)
1470 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images")
1471
1472 for PYTHON_ABI in ${PYTHON_ABIS}; do
1473 if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
1474 die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist"
1475 fi
1476
1477 pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed"
1478
1479 for file in "${files[@]}"; do
1480 version_executable="0"
1481 for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}"; do
1482 if [[ "/${file}" =~ ^${regex}$ ]]; then
1483 version_executable="1"
1484 break
1485 fi
1486 done
1487 for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}"; do
1488 if [[ "/${file}" =~ ^${regex}$ ]]; then
1489 version_executable="2"
1490 break
1491 fi
1492 done
1493 if [[ "${version_executable}" != "0" ]]; then
1494 for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}"; do
1495 if [[ "/${file}" =~ ^${regex}$ ]]; then
1496 version_executable="0"
1497 break
1498 fi
1499 done
1500 fi
1501
1502 [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue
1503
1504 shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed"
1505
1506 if [[ "${version_executable}" == "2" ]]; then
1507 wrapper_scripts+=("${ED}${file}")
1508 elif [[ "${version_executable}" == "1" ]]; then
1509 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
1510 wrapper_scripts+=("${ED}${file}")
1511 else
1512 version_executable="0"
1513 fi
1514 fi
1515
1516 [[ "${version_executable}" == "0" ]] && continue
1517
1518 if [[ -e "${file}-${PYTHON_ABI}" ]]; then
1519 die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists"
1520 fi
1521
1522 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
1523
1524 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
1525 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
1526 fi
1527 done
1528
1529 popd > /dev/null || die "popd failed"
1530
1531 if ROOT="/" has_version sys-apps/coreutils; then
1532 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"
1533 else
1534 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1535 fi
1536 done
1537
1538 rm -fr "${intermediate_installation_images_directory}"
1539
1540 if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
1541 rm -f "${T}/python_wrapper_scripts"
1542
1543 for file in "${wrapper_scripts[@]}"; do
1544 echo -n "${file}" >> "${T}/python_wrapper_scripts"
1545 echo -en "\x00" >> "${T}/python_wrapper_scripts"
1546 done
1547
1548 while read -d $'\0' -r file; do
1549 wrapper_scripts_set+=("${file}")
1550 done < <("$(PYTHON -f)" -c \
1551"import sys
1552
1553if hasattr(sys.stdout, 'buffer'):
1554 # Python 3
1555 stdout = sys.stdout.buffer
1556else:
1557 # Python 2
1558 stdout = sys.stdout
1559
1560files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00'))
1561
1562for file in sorted(files):
1563 stdout.write(file)
1564 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1565
1566 python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}"
1567 fi
1568}
1569
1260# ================================================================================================ 1570# ================================================================================================
1261# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1571# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1262# ================================================================================================ 1572# ================================================================================================
1263 1573
1264unset EPYTHON PYTHON_ABI 1574unset EPYTHON PYTHON_ABI
1265 1575
1266# @FUNCTION: python_set_active_version 1576# @FUNCTION: python_set_active_version
1267# @USAGE: <CPython_ABI|2|3> 1577# @USAGE: <Python_ABI|2|3>
1268# @DESCRIPTION: 1578# @DESCRIPTION:
1269# Set specified version of CPython as active version of Python. 1579# Set locally active version of Python.
1580# If Python_ABI argument is specified, then version of Python corresponding to Python_ABI is used.
1581# If 2 argument is specified, then active version of CPython 2 is used.
1582# If 3 argument is specified, then active version of CPython 3 is used.
1270# 1583#
1271# This function can be used only in pkg_setup() phase. 1584# This function can be used only in pkg_setup() phase.
1272python_set_active_version() { 1585python_set_active_version() {
1273 # Check if phase is pkg_setup(). 1586 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1274 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 1587 die "${FUNCNAME}() can be used only in pkg_setup() phase"
1588 fi
1275 1589
1276 if _python_package_supporting_installation_for_multiple_python_abis; then 1590 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" 1591 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1278 fi 1592 fi
1279 1593
1282 fi 1596 fi
1283 1597
1284 _python_initial_sanity_checks 1598 _python_initial_sanity_checks
1285 1599
1286 if [[ -z "${PYTHON_ABI}" ]]; then 1600 if [[ -z "${PYTHON_ABI}" ]]; then
1287 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1601 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
1288 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1602 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1289 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1603 # so it does not need to be exported to subprocesses.
1604 PYTHON_ABI="$1"
1605 if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
1606 die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed"
1290 fi 1607 fi
1291 export EPYTHON="$(PYTHON "$1")" 1608 export EPYTHON="$(PYTHON "$1")"
1292 elif [[ "$1" == "2" ]]; then 1609 elif [[ "$1" == "2" ]]; then
1293 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1610 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1294 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1611 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1295 fi 1612 fi
1296 export EPYTHON="$(PYTHON -2)" 1613 export EPYTHON="$(PYTHON -2)"
1614 PYTHON_ABI="${EPYTHON#python}"
1615 PYTHON_ABI="${PYTHON_ABI%%-*}"
1297 elif [[ "$1" == "3" ]]; then 1616 elif [[ "$1" == "3" ]]; then
1298 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1617 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1299 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1618 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1300 fi 1619 fi
1301 export EPYTHON="$(PYTHON -3)" 1620 export EPYTHON="$(PYTHON -3)"
1621 PYTHON_ABI="${EPYTHON#python}"
1622 PYTHON_ABI="${PYTHON_ABI%%-*}"
1302 else 1623 else
1303 die "${FUNCNAME}(): Unrecognized argument '$1'" 1624 die "${FUNCNAME}(): Unrecognized argument '$1'"
1304 fi 1625 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 1626 fi
1311 1627
1312 _python_final_sanity_checks 1628 _python_final_sanity_checks
1313 1629
1314 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1630 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1317 1633
1318# @FUNCTION: python_need_rebuild 1634# @FUNCTION: python_need_rebuild
1319# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1635# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1320# switching of active version of Python. 1636# switching of active version of Python.
1321python_need_rebuild() { 1637python_need_rebuild() {
1322 _python_check_python_pkg_setup_execution
1323
1324 if _python_package_supporting_installation_for_multiple_python_abis; then 1638 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" 1639 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1326 fi 1640 fi
1641
1642 _python_check_python_pkg_setup_execution
1327 1643
1328 if [[ "$#" -ne 0 ]]; then 1644 if [[ "$#" -ne 0 ]]; then
1329 die "${FUNCNAME}() does not accept arguments" 1645 die "${FUNCNAME}() does not accept arguments"
1330 fi 1646 fi
1331 1647
1341sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) 1657sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
1342if platform.system()[:4] == "Java": 1658if platform.system()[:4] == "Java":
1343 sys.stdout.write("-jython")' 1659 sys.stdout.write("-jython")'
1344 1660
1345_python_get_implementation() { 1661_python_get_implementation() {
1662 local ignore_invalid="0"
1663
1664 while (($#)); do
1665 case "$1" in
1666 --ignore-invalid)
1667 ignore_invalid="1"
1668 ;;
1669 --)
1670 shift
1671 break
1672 ;;
1673 -*)
1674 die "${FUNCNAME}(): Unrecognized option '$1'"
1675 ;;
1676 *)
1677 break
1678 ;;
1679 esac
1680 shift
1681 done
1682
1346 if [[ "$#" -ne 1 ]]; then 1683 if [[ "$#" -ne 1 ]]; then
1347 die "${FUNCNAME}() requires 1 argument" 1684 die "${FUNCNAME}() requires 1 argument"
1348 fi 1685 fi
1349 1686
1350 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1687 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1351 echo "CPython" 1688 echo "CPython"
1352 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then 1689 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
1353 echo "Jython" 1690 echo "Jython"
1354 else 1691 else
1692 if [[ "${ignore_invalid}" == "0" ]]; then
1355 die "${FUNCNAME}(): Unrecognized Python ABI '$1'" 1693 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
1694 fi
1356 fi 1695 fi
1357} 1696}
1358 1697
1359# @FUNCTION: PYTHON 1698# @FUNCTION: PYTHON
1360# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 1699# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
1361# @DESCRIPTION: 1700# @DESCRIPTION:
1362# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument 1701# 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. 1702# 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. 1703# 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. 1704# 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. 1705# 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. 1706# -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 1707# If --ABI option is specified, then only specified Python ABI is printed instead of
1369# filename of Python interpreter. 1708# filename of Python interpreter.
1370# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1709# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1421 _python_calculate_PYTHON_ABIS 1760 _python_calculate_PYTHON_ABIS
1422 PYTHON_ABI="${PYTHON_ABIS##* }" 1761 PYTHON_ABI="${PYTHON_ABIS##* }"
1423 elif [[ "${python2}" == "1" ]]; then 1762 elif [[ "${python2}" == "1" ]]; then
1424 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1763 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1425 if [[ -z "${PYTHON_ABI}" ]]; then 1764 if [[ -z "${PYTHON_ABI}" ]]; then
1426 die "${FUNCNAME}(): Active version of Python 2 not set" 1765 die "${FUNCNAME}(): Active version of CPython 2 not set"
1427 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1766 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1428 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1767 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1429 fi 1768 fi
1430 elif [[ "${python3}" == "1" ]]; then 1769 elif [[ "${python3}" == "1" ]]; then
1431 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1770 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1432 if [[ -z "${PYTHON_ABI}" ]]; then 1771 if [[ -z "${PYTHON_ABI}" ]]; then
1433 die "${FUNCNAME}(): Active version of Python 3 not set" 1772 die "${FUNCNAME}(): Active version of CPython 3 not set"
1434 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1773 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1435 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1774 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1436 fi 1775 fi
1437 elif _python_package_supporting_installation_for_multiple_python_abis; then 1776 elif _python_package_supporting_installation_for_multiple_python_abis; then
1438 if ! _python_abi-specific_local_scope; then 1777 if ! _python_abi-specific_local_scope; then
1464 return 1803 return
1465 else 1804 else
1466 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1805 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1467 python_interpreter="python${PYTHON_ABI}" 1806 python_interpreter="python${PYTHON_ABI}"
1468 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1807 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1469 python_interpreter="jython-${PYTHON_ABI%-jython}" 1808 python_interpreter="jython${PYTHON_ABI%-jython}"
1470 fi 1809 fi
1471 1810
1472 if [[ "${absolute_path_output}" == "1" ]]; then 1811 if [[ "${absolute_path_output}" == "1" ]]; then
1473 echo -n "${EPREFIX}/usr/bin/${python_interpreter}" 1812 echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
1474 else 1813 else
1562 else 1901 else
1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 1902 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi 1903 fi
1565 fi 1904 fi
1566 1905
1906 if [[ "${EAPI:-0}" == "0" ]]; then
1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1907 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1568 echo "dev-lang/python:${PYTHON_ABI}" 1908 echo "=dev-lang/python-${PYTHON_ABI}*"
1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1909 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1910 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1911 fi
1912 else
1913 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1914 echo "dev-lang/python:${PYTHON_ABI}"
1915 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1570 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1916 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1917 fi
1571 fi 1918 fi
1572} 1919}
1573 1920
1574# @FUNCTION: python_get_includedir 1921# @FUNCTION: python_get_includedir
1575# @USAGE: [-b|--base-path] [-f|--final-ABI] 1922# @USAGE: [-b|--base-path] [-f|--final-ABI]
1790 die "${FUNCNAME}(): Jython does not have shared library" 2137 die "${FUNCNAME}(): Jython does not have shared library"
1791 fi 2138 fi
1792} 2139}
1793 2140
1794# @FUNCTION: python_get_version 2141# @FUNCTION: python_get_version
1795# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] 2142# @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro]
1796# @DESCRIPTION: 2143# @DESCRIPTION:
1797# Print Python version. 2144# Print Python version.
1798# --full, --major, --minor and --micro options cannot be specified simultaneously. 2145# --full, --major, --minor and --micro options cannot be specified simultaneously.
1799# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 2146# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
2147# If --language option is specified, then Python language version is printed.
2148# --language and --full options cannot be specified simultaneously.
2149# --language and --micro options cannot be specified simultaneously.
1800# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 2150# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1801python_get_version() { 2151python_get_version() {
1802 _python_check_python_pkg_setup_execution 2152 _python_check_python_pkg_setup_execution
1803 2153
1804 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 2154 local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command
1805 2155
1806 while (($#)); do 2156 while (($#)); do
1807 case "$1" in 2157 case "$1" in
1808 -f|--final-ABI) 2158 -f|--final-ABI)
1809 final_ABI="1" 2159 final_ABI="1"
1810 ;; 2160 ;;
2161 -l|--language)
2162 language="1"
2163 ;;
1811 --full) 2164 --full)
1812 full="1" 2165 full="1"
1813 ;; 2166 ;;
1814 --major) 2167 --major)
1815 major="1" 2168 major="1"
1827 die "${FUNCNAME}(): Invalid usage" 2180 die "${FUNCNAME}(): Invalid usage"
1828 ;; 2181 ;;
1829 esac 2182 esac
1830 shift 2183 shift
1831 done 2184 done
1832
1833 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
1834 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
1835 fi
1836
1837 if [[ "${full}" == "1" ]]; then
1838 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
1839 elif [[ "${major}" == "1" ]]; then
1840 python_command="from sys import version_info; print(version_info[0])"
1841 elif [[ "${minor}" == "1" ]]; then
1842 python_command="from sys import version_info; print(version_info[1])"
1843 elif [[ "${micro}" == "1" ]]; then
1844 python_command="from sys import version_info; print(version_info[2])"
1845 else
1846 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
1847 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1848 echo "${PYTHON_ABI}"
1849 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1850 echo "${PYTHON_ABI%-jython}"
1851 fi
1852 return
1853 fi
1854 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1855 fi
1856 2185
1857 if [[ "${final_ABI}" == "1" ]]; then 2186 if [[ "${final_ABI}" == "1" ]]; then
1858 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2187 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1859 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 2188 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1860 fi 2189 fi
1861 "$(PYTHON -f)" -c "${python_command}"
1862 else 2190 else
1863 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then 2191 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" 2192 die "${FUNCNAME}() should be used in ABI-specific local scope"
1865 fi 2193 fi
2194 fi
2195
2196 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2197 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2198 fi
2199
2200 if [[ "${language}" == "1" ]]; then
2201 if [[ "${final_ABI}" == "1" ]]; then
2202 PYTHON_ABI="$(PYTHON -f --ABI)"
2203 elif [[ -z "${PYTHON_ABI}" ]]; then
2204 PYTHON_ABI="$(PYTHON --ABI)"
2205 fi
2206 language_version="${PYTHON_ABI%%-*}"
2207 if [[ "${full}" == "1" ]]; then
2208 die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously"
2209 elif [[ "${major}" == "1" ]]; then
2210 echo "${language_version%.*}"
2211 elif [[ "${minor}" == "1" ]]; then
2212 echo "${language_version#*.}"
2213 elif [[ "${micro}" == "1" ]]; then
2214 die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously"
2215 else
2216 echo "${language_version}"
2217 fi
2218 else
2219 if [[ "${full}" == "1" ]]; then
2220 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
2221 elif [[ "${major}" == "1" ]]; then
2222 python_command="from sys import version_info; print(version_info[0])"
2223 elif [[ "${minor}" == "1" ]]; then
2224 python_command="from sys import version_info; print(version_info[1])"
2225 elif [[ "${micro}" == "1" ]]; then
2226 python_command="from sys import version_info; print(version_info[2])"
2227 else
2228 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2229 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2230 echo "${PYTHON_ABI}"
2231 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2232 echo "${PYTHON_ABI%-jython}"
2233 fi
2234 return
2235 fi
2236 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2237 fi
2238
2239 if [[ "${final_ABI}" == "1" ]]; then
2240 "$(PYTHON -f)" -c "${python_command}"
2241 else
1866 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2242 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
2243 fi
1867 fi 2244 fi
1868} 2245}
1869 2246
1870# ================================================================================================ 2247# ================================================================================================
1871# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 2248# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1895# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2272# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1896python_execute_nosetests() { 2273python_execute_nosetests() {
1897 _python_check_python_pkg_setup_execution 2274 _python_check_python_pkg_setup_execution
1898 _python_set_color_variables 2275 _python_set_color_variables
1899 2276
1900 local PYTHONPATH_template= separate_build_dirs= 2277 local PYTHONPATH_template separate_build_dirs
1901 2278
1902 while (($#)); do 2279 while (($#)); do
1903 case "$1" in 2280 case "$1" in
1904 -P|--PYTHONPATH) 2281 -P|--PYTHONPATH)
1905 PYTHONPATH_template="$2" 2282 PYTHONPATH_template="$2"
1959# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2336# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1960python_execute_py.test() { 2337python_execute_py.test() {
1961 _python_check_python_pkg_setup_execution 2338 _python_check_python_pkg_setup_execution
1962 _python_set_color_variables 2339 _python_set_color_variables
1963 2340
1964 local PYTHONPATH_template= separate_build_dirs= 2341 local PYTHONPATH_template separate_build_dirs
1965 2342
1966 while (($#)); do 2343 while (($#)); do
1967 case "$1" in 2344 case "$1" in
1968 -P|--PYTHONPATH) 2345 -P|--PYTHONPATH)
1969 PYTHONPATH_template="$2" 2346 PYTHONPATH_template="$2"
2023# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2400# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2024python_execute_trial() { 2401python_execute_trial() {
2025 _python_check_python_pkg_setup_execution 2402 _python_check_python_pkg_setup_execution
2026 _python_set_color_variables 2403 _python_set_color_variables
2027 2404
2028 local PYTHONPATH_template= separate_build_dirs= 2405 local PYTHONPATH_template separate_build_dirs
2029 2406
2030 while (($#)); do 2407 while (($#)); do
2031 case "$1" in 2408 case "$1" in
2032 -P|--PYTHONPATH) 2409 -P|--PYTHONPATH)
2033 PYTHONPATH_template="$2" 2410 PYTHONPATH_template="$2"
2114 2491
2115_python_clean_compiled_modules() { 2492_python_clean_compiled_modules() {
2116 _python_initialize_prefix_variables 2493 _python_initialize_prefix_variables
2117 _python_set_color_variables 2494 _python_set_color_variables
2118 2495
2119 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2496 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2120 2497
2121 local base_module_name compiled_file compiled_files=() dir path py_file root 2498 local base_module_name compiled_file compiled_files=() dir path py_file root
2122 2499
2123 # Strip trailing slash from EROOT. 2500 # Strip trailing slash from EROOT.
2124 root="${EROOT%/}" 2501 root="${EROOT%/}"
2173 if [[ "${dir}" == "__pycache__" ]]; then 2550 if [[ "${dir}" == "__pycache__" ]]; then
2174 base_module_name="${compiled_file##*/}" 2551 base_module_name="${compiled_file##*/}"
2175 base_module_name="${base_module_name%\$py.class}" 2552 base_module_name="${base_module_name%\$py.class}"
2176 py_file="${compiled_file%__pycache__/*}${base_module_name}.py" 2553 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2177 else 2554 else
2178 py_file="${compiled_file%\$py.class}" 2555 py_file="${compiled_file%\$py.class}.py"
2179 fi 2556 fi
2180 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2557 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2181 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2558 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2182 else 2559 else
2183 [[ -f "${py_file}" ]] && continue 2560 [[ -f "${py_file}" ]] && continue
2201 done 2578 done
2202 done 2579 done
2203} 2580}
2204 2581
2205# @FUNCTION: python_mod_optimize 2582# @FUNCTION: python_mod_optimize
2206# @USAGE: [options] [directory|file] 2583# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
2207# @DESCRIPTION: 2584# @DESCRIPTION:
2208# If no arguments supplied, it will recompile not recursively all modules 2585# 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. 2586# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2215# 2587#
2216# This function can be used only in pkg_postinst() phase. 2588# This function can be used only in pkg_postinst() phase.
2217python_mod_optimize() { 2589python_mod_optimize() {
2590 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
2591 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2592 fi
2593
2218 _python_check_python_pkg_setup_execution 2594 _python_check_python_pkg_setup_execution
2219 _python_initialize_prefix_variables 2595 _python_initialize_prefix_variables
2220 2596
2221 # Check if phase is pkg_postinst(). 2597 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. 2598 # 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=() 2599 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 2600
2228 if _python_package_supporting_installation_for_multiple_python_abis; then 2601 if _python_package_supporting_installation_for_multiple_python_abis; then
2229 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2602 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 2643 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" 2644 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2272 fi 2645 fi
2273 2646
2274 if [[ "$#" -eq 0 ]]; then 2647 if [[ "$#" -eq 0 ]]; then
2275 ewarn 2648 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 2649 fi
2281 2650
2282 while (($#)); do 2651 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2652 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'" 2653 die "${FUNCNAME}(): Invalid argument '$1'"
2386 if ((${#other_files[@]})); then 2755 if ((${#other_files[@]})); then
2387 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2756 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2388 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2757 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" 2758 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2390 fi 2759 fi
2391 _python_clean_compiled_modules "${other_dirs[@]}" 2760 _python_clean_compiled_modules "${other_files[@]}"
2392 fi 2761 fi
2393 eend "${return_code}" 2762 eend "${return_code}"
2394 fi 2763 fi
2395 else 2764 else
2396 # Deprecated part of python_mod_optimize() 2765 # Deprecated part of python_mod_optimize()
2766 ewarn
2767 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2768 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2769 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2770 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2771 ewarn
2397 2772
2398 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2773 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2399 2774
2400 # strip trailing slash 2775 # strip trailing slash
2401 myroot="${EROOT%/}" 2776 myroot="${EROOT%/}"
2423 esac 2798 esac
2424 shift 2799 shift
2425 done 2800 done
2426 2801
2427 if [[ "$#" -eq 0 ]]; then 2802 if [[ "$#" -eq 0 ]]; then
2428 ewarn 2803 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 2804 fi
2434 2805
2435 while (($#)); do 2806 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2807 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'" 2808 die "${FUNCNAME}(): Invalid argument '$1'"
2438 elif [[ -d "${myroot}/${1#/}" ]]; then 2809 elif [[ -d "${myroot}/${1#/}" ]]; then
2439 mydirs+=("${myroot}/${1#/}") 2810 mydirs+=("${myroot}/${1#/}")
2440 elif [[ -f "${myroot}/${1#/}" ]]; then 2811 elif [[ -f "${myroot}/${1#/}" ]]; then
2441 # Files are passed to python_mod_compile which is EROOT-aware 2812 myfiles+=("${myroot}/${1#/}")
2442 myfiles+=("$1")
2443 elif [[ -e "${myroot}/${1#/}" ]]; then 2813 elif [[ -e "${myroot}/${1#/}" ]]; then
2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" 2814 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2445 else 2815 else
2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" 2816 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2447 fi 2817 fi
2459 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2829 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2460 _python_clean_compiled_modules "${mydirs[@]}" 2830 _python_clean_compiled_modules "${mydirs[@]}"
2461 fi 2831 fi
2462 2832
2463 if ((${#myfiles[@]})); then 2833 if ((${#myfiles[@]})); then
2834 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2835 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2464 python_mod_compile "${myfiles[@]}" 2836 _python_clean_compiled_modules "${myfiles[@]}"
2465 fi 2837 fi
2466 2838
2467 eend "${return_code}" 2839 eend "${return_code}"
2468 fi 2840 fi
2469} 2841}
2470 2842
2471# @FUNCTION: python_mod_cleanup 2843# @FUNCTION: python_mod_cleanup
2472# @USAGE: [directory|file] 2844# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2473# @DESCRIPTION: 2845# @DESCRIPTION:
2474# Run with optional arguments, where arguments are Python modules. If none given, 2846# 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# 2847#
2481# This function can be used only in pkg_postrm() phase. 2848# This function can be used only in pkg_postrm() phase.
2482python_mod_cleanup() { 2849python_mod_cleanup() {
2850 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
2851 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2852 fi
2853
2483 _python_check_python_pkg_setup_execution 2854 _python_check_python_pkg_setup_execution
2484 _python_initialize_prefix_variables 2855 _python_initialize_prefix_variables
2485 2856
2486 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2857 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 2858
2491 if _python_package_supporting_installation_for_multiple_python_abis; then 2859 if _python_package_supporting_installation_for_multiple_python_abis; then
2492 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2860 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2493 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2861 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2494 fi 2862 fi
2525 2893
2526 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2894 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" 2895 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2528 fi 2896 fi
2529 2897
2530 if [[ "$#" -gt 0 ]]; then 2898 if [[ "$#" -eq 0 ]]; then
2531 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2899 die "${FUNCNAME}(): Missing files or directories"
2900 fi
2901
2902 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 2903 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2904 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'" 2905 die "${FUNCNAME}(): Invalid argument '$1'"
2535 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2906 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" 2907 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2537 elif [[ "$1" =~ ^/ ]]; then 2908 elif [[ "$1" =~ ^/ ]]; then
2538 if _python_package_supporting_installation_for_multiple_python_abis; then 2909 if _python_package_supporting_installation_for_multiple_python_abis; then
2539 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then 2910 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" 2911 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 2912 fi
2913 if [[ "$1" != *\$* ]]; then
2914 die "${FUNCNAME}(): '$1' has invalid syntax"
2915 fi
2916 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2917 eval "search_paths+=(\"\${root}$1\")"
2918 done
2551 else 2919 else
2920 search_paths+=("${root}$1")
2921 fi
2922 else
2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2923 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2553 search_paths+=("${root}$(python_get_sitedir)/$1") 2924 search_paths+=("${root}$(python_get_sitedir)/$1")
2554 done 2925 done
2555 fi 2926 fi
2556 shift 2927 shift
2557 done 2928 done
2558 else 2929 else
2559 # Deprecated part of python_mod_cleanup() 2930 # Deprecated part of python_mod_cleanup()
2560
2561 search_paths=("${@#/}")
2562 search_paths=("${search_paths[@]/#/${root}/}")
2563 fi
2564 else
2565 ewarn 2931 ewarn
2566 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" 2932 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." 2933 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2934 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." 2935 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2569 ewarn 2936 ewarn
2570 2937
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}") 2938 search_paths=("${@#/}")
2583 fi 2939 search_paths=("${search_paths[@]/#/${root}/}")
2584 done
2585 fi 2940 fi
2586 2941
2587 _python_clean_compiled_modules "${search_paths[@]}" 2942 _python_clean_compiled_modules "${search_paths[@]}"
2588} 2943}
2589 2944
2590# ================================================================================================ 2945# ================================================================================================
2591# ===================================== DEPRECATED FUNCTIONS ===================================== 2946# ===================================== DEPRECATED FUNCTIONS =====================================
2592# ================================================================================================ 2947# ================================================================================================
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.118

  ViewVC Help
Powered by ViewVC 1.1.20