/[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.125
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.125 2011/07/08 07:47:30 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.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_ABI_PATTERN_REGEX="([[:alnum:]]|\.|-|\*|\[|\])+"
28
29_python_check_python_abi_matching() {
30 local pattern patterns patterns_list="0" PYTHON_ABI
31
32 while (($#)); do
33 case "$1" in
34 --patterns-list)
35 patterns_list="1"
36 ;;
37 --)
38 shift
39 break
40 ;;
41 -*)
42 die "${FUNCNAME}(): Unrecognized option '$1'"
43 ;;
44 *)
45 break
46 ;;
47 esac
48 shift
49 done
50
51 if [[ "$#" -ne 2 ]]; then
52 die "${FUNCNAME}() requires 2 arguments"
53 fi
54
55 PYTHON_ABI="$1"
56
57 if [[ "${patterns_list}" == "0" ]]; then
58 pattern="$2"
59
60 if [[ "${pattern}" == *"-cpython" ]]; then
61 [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]]
62 elif [[ "${pattern}" == *"-jython" ]]; then
63 [[ "${PYTHON_ABI}" == ${pattern} ]]
64 else
65 if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
66 [[ "${PYTHON_ABI}" == ${pattern} ]]
67 elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
68 [[ "${PYTHON_ABI%-jython}" == ${pattern} ]]
69 else
70 die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'"
71 fi
72 fi
73 else
74 patterns="${2// /$'\n'}"
75
76 while read pattern; do
77 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
78 return 0
79 fi
80 done <<< "${patterns}"
81
82 return 1
83 fi
84}
85
86_python_package_supporting_installation_for_multiple_python_abis() {
87 if has "${EAPI:-0}" 0 1 2 3 4; then
88 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
89 return 0
90 else
91 return 1
92 fi
93 else
94 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
95 fi
96}
21 97
22# @ECLASS-VARIABLE: PYTHON_DEPEND 98# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 99# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 100# Specification of dependency on dev-lang/python.
25# Syntax: 101# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 103# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 104# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 105# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 106# maximal_version: <maximal_major_version.maximal_minor_version>
31 107
32_parse_PYTHON_DEPEND() { 108_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 109 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 110
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 111 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 112 version_components_groups="${PYTHON_DEPEND}"
37 113
60 fi 136 fi
61 fi 137 fi
62 138
63 if [[ "${major_version}" == "2" ]]; then 139 if [[ "${major_version}" == "2" ]]; then
64 python2="1" 140 python2="1"
65 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 141 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
66 python2_minimal_version="${minimal_version}" 142 python2_minimal_version="${minimal_version}"
67 python2_maximal_version="${maximal_version}" 143 python2_maximal_version="${maximal_version}"
68 elif [[ "${major_version}" == "3" ]]; then 144 elif [[ "${major_version}" == "3" ]]; then
69 python3="1" 145 python3="1"
70 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 146 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
71 python3_minimal_version="${minimal_version}" 147 python3_minimal_version="${minimal_version}"
72 python3_maximal_version="${maximal_version}" 148 python3_maximal_version="${maximal_version}"
73 else 149 else
74 python_all="1" 150 python_all="1"
75 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 151 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
76 python_minimal_version="${minimal_version}" 152 python_minimal_version="${minimal_version}"
77 python_maximal_version="${maximal_version}" 153 python_maximal_version="${maximal_version}"
78 fi 154 fi
79 155
80 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then 156 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
108 184
109 if [[ "${python_all}" == "1" ]]; then 185 if [[ "${python_all}" == "1" ]]; then
110 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then 186 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
111 _PYTHON_ATOMS+=("dev-lang/python") 187 _PYTHON_ATOMS+=("dev-lang/python")
112 else 188 else
113 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 189 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
114 python_minimal_version="${python_minimal_version:-${python_versions[0]}}" 190 python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
115 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 191 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
116 _append_accepted_versions_range 192 _append_accepted_versions_range
117 fi 193 fi
118 else 194 else
119 if [[ "${python3}" == "1" ]]; then 195 if [[ "${python3}" == "1" ]]; then
120 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then 196 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
121 _PYTHON_ATOMS+=("=dev-lang/python-3*") 197 _PYTHON_ATOMS+=("=dev-lang/python-3*")
122 else 198 else
123 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 199 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
124 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}" 200 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
125 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 201 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
126 _append_accepted_versions_range 202 _append_accepted_versions_range
127 fi 203 fi
128 fi 204 fi
129 if [[ "${python2}" == "1" ]]; then 205 if [[ "${python2}" == "1" ]]; then
130 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then 206 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
131 _PYTHON_ATOMS+=("=dev-lang/python-2*") 207 _PYTHON_ATOMS+=("=dev-lang/python-2*")
132 else 208 else
133 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 209 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
134 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}" 210 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
135 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 211 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
136 _append_accepted_versions_range 212 _append_accepted_versions_range
137 fi 213 fi
138 fi 214 fi
153} 229}
154 230
155DEPEND=">=app-admin/eselect-python-20091230" 231DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 232RDEPEND="${DEPEND}"
157 233
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 234if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 235 _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 236else
181 _PYTHON_ATOMS=("dev-lang/python") 237 _PYTHON_ATOMS=("dev-lang/python")
238fi
239unset -f _python_parse_PYTHON_DEPEND
240
241if [[ -n "${NEED_PYTHON}" ]]; then
242 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
243 die "NEED_PYTHON variable is banned"
182fi 244fi
183 245
184# @ECLASS-VARIABLE: PYTHON_USE_WITH 246# @ECLASS-VARIABLE: PYTHON_USE_WITH
185# @DESCRIPTION: 247# @DESCRIPTION:
186# Set this to a space separated list of USE flags the Python slot in use must be built with. 248# Set this to a space separated list of USE flags the Python slot in use must be built with.
235 else 297 else
236 return 1 298 return 1
237 fi 299 fi
238} 300}
239 301
240_python_package_supporting_installation_for_multiple_python_abis() {
241 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
242 die "${FUNCNAME}() cannot be used in global scope"
243 fi
244
245 if has "${EAPI:-0}" 0 1 2 3 4; then
246 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
247 return 0
248 else
249 return 1
250 fi
251 else
252 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
253 fi
254}
255
256_python_abi-specific_local_scope() { 302_python_abi-specific_local_scope() {
257 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] 303 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
258} 304}
259 305
260_python_initialize_prefix_variables() { 306_python_initialize_prefix_variables() {
347# @DESCRIPTION: 393# @DESCRIPTION:
348# Perform sanity checks and initialize environment. 394# Perform sanity checks and initialize environment.
349# 395#
350# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable 396# 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. 397# 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() { 398python_pkg_setup() {
355 # Check if phase is pkg_setup(). 399 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
356 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 400 die "${FUNCNAME}() can be used only in pkg_setup() phase"
401 fi
357 402
358 if [[ "$#" -ne 0 ]]; then 403 if [[ "$#" -ne 0 ]]; then
359 die "${FUNCNAME}() does not accept arguments" 404 die "${FUNCNAME}() does not accept arguments"
360 fi 405 fi
406
407 export JYTHON_SYSTEM_CACHEDIR="1"
408 addwrite "${EPREFIX}/var/cache/jython"
361 409
362 if _python_package_supporting_installation_for_multiple_python_abis; then 410 if _python_package_supporting_installation_for_multiple_python_abis; then
363 _python_calculate_PYTHON_ABIS 411 _python_calculate_PYTHON_ABIS
364 export EPYTHON="$(PYTHON -f)" 412 export EPYTHON="$(PYTHON -f)"
365 else 413 else
408 fi 456 fi
409 457
410 PYTHON_PKG_SETUP_EXECUTED="1" 458 PYTHON_PKG_SETUP_EXECUTED="1"
411} 459}
412 460
413if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 461if ! 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 462 EXPORT_FUNCTIONS pkg_setup
415fi 463fi
416 464
465_PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|python)'
466
417# @FUNCTION: python_convert_shebangs 467# @FUNCTION: python_convert_shebangs
418# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 468# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories]
419# @DESCRIPTION: 469# @DESCRIPTION:
420# Convert shebangs in specified files. Directories can be specified only with --recursive option. 470# Convert shebangs in specified files. Directories can be specified only with --recursive option.
421python_convert_shebangs() { 471python_convert_shebangs() {
422 _python_check_python_pkg_setup_execution 472 _python_check_python_pkg_setup_execution
423 473
424 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 474 local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0"
425 475
426 while (($#)); do 476 while (($#)); do
427 case "$1" in 477 case "$1" in
428 -r|--recursive) 478 -r|--recursive)
429 recursive="1" 479 recursive="1"
452 die "${FUNCNAME}(): Missing Python version and files or directories" 502 die "${FUNCNAME}(): Missing Python version and files or directories"
453 elif [[ "$#" -eq 1 ]]; then 503 elif [[ "$#" -eq 1 ]]; then
454 die "${FUNCNAME}(): Missing files or directories" 504 die "${FUNCNAME}(): Missing files or directories"
455 fi 505 fi
456 506
457 python_version="$1" 507 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
508 python_interpreter="$(PYTHON "$1")"
509 else
510 python_interpreter="python$1"
511 fi
458 shift 512 shift
459 513
460 for argument in "$@"; do 514 for argument in "$@"; do
461 if [[ ! -e "${argument}" ]]; then 515 if [[ ! -e "${argument}" ]]; then
462 die "${FUNCNAME}(): '${argument}' does not exist" 516 die "${FUNCNAME}(): '${argument}' does not exist"
477 531
478 for file in "${files[@]}"; do 532 for file in "${files[@]}"; do
479 file="${file#./}" 533 file="${file#./}"
480 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 534 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
481 535
482 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 536 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 537 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
484 538
485 if [[ "${quiet}" == "0" ]]; then 539 if [[ "${quiet}" == "0" ]]; then
486 einfo "Converting shebang in '${file}'" 540 einfo "Converting shebang in '${file}'"
487 fi 541 fi
488 542
489 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 543 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 544 fi
494 done 545 done
495} 546}
496 547
497# @FUNCTION: python_clean_installation_image 548# @FUNCTION: python_clean_installation_image
498# @USAGE: [-q|--quiet] 549# @USAGE: [-q|--quiet]
499# @DESCRIPTION: 550# @DESCRIPTION:
500# Delete needless files in installation image. 551# Delete needless files in installation image.
552#
553# This function can be used only in src_install() phase.
501python_clean_installation_image() { 554python_clean_installation_image() {
555 if [[ "${EBUILD_PHASE}" != "install" ]]; then
556 die "${FUNCNAME}() can be used only in src_install() phase"
557 fi
558
502 _python_check_python_pkg_setup_execution 559 _python_check_python_pkg_setup_execution
503 _python_initialize_prefix_variables 560 _python_initialize_prefix_variables
504 561
505 local file files=() quiet="0" 562 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 563
510 while (($#)); do 564 while (($#)); do
511 case "$1" in 565 case "$1" in
512 -q|--quiet) 566 -q|--quiet)
513 quiet="1" 567 quiet="1"
564# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 618# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
565# @DESCRIPTION: 619# @DESCRIPTION:
566# Set this in EAPI <= 4 to indicate that current package supports installation for 620# Set this in EAPI <= 4 to indicate that current package supports installation for
567# multiple Python ABIs. 621# multiple Python ABIs.
568 622
623# @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS
624# @DESCRIPTION:
625# Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI
626# patterns specified in this list is skipped.
627
569# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 628# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
570# @DESCRIPTION: 629# @DESCRIPTION:
571# Set this to export phase functions for the following ebuild phases: 630# Set this to export phase functions for the following ebuild phases:
572# src_prepare, src_configure, src_compile, src_test, src_install. 631# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
573if ! has "${EAPI:-0}" 0 1; then 632if ! has "${EAPI:-0}" 0 1; then
574 python_src_prepare() { 633 python_src_prepare() {
575 _python_check_python_pkg_setup_execution 634 if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
635 die "${FUNCNAME}() can be used only in src_prepare() phase"
636 fi
576 637
577 if ! _python_package_supporting_installation_for_multiple_python_abis; then 638 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" 639 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
579 fi 640 fi
580 641
642 _python_check_python_pkg_setup_execution
643
581 if [[ "$#" -ne 0 ]]; then 644 if [[ "$#" -ne 0 ]]; then
582 die "${FUNCNAME}() does not accept arguments" 645 die "${FUNCNAME}() does not accept arguments"
583 fi 646 fi
584 647
585 python_copy_sources 648 python_copy_sources
586 } 649 }
587 650
588 for python_default_function in src_configure src_compile src_test src_install; do 651 for python_default_function in src_configure src_compile src_test; do
589 eval "python_${python_default_function}() { 652 eval "python_${python_default_function}() {
590 _python_check_python_pkg_setup_execution 653 if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
654 die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
655 fi
591 656
592 if ! _python_package_supporting_installation_for_multiple_python_abis; then 657 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\" 658 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
594 fi 659 fi
595 660
661 _python_check_python_pkg_setup_execution
662
596 python_execute_function -d -s -- \"\$@\" 663 python_execute_function -d -s -- \"\$@\"
597 }" 664 }"
598 done 665 done
599 unset python_default_function 666 unset python_default_function
600 667
668 python_src_install() {
669 if [[ "${EBUILD_PHASE}" != "install" ]]; then
670 die "${FUNCNAME}() can be used only in src_install() phase"
671 fi
672
673 if ! _python_package_supporting_installation_for_multiple_python_abis; then
674 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
675 fi
676
677 _python_check_python_pkg_setup_execution
678
679 if has "${EAPI:-0}" 0 1 2 3; then
680 python_execute_function -d -s -- "$@"
681 else
682 python_installation() {
683 emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
684 }
685 python_execute_function -s python_installation "$@"
686 unset python_installation
687
688 python_merge_intermediate_installation_images "${T}/images"
689 fi
690 }
691
601 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 692 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
602 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 693 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
603 fi 694 fi
604fi 695fi
605 696
697if has "${EAPI:-0}" 0 1 2 3 4; then
606unset PYTHON_ABIS 698 unset PYTHON_ABIS
699fi
607 700
608_python_calculate_PYTHON_ABIS() { 701_python_calculate_PYTHON_ABIS() {
609 if ! _python_package_supporting_installation_for_multiple_python_abis; then 702 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" 703 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
611 fi 704 fi
612 705
613 _python_initial_sanity_checks 706 _python_initial_sanity_checks
614 707
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 708 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= 709 local PYTHON_ABI
618 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
619 710
620 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 711 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
621 local cpython_enabled="0" 712 local cpython_enabled="0"
622 713
623 if [[ -z "${USE_PYTHON}" ]]; then 714 if [[ -z "${USE_PYTHON}" ]]; then
624 die "USE_PYTHON variable is empty" 715 die "USE_PYTHON variable is empty"
625 fi 716 fi
626 717
627 for PYTHON_ABI in ${USE_PYTHON}; do 718 for PYTHON_ABI in ${USE_PYTHON}; do
628 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 719 if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
629 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 720 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
630 fi 721 fi
631 722
632 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 723 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
633 cpython_enabled="1" 724 cpython_enabled="1"
634 fi 725 fi
635 726
636 support_ABI="1" 727 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 728 export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
638 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 729 fi
639 support_ABI="0" 730 done
731
732 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
733 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
734 fi
735
736 if [[ "${cpython_enabled}" == "0" ]]; then
737 die "USE_PYTHON variable does not enable any CPython ABI"
738 fi
739 else
740 local python_version python2_version python3_version support_python_major_version
741
742 if ! has_version "dev-lang/python"; then
743 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
744 fi
745
746 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
747
748 if has_version "=dev-lang/python-2*"; then
749 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
750 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
751 fi
752
753 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
754
755 support_python_major_version="0"
756 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
757 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
758 support_python_major_version="1"
640 break 759 break
641 fi 760 fi
642 done 761 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 762 if [[ "${support_python_major_version}" == "1" ]]; then
679 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 763 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}" 764 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
682 fi 765 fi
683 done
684 else 766 else
685 python2_version="" 767 python2_version=""
686 fi 768 fi
687 fi 769 fi
688 770
691 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 773 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
692 fi 774 fi
693 775
694 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 776 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
695 777
778 support_python_major_version="0"
696 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 779 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
780 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
697 support_python_major_version="1" 781 support_python_major_version="1"
698 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 782 break
699 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
700 support_python_major_version="0"
701 fi 783 fi
702 done
703 [[ "${support_python_major_version}" == "1" ]] && break
704 done 784 done
705 if [[ "${support_python_major_version}" == "1" ]]; then 785 if [[ "${support_python_major_version}" == "1" ]]; then
706 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 786 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}" 787 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
709 fi 788 fi
710 done
711 else 789 else
712 python3_version="" 790 python3_version=""
713 fi 791 fi
714 fi 792 fi
715 793
740 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"" 818 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
741 for prefix in PYTHON_USER_ PYTHON_; do 819 for prefix in PYTHON_USER_ PYTHON_; do
742 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then 820 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
743 eval "array=(\"\${${prefix}${variable}[@]}\")" 821 eval "array=(\"\${${prefix}${variable}[@]}\")"
744 for element in "${array[@]}"; do 822 for element in "${array[@]}"; do
745 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then 823 if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
746 pattern="${element%% *}" 824 pattern="${element%% *}"
747 element="${element#* }" 825 element="${element#* }"
748 operator="${element%% *}" 826 operator="${element%% *}"
749 flags="${element#* }" 827 flags="${element#* }"
750 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then 828 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
751 if [[ "${operator}" == "+" ]]; then 829 if [[ "${operator}" == "+" ]]; then
752 eval "export ${variable}+=\"\${variable:+ }${flags}\"" 830 eval "export ${variable}+=\"\${variable:+ }${flags}\""
753 elif [[ "${operator}" == "-" ]]; then 831 elif [[ "${operator}" == "-" ]]; then
754 flags="${flags// /$'\n'}" 832 flags="${flags// /$'\n'}"
755 old_value="${!variable// /$'\n'}" 833 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] 867# @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: 868# @DESCRIPTION:
791# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 869# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
792# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 870# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
793python_execute_function() { 871python_execute_function() {
794 _python_check_python_pkg_setup_execution
795
796 if ! _python_package_supporting_installation_for_multiple_python_abis; then 872 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" 873 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
798 fi 874 fi
799 875
876 _python_check_python_pkg_setup_execution
800 _python_set_color_variables 877 _python_set_color_variables
801 878
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= 879 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 880
804 while (($#)); do 881 while (($#)); do
805 case "$1" in 882 case "$1" in
806 --action-message) 883 --action-message)
807 action_message_template="$2" 884 action_message_template="$2"
919 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 996 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
920 else 997 else
921 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 998 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
922 fi 999 fi
923 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1000 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1001 if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
1002 if [[ "${quiet}" == "0" ]]; then
1003 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}"
1004 fi
1005 continue
1006 fi
1007
924 _python_prepare_flags 1008 _python_prepare_flags
925 1009
926 if [[ "${quiet}" == "0" ]]; then 1010 if [[ "${quiet}" == "0" ]]; then
927 if [[ -n "${action_message_template}" ]]; then 1011 if [[ -n "${action_message_template}" ]]; then
928 eval "action_message=\"${action_message_template}\"" 1012 eval "action_message=\"${action_message_template}\""
929 else 1013 else
930 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 1014 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)..."
931 fi 1015 fi
932 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 1016 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
933 fi 1017 fi
934 1018
935 if [[ "${separate_build_dirs}" == "1" ]]; then 1019 if [[ "${separate_build_dirs}" == "1" ]]; then
959 1043
960 if [[ "${return_code}" -ne 0 ]]; then 1044 if [[ "${return_code}" -ne 0 ]]; then
961 if [[ -n "${failure_message_template}" ]]; then 1045 if [[ -n "${failure_message_template}" ]]; then
962 eval "failure_message=\"${failure_message_template}\"" 1046 eval "failure_message=\"${failure_message_template}\""
963 else 1047 else
964 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 1048 failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function"
965 fi 1049 fi
966 1050
967 if [[ "${nonfatal}" == "1" ]]; then 1051 if [[ "${nonfatal}" == "1" ]]; then
968 if [[ "${quiet}" == "0" ]]; then 1052 if [[ "${quiet}" == "0" ]]; then
969 ewarn "${failure_message}" 1053 ewarn "${failure_message}"
1022# @FUNCTION: python_copy_sources 1106# @FUNCTION: python_copy_sources
1023# @USAGE: <directory="${S}"> [directory] 1107# @USAGE: <directory="${S}"> [directory]
1024# @DESCRIPTION: 1108# @DESCRIPTION:
1025# Copy unpacked sources of current package to separate build directory for each Python ABI. 1109# Copy unpacked sources of current package to separate build directory for each Python ABI.
1026python_copy_sources() { 1110python_copy_sources() {
1027 _python_check_python_pkg_setup_execution
1028
1029 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1111 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" 1112 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1031 fi 1113 fi
1114
1115 _python_check_python_pkg_setup_execution
1032 1116
1033 local dir dirs=() PYTHON_ABI 1117 local dir dirs=() PYTHON_ABI
1034 1118
1035 if [[ "$#" -eq 0 ]]; then 1119 if [[ "$#" -eq 0 ]]; then
1036 if [[ "${WORKDIR}" == "${S}" ]]; then 1120 if [[ "${WORKDIR}" == "${S}" ]]; then
1053# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1137# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1054# @DESCRIPTION: 1138# @DESCRIPTION:
1055# Generate wrapper scripts. Existing files are overwritten only with --force option. 1139# Generate wrapper scripts. Existing files are overwritten only with --force option.
1056# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1140# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1057# respect EPYTHON variable at run time. 1141# respect EPYTHON variable at run time.
1142#
1143# This function can be used only in src_install() phase.
1058python_generate_wrapper_scripts() { 1144python_generate_wrapper_scripts() {
1059 _python_check_python_pkg_setup_execution 1145 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1146 die "${FUNCNAME}() can be used only in src_install() phase"
1147 fi
1060 1148
1061 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1149 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" 1150 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1063 fi 1151 fi
1064 1152
1153 _python_check_python_pkg_setup_execution
1065 _python_initialize_prefix_variables 1154 _python_initialize_prefix_variables
1066 1155
1067 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 1156 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1068 1157
1069 while (($#)); do 1158 while (($#)); do
1070 case "$1" in 1159 case "$1" in
1071 -E|--respect-EPYTHON) 1160 -E|--respect-EPYTHON)
1072 respect_EPYTHON="1" 1161 respect_EPYTHON="1"
1094 if [[ "$#" -eq 0 ]]; then 1183 if [[ "$#" -eq 0 ]]; then
1095 die "${FUNCNAME}(): Missing arguments" 1184 die "${FUNCNAME}(): Missing arguments"
1096 fi 1185 fi
1097 1186
1098 _python_calculate_PYTHON_ABIS 1187 _python_calculate_PYTHON_ABIS
1099 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1188 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1100 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1189 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1101 python2_enabled="1" 1190 python2_enabled="1"
1102 fi 1191 fi
1103 done 1192 done
1104 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 1193 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1105 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1194 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1106 python3_enabled="1" 1195 python3_enabled="1"
1107 fi 1196 fi
1108 done 1197 done
1109 1198
1115 eselect_python_option="--python3" 1204 eselect_python_option="--python3"
1116 else 1205 else
1117 die "${FUNCNAME}(): Unsupported environment" 1206 die "${FUNCNAME}(): Unsupported environment"
1118 fi 1207 fi
1119 1208
1209 PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")"
1210
1120 for file in "$@"; do 1211 for file in "$@"; do
1121 if [[ -f "${file}" && "${force}" == "0" ]]; then 1212 if [[ -f "${file}" && "${force}" == "0" ]]; then
1122 die "${FUNCNAME}(): '$1' already exists" 1213 die "${FUNCNAME}(): '${file}' already exists"
1123 fi 1214 fi
1124 1215
1125 if [[ "${quiet}" == "0" ]]; then 1216 if [[ "${quiet}" == "0" ]]; then
1126 einfo "Generating '${file#${ED%/}}' wrapper script" 1217 einfo "Generating '${file#${ED%/}}' wrapper script"
1127 fi 1218 fi
1133import os 1224import os
1134import re 1225import re
1135import subprocess 1226import subprocess
1136import sys 1227import sys
1137 1228
1138EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 1229cpython_re = re.compile(r"^python(\d+\.\d+)$")
1230jython_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)") 1231python_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$") 1232python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1233
1234def get_PYTHON_ABI(EPYTHON):
1235 cpython_matched = cpython_re.match(EPYTHON)
1236 jython_matched = jython_re.match(EPYTHON)
1237 if cpython_matched is not None:
1238 PYTHON_ABI = cpython_matched.group(1)
1239 elif jython_matched is not None:
1240 PYTHON_ABI = jython_matched.group(1) + "-jython"
1241 else:
1242 PYTHON_ABI = None
1243 return PYTHON_ABI
1141 1244
1142EOF 1245EOF
1143 if [[ "$?" != "0" ]]; then 1246 if [[ "$?" != "0" ]]; then
1144 die "${FUNCNAME}(): Generation of '$1' failed" 1247 die "${FUNCNAME}(): Generation of '$1' failed"
1145 fi 1248 fi
1146 if [[ "${respect_EPYTHON}" == "1" ]]; then 1249 if [[ "${respect_EPYTHON}" == "1" ]]; then
1147 cat << EOF >> "${file}" 1250 cat << EOF >> "${file}"
1148EPYTHON = os.environ.get("EPYTHON") 1251EPYTHON = os.environ.get("EPYTHON")
1149if EPYTHON: 1252if EPYTHON:
1150 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1253 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1151 if EPYTHON_matched: 1254 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) 1255 sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], EPYTHON))
1155 sys.exit(1) 1256 sys.exit(1)
1156else: 1257else:
1157 try: 1258 try:
1259 environment = os.environ.copy()
1260 environment["ROOT"] = "/"
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 "\"")}], env=environment, stdout=subprocess.PIPE)
1159 if eselect_process.wait() != 0: 1262 if eselect_process.wait() != 0:
1160 raise ValueError 1263 raise ValueError
1161 except (OSError, ValueError): 1264 except (OSError, ValueError):
1162 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1265 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1163 sys.exit(1) 1266 sys.exit(1)
1164 1267
1165 EPYTHON = eselect_process.stdout.read() 1268 EPYTHON = eselect_process.stdout.read()
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("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], 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: '%s' does not exist\n" % (sys.argv[0], 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
1182 cat << EOF >> "${file}" 1289 cat << EOF >> "${file}"
1183try: 1290try:
1291 environment = os.environ.copy()
1292 environment["ROOT"] = "/"
1184 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1293 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
1185 if eselect_process.wait() != 0: 1294 if eselect_process.wait() != 0:
1186 raise ValueError 1295 raise ValueError
1187except (OSError, ValueError): 1296except (OSError, ValueError):
1188 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1297 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1189 sys.exit(1) 1298 sys.exit(1)
1190 1299
1191EPYTHON = eselect_process.stdout.read() 1300EPYTHON = eselect_process.stdout.read()
1192if not isinstance(EPYTHON, str): 1301if not isinstance(EPYTHON, str):
1193 # Python 3 1302 # Python 3
1194 EPYTHON = EPYTHON.decode() 1303 EPYTHON = EPYTHON.decode()
1195EPYTHON = EPYTHON.rstrip("\n") 1304EPYTHON = EPYTHON.rstrip("\n")
1196 1305
1197EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1306PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1198if EPYTHON_matched: 1307if PYTHON_ABI is None:
1199 PYTHON_ABI = EPYTHON_matched.group(1) 1308 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON))
1309 sys.exit(1)
1310
1311wrapper_script_path = os.path.realpath(sys.argv[0])
1312for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1313 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1314 if os.path.exists(target_executable_path):
1315 break
1200else: 1316else:
1201 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1317 sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
1202 sys.exit(1) 1318 sys.exit(1)
1203EOF 1319EOF
1204 if [[ "$?" != "0" ]]; then 1320 if [[ "$?" != "0" ]]; then
1205 die "${FUNCNAME}(): Generation of '$1' failed" 1321 die "${FUNCNAME}(): Generation of '$1' failed"
1206 fi 1322 fi
1207 fi 1323 fi
1208 cat << EOF >> "${file}" 1324 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 1325
1219target_executable = open(target_executable_path, "rb") 1326target_executable = open(target_executable_path, "rb")
1220target_executable_first_line = target_executable.readline() 1327target_executable_first_line = target_executable.readline()
1221if not isinstance(target_executable_first_line, str): 1328if not isinstance(target_executable_first_line, str):
1222 # Python 3 1329 # Python 3
1223 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1330 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1224 1331
1225python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1332python_shebang_matched = python_shebang_re.match(target_executable_first_line)
1226target_executable.close() 1333target_executable.close()
1227 1334
1228if python_shebang_matched: 1335if python_shebang_matched is not None:
1229 try: 1336 try:
1230 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1337 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1231 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1338 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1232 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1339 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1233 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1340 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1240 python_verification_output = python_verification_output.decode() 1347 python_verification_output = python_verification_output.decode()
1241 1348
1242 if not python_verification_output_re.match(python_verification_output): 1349 if not python_verification_output_re.match(python_verification_output):
1243 raise ValueError 1350 raise ValueError
1244 1351
1352 if cpython_re.match(EPYTHON) is not None:
1353 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1354 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1355 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1356
1357 if hasattr(os, "execv"):
1245 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1358 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
1359 else:
1360 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait())
1361 except (KeyboardInterrupt, SystemExit):
1362 raise
1246 except: 1363 except:
1247 pass 1364 pass
1248 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: 1365 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"] 1366 if variable in os.environ:
1367 del os.environ[variable]
1250 1368
1369if hasattr(os, "execv"):
1251os.execv(target_executable_path, sys.argv) 1370 os.execv(target_executable_path, sys.argv)
1371else:
1372 sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
1252EOF 1373EOF
1253 if [[ "$?" != "0" ]]; then 1374 if [[ "$?" != "0" ]]; then
1254 die "${FUNCNAME}(): Generation of '$1' failed" 1375 die "${FUNCNAME}(): Generation of '$1' failed"
1255 fi 1376 fi
1256 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 1377 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
1257 done 1378 done
1258} 1379}
1259 1380
1381# @ECLASS-VARIABLE: PYTHON_VERSIONED_SCRIPTS
1382# @DESCRIPTION:
1383# Array of regular expressions of paths to versioned Python scripts.
1384# Python scripts in /usr/bin and /usr/sbin are versioned by default.
1385
1386# @ECLASS-VARIABLE: PYTHON_VERSIONED_EXECUTABLES
1387# @DESCRIPTION:
1388# Array of regular expressions of paths to versioned executables (including Python scripts).
1389
1390# @ECLASS-VARIABLE: PYTHON_NONVERSIONED_EXECUTABLES
1391# @DESCRIPTION:
1392# Array of regular expressions of paths to nonversioned executables (including Python scripts).
1393
1394# @FUNCTION: python_merge_intermediate_installation_images
1395# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
1396# @DESCRIPTION:
1397# Merge intermediate installation images into installation image.
1398#
1399# This function can be used only in src_install() phase.
1400python_merge_intermediate_installation_images() {
1401 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1402 die "${FUNCNAME}() can be used only in src_install() phase"
1403 fi
1404
1405 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1406 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1407 fi
1408
1409 _python_check_python_pkg_setup_execution
1410 _python_initialize_prefix_variables
1411
1412 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1413
1414 while (($#)); do
1415 case "$1" in
1416 -q|--quiet)
1417 quiet="1"
1418 ;;
1419 --)
1420 shift
1421 break
1422 ;;
1423 -*)
1424 die "${FUNCNAME}(): Unrecognized option '$1'"
1425 ;;
1426 *)
1427 break
1428 ;;
1429 esac
1430 shift
1431 done
1432
1433 if [[ "$#" -ne 1 ]]; then
1434 die "${FUNCNAME}() requires 1 argument"
1435 fi
1436
1437 intermediate_installation_images_directory="$1"
1438
1439 if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
1440 die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist"
1441 fi
1442
1443 _python_calculate_PYTHON_ABIS
1444 if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
1445 b="b"
1446 fi
1447
1448 while read -d $'\0' -r file; do
1449 files+=("${file}")
1450 done < <("$(PYTHON -f)" -c \
1451"import os
1452import sys
1453
1454if hasattr(sys.stdout, 'buffer'):
1455 # Python 3
1456 stdout = sys.stdout.buffer
1457else:
1458 # Python 2
1459 stdout = sys.stdout
1460
1461files_set = set()
1462
1463os.chdir(${b}'${intermediate_installation_images_directory}')
1464
1465for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
1466 for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
1467 root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
1468 files_set.update(root + ${b}'/' + file for file in files)
1469
1470for file in sorted(files_set):
1471 stdout.write(file)
1472 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images")
1473
1474 for PYTHON_ABI in ${PYTHON_ABIS}; do
1475 if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
1476 die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist"
1477 fi
1478
1479 pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed"
1480
1481 for file in "${files[@]}"; do
1482 version_executable="0"
1483 for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}"; do
1484 if [[ "/${file}" =~ ^${regex}$ ]]; then
1485 version_executable="1"
1486 break
1487 fi
1488 done
1489 for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}"; do
1490 if [[ "/${file}" =~ ^${regex}$ ]]; then
1491 version_executable="2"
1492 break
1493 fi
1494 done
1495 if [[ "${version_executable}" != "0" ]]; then
1496 for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}"; do
1497 if [[ "/${file}" =~ ^${regex}$ ]]; then
1498 version_executable="0"
1499 break
1500 fi
1501 done
1502 fi
1503
1504 [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue
1505
1506 shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed"
1507
1508 if [[ "${version_executable}" == "2" ]]; then
1509 wrapper_scripts+=("${ED}${file}")
1510 elif [[ "${version_executable}" == "1" ]]; then
1511 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
1512 wrapper_scripts+=("${ED}${file}")
1513 else
1514 version_executable="0"
1515 fi
1516 fi
1517
1518 [[ "${version_executable}" == "0" ]] && continue
1519
1520 if [[ -e "${file}-${PYTHON_ABI}" ]]; then
1521 die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists"
1522 fi
1523
1524 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
1525
1526 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
1527 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
1528 fi
1529 done
1530
1531 popd > /dev/null || die "popd failed"
1532
1533 if ROOT="/" has_version sys-apps/coreutils; then
1534 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"
1535 else
1536 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1537 fi
1538 done
1539
1540 rm -fr "${intermediate_installation_images_directory}"
1541
1542 if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
1543 rm -f "${T}/python_wrapper_scripts"
1544
1545 for file in "${wrapper_scripts[@]}"; do
1546 echo -n "${file}" >> "${T}/python_wrapper_scripts"
1547 echo -en "\x00" >> "${T}/python_wrapper_scripts"
1548 done
1549
1550 while read -d $'\0' -r file; do
1551 wrapper_scripts_set+=("${file}")
1552 done < <("$(PYTHON -f)" -c \
1553"import sys
1554
1555if hasattr(sys.stdout, 'buffer'):
1556 # Python 3
1557 stdout = sys.stdout.buffer
1558else:
1559 # Python 2
1560 stdout = sys.stdout
1561
1562files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00'))
1563
1564for file in sorted(files):
1565 stdout.write(file)
1566 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1567
1568 python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}"
1569 fi
1570}
1571
1260# ================================================================================================ 1572# ================================================================================================
1261# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1573# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1262# ================================================================================================ 1574# ================================================================================================
1263 1575
1264unset EPYTHON PYTHON_ABI 1576unset EPYTHON PYTHON_ABI
1265 1577
1266# @FUNCTION: python_set_active_version 1578# @FUNCTION: python_set_active_version
1267# @USAGE: <CPython_ABI|2|3> 1579# @USAGE: <Python_ABI|2|3>
1268# @DESCRIPTION: 1580# @DESCRIPTION:
1269# Set specified version of CPython as active version of Python. 1581# Set locally active version of Python.
1582# If Python_ABI argument is specified, then version of Python corresponding to Python_ABI is used.
1583# If 2 argument is specified, then active version of CPython 2 is used.
1584# If 3 argument is specified, then active version of CPython 3 is used.
1270# 1585#
1271# This function can be used only in pkg_setup() phase. 1586# This function can be used only in pkg_setup() phase.
1272python_set_active_version() { 1587python_set_active_version() {
1273 # Check if phase is pkg_setup(). 1588 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1274 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 1589 die "${FUNCNAME}() can be used only in pkg_setup() phase"
1590 fi
1275 1591
1276 if _python_package_supporting_installation_for_multiple_python_abis; then 1592 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" 1593 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1278 fi 1594 fi
1279 1595
1282 fi 1598 fi
1283 1599
1284 _python_initial_sanity_checks 1600 _python_initial_sanity_checks
1285 1601
1286 if [[ -z "${PYTHON_ABI}" ]]; then 1602 if [[ -z "${PYTHON_ABI}" ]]; then
1287 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1603 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
1288 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1604 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1289 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1605 # so it does not need to be exported to subprocesses.
1606 PYTHON_ABI="$1"
1607 if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
1608 die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed"
1290 fi 1609 fi
1291 export EPYTHON="$(PYTHON "$1")" 1610 export EPYTHON="$(PYTHON "$1")"
1292 elif [[ "$1" == "2" ]]; then 1611 elif [[ "$1" == "2" ]]; then
1293 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1612 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1294 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1613 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1295 fi 1614 fi
1296 export EPYTHON="$(PYTHON -2)" 1615 export EPYTHON="$(PYTHON -2)"
1616 PYTHON_ABI="${EPYTHON#python}"
1617 PYTHON_ABI="${PYTHON_ABI%%-*}"
1297 elif [[ "$1" == "3" ]]; then 1618 elif [[ "$1" == "3" ]]; then
1298 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1619 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1299 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1620 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1300 fi 1621 fi
1301 export EPYTHON="$(PYTHON -3)" 1622 export EPYTHON="$(PYTHON -3)"
1623 PYTHON_ABI="${EPYTHON#python}"
1624 PYTHON_ABI="${PYTHON_ABI%%-*}"
1302 else 1625 else
1303 die "${FUNCNAME}(): Unrecognized argument '$1'" 1626 die "${FUNCNAME}(): Unrecognized argument '$1'"
1304 fi 1627 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 1628 fi
1311 1629
1312 _python_final_sanity_checks 1630 _python_final_sanity_checks
1313 1631
1314 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1632 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1317 1635
1318# @FUNCTION: python_need_rebuild 1636# @FUNCTION: python_need_rebuild
1319# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1637# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1320# switching of active version of Python. 1638# switching of active version of Python.
1321python_need_rebuild() { 1639python_need_rebuild() {
1322 _python_check_python_pkg_setup_execution
1323
1324 if _python_package_supporting_installation_for_multiple_python_abis; then 1640 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" 1641 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1326 fi 1642 fi
1643
1644 _python_check_python_pkg_setup_execution
1327 1645
1328 if [[ "$#" -ne 0 ]]; then 1646 if [[ "$#" -ne 0 ]]; then
1329 die "${FUNCNAME}() does not accept arguments" 1647 die "${FUNCNAME}() does not accept arguments"
1330 fi 1648 fi
1331 1649
1341sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) 1659sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
1342if platform.system()[:4] == "Java": 1660if platform.system()[:4] == "Java":
1343 sys.stdout.write("-jython")' 1661 sys.stdout.write("-jython")'
1344 1662
1345_python_get_implementation() { 1663_python_get_implementation() {
1664 local ignore_invalid="0"
1665
1666 while (($#)); do
1667 case "$1" in
1668 --ignore-invalid)
1669 ignore_invalid="1"
1670 ;;
1671 --)
1672 shift
1673 break
1674 ;;
1675 -*)
1676 die "${FUNCNAME}(): Unrecognized option '$1'"
1677 ;;
1678 *)
1679 break
1680 ;;
1681 esac
1682 shift
1683 done
1684
1346 if [[ "$#" -ne 1 ]]; then 1685 if [[ "$#" -ne 1 ]]; then
1347 die "${FUNCNAME}() requires 1 argument" 1686 die "${FUNCNAME}() requires 1 argument"
1348 fi 1687 fi
1349 1688
1350 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1689 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1351 echo "CPython" 1690 echo "CPython"
1352 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then 1691 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
1353 echo "Jython" 1692 echo "Jython"
1354 else 1693 else
1694 if [[ "${ignore_invalid}" == "0" ]]; then
1355 die "${FUNCNAME}(): Unrecognized Python ABI '$1'" 1695 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
1696 fi
1356 fi 1697 fi
1357} 1698}
1358 1699
1359# @FUNCTION: PYTHON 1700# @FUNCTION: PYTHON
1360# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 1701# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
1361# @DESCRIPTION: 1702# @DESCRIPTION:
1362# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument 1703# 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. 1704# 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. 1705# 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. 1706# 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. 1707# 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. 1708# -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 1709# If --ABI option is specified, then only specified Python ABI is printed instead of
1369# filename of Python interpreter. 1710# filename of Python interpreter.
1370# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1711# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1419 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1760 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1420 fi 1761 fi
1421 _python_calculate_PYTHON_ABIS 1762 _python_calculate_PYTHON_ABIS
1422 PYTHON_ABI="${PYTHON_ABIS##* }" 1763 PYTHON_ABI="${PYTHON_ABIS##* }"
1423 elif [[ "${python2}" == "1" ]]; then 1764 elif [[ "${python2}" == "1" ]]; then
1424 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1765 PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)"
1425 if [[ -z "${PYTHON_ABI}" ]]; then 1766 if [[ -z "${PYTHON_ABI}" ]]; then
1426 die "${FUNCNAME}(): Active version of Python 2 not set" 1767 die "${FUNCNAME}(): Active version of CPython 2 not set"
1427 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1768 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1428 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1769 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1429 fi 1770 fi
1430 elif [[ "${python3}" == "1" ]]; then 1771 elif [[ "${python3}" == "1" ]]; then
1431 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1772 PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)"
1432 if [[ -z "${PYTHON_ABI}" ]]; then 1773 if [[ -z "${PYTHON_ABI}" ]]; then
1433 die "${FUNCNAME}(): Active version of Python 3 not set" 1774 die "${FUNCNAME}(): Active version of CPython 3 not set"
1434 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1775 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1435 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1776 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1436 fi 1777 fi
1437 elif _python_package_supporting_installation_for_multiple_python_abis; then 1778 elif _python_package_supporting_installation_for_multiple_python_abis; then
1438 if ! _python_abi-specific_local_scope; then 1779 if ! _python_abi-specific_local_scope; then
1464 return 1805 return
1465 else 1806 else
1466 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1807 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1467 python_interpreter="python${PYTHON_ABI}" 1808 python_interpreter="python${PYTHON_ABI}"
1468 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1809 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1469 python_interpreter="jython-${PYTHON_ABI%-jython}" 1810 python_interpreter="jython${PYTHON_ABI%-jython}"
1470 fi 1811 fi
1471 1812
1472 if [[ "${absolute_path_output}" == "1" ]]; then 1813 if [[ "${absolute_path_output}" == "1" ]]; then
1473 echo -n "${EPREFIX}/usr/bin/${python_interpreter}" 1814 echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
1474 else 1815 else
1562 else 1903 else
1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 1904 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi 1905 fi
1565 fi 1906 fi
1566 1907
1908 if [[ "${EAPI:-0}" == "0" ]]; then
1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1909 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1568 echo "dev-lang/python:${PYTHON_ABI}" 1910 echo "=dev-lang/python-${PYTHON_ABI}*"
1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1911 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1912 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1913 fi
1914 else
1915 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1916 echo "dev-lang/python:${PYTHON_ABI}"
1917 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1570 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1918 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1919 fi
1571 fi 1920 fi
1572} 1921}
1573 1922
1574# @FUNCTION: python_get_includedir 1923# @FUNCTION: python_get_includedir
1575# @USAGE: [-b|--base-path] [-f|--final-ABI] 1924# @USAGE: [-b|--base-path] [-f|--final-ABI]
1790 die "${FUNCNAME}(): Jython does not have shared library" 2139 die "${FUNCNAME}(): Jython does not have shared library"
1791 fi 2140 fi
1792} 2141}
1793 2142
1794# @FUNCTION: python_get_version 2143# @FUNCTION: python_get_version
1795# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] 2144# @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro]
1796# @DESCRIPTION: 2145# @DESCRIPTION:
1797# Print Python version. 2146# Print version of Python implementation.
1798# --full, --major, --minor and --micro options cannot be specified simultaneously. 2147# --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. 2148# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
2149# If --language option is specified, then version of Python language is printed.
2150# --language and --full options cannot be specified simultaneously.
2151# --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. 2152# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1801python_get_version() { 2153python_get_version() {
1802 _python_check_python_pkg_setup_execution 2154 _python_check_python_pkg_setup_execution
1803 2155
1804 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 2156 local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command
1805 2157
1806 while (($#)); do 2158 while (($#)); do
1807 case "$1" in 2159 case "$1" in
1808 -f|--final-ABI) 2160 -f|--final-ABI)
1809 final_ABI="1" 2161 final_ABI="1"
1810 ;; 2162 ;;
2163 -l|--language)
2164 language="1"
2165 ;;
1811 --full) 2166 --full)
1812 full="1" 2167 full="1"
1813 ;; 2168 ;;
1814 --major) 2169 --major)
1815 major="1" 2170 major="1"
1827 die "${FUNCNAME}(): Invalid usage" 2182 die "${FUNCNAME}(): Invalid usage"
1828 ;; 2183 ;;
1829 esac 2184 esac
1830 shift 2185 shift
1831 done 2186 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 2187
1857 if [[ "${final_ABI}" == "1" ]]; then 2188 if [[ "${final_ABI}" == "1" ]]; then
1858 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2189 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" 2190 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1860 fi 2191 fi
1861 "$(PYTHON -f)" -c "${python_command}"
1862 else 2192 else
1863 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then 2193 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" 2194 die "${FUNCNAME}() should be used in ABI-specific local scope"
1865 fi 2195 fi
2196 fi
2197
2198 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2199 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2200 fi
2201
2202 if [[ "${language}" == "1" ]]; then
2203 if [[ "${final_ABI}" == "1" ]]; then
2204 PYTHON_ABI="$(PYTHON -f --ABI)"
2205 elif [[ -z "${PYTHON_ABI}" ]]; then
2206 PYTHON_ABI="$(PYTHON --ABI)"
2207 fi
2208 language_version="${PYTHON_ABI%%-*}"
2209 if [[ "${full}" == "1" ]]; then
2210 die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously"
2211 elif [[ "${major}" == "1" ]]; then
2212 echo "${language_version%.*}"
2213 elif [[ "${minor}" == "1" ]]; then
2214 echo "${language_version#*.}"
2215 elif [[ "${micro}" == "1" ]]; then
2216 die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously"
2217 else
2218 echo "${language_version}"
2219 fi
2220 else
2221 if [[ "${full}" == "1" ]]; then
2222 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
2223 elif [[ "${major}" == "1" ]]; then
2224 python_command="from sys import version_info; print(version_info[0])"
2225 elif [[ "${minor}" == "1" ]]; then
2226 python_command="from sys import version_info; print(version_info[1])"
2227 elif [[ "${micro}" == "1" ]]; then
2228 python_command="from sys import version_info; print(version_info[2])"
2229 else
2230 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2231 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2232 echo "${PYTHON_ABI}"
2233 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2234 echo "${PYTHON_ABI%-jython}"
2235 fi
2236 return
2237 fi
2238 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2239 fi
2240
2241 if [[ "${final_ABI}" == "1" ]]; then
2242 "$(PYTHON -f)" -c "${python_command}"
2243 else
1866 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2244 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
2245 fi
2246 fi
2247}
2248
2249# @FUNCTION: python_get_implementation_and_version
2250# @USAGE: [-f|--final-ABI]
2251# @DESCRIPTION:
2252# Print name and version of Python implementation.
2253# If version of Python implementation is not bound to version of Python language, then
2254# version of Python language is additionally printed.
2255# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2256python_get_implementation_and_version() {
2257 _python_check_python_pkg_setup_execution
2258
2259 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
2260
2261 while (($#)); do
2262 case "$1" in
2263 -f|--final-ABI)
2264 final_ABI="1"
2265 ;;
2266 -*)
2267 die "${FUNCNAME}(): Unrecognized option '$1'"
2268 ;;
2269 *)
2270 die "${FUNCNAME}(): Invalid usage"
2271 ;;
2272 esac
2273 shift
2274 done
2275
2276 if [[ "${final_ABI}" == "1" ]]; then
2277 if ! _python_package_supporting_installation_for_multiple_python_abis; then
2278 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2279 fi
2280 PYTHON_ABI="$(PYTHON -f --ABI)"
2281 else
2282 if _python_package_supporting_installation_for_multiple_python_abis; then
2283 if ! _python_abi-specific_local_scope; then
2284 die "${FUNCNAME}() should be used in ABI-specific local scope"
2285 fi
2286 else
2287 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2288 fi
2289 fi
2290
2291 if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
2292 echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})"
2293 else
2294 echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}"
1867 fi 2295 fi
1868} 2296}
1869 2297
1870# ================================================================================================ 2298# ================================================================================================
1871# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 2299# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1895# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2323# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1896python_execute_nosetests() { 2324python_execute_nosetests() {
1897 _python_check_python_pkg_setup_execution 2325 _python_check_python_pkg_setup_execution
1898 _python_set_color_variables 2326 _python_set_color_variables
1899 2327
1900 local PYTHONPATH_template= separate_build_dirs= 2328 local PYTHONPATH_template separate_build_dirs
1901 2329
1902 while (($#)); do 2330 while (($#)); do
1903 case "$1" in 2331 case "$1" in
1904 -P|--PYTHONPATH) 2332 -P|--PYTHONPATH)
1905 PYTHONPATH_template="$2" 2333 PYTHONPATH_template="$2"
1959# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2387# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1960python_execute_py.test() { 2388python_execute_py.test() {
1961 _python_check_python_pkg_setup_execution 2389 _python_check_python_pkg_setup_execution
1962 _python_set_color_variables 2390 _python_set_color_variables
1963 2391
1964 local PYTHONPATH_template= separate_build_dirs= 2392 local PYTHONPATH_template separate_build_dirs
1965 2393
1966 while (($#)); do 2394 while (($#)); do
1967 case "$1" in 2395 case "$1" in
1968 -P|--PYTHONPATH) 2396 -P|--PYTHONPATH)
1969 PYTHONPATH_template="$2" 2397 PYTHONPATH_template="$2"
2023# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2451# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2024python_execute_trial() { 2452python_execute_trial() {
2025 _python_check_python_pkg_setup_execution 2453 _python_check_python_pkg_setup_execution
2026 _python_set_color_variables 2454 _python_set_color_variables
2027 2455
2028 local PYTHONPATH_template= separate_build_dirs= 2456 local PYTHONPATH_template separate_build_dirs
2029 2457
2030 while (($#)); do 2458 while (($#)); do
2031 case "$1" in 2459 case "$1" in
2032 -P|--PYTHONPATH) 2460 -P|--PYTHONPATH)
2033 PYTHONPATH_template="$2" 2461 PYTHONPATH_template="$2"
2114 2542
2115_python_clean_compiled_modules() { 2543_python_clean_compiled_modules() {
2116 _python_initialize_prefix_variables 2544 _python_initialize_prefix_variables
2117 _python_set_color_variables 2545 _python_set_color_variables
2118 2546
2119 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2547 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2120 2548
2121 local base_module_name compiled_file compiled_files=() dir path py_file root 2549 local base_module_name compiled_file compiled_files=() dir path py_file root
2122 2550
2123 # Strip trailing slash from EROOT. 2551 # Strip trailing slash from EROOT.
2124 root="${EROOT%/}" 2552 root="${EROOT%/}"
2173 if [[ "${dir}" == "__pycache__" ]]; then 2601 if [[ "${dir}" == "__pycache__" ]]; then
2174 base_module_name="${compiled_file##*/}" 2602 base_module_name="${compiled_file##*/}"
2175 base_module_name="${base_module_name%\$py.class}" 2603 base_module_name="${base_module_name%\$py.class}"
2176 py_file="${compiled_file%__pycache__/*}${base_module_name}.py" 2604 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2177 else 2605 else
2178 py_file="${compiled_file%\$py.class}" 2606 py_file="${compiled_file%\$py.class}.py"
2179 fi 2607 fi
2180 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2608 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2181 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2609 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2182 else 2610 else
2183 [[ -f "${py_file}" ]] && continue 2611 [[ -f "${py_file}" ]] && continue
2201 done 2629 done
2202 done 2630 done
2203} 2631}
2204 2632
2205# @FUNCTION: python_mod_optimize 2633# @FUNCTION: python_mod_optimize
2206# @USAGE: [options] [directory|file] 2634# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
2207# @DESCRIPTION: 2635# @DESCRIPTION:
2208# If no arguments supplied, it will recompile not recursively all modules 2636# 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. 2637# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2215# 2638#
2216# This function can be used only in pkg_postinst() phase. 2639# This function can be used only in pkg_postinst() phase.
2217python_mod_optimize() { 2640python_mod_optimize() {
2641 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
2642 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2643 fi
2644
2218 _python_check_python_pkg_setup_execution 2645 _python_check_python_pkg_setup_execution
2219 _python_initialize_prefix_variables 2646 _python_initialize_prefix_variables
2220 2647
2221 # Check if phase is pkg_postinst(). 2648 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. 2649 # 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=() 2650 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=() stderr stderr_line
2227 2651
2228 if _python_package_supporting_installation_for_multiple_python_abis; then 2652 if _python_package_supporting_installation_for_multiple_python_abis; then
2229 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2653 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2230 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2654 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2231 fi 2655 fi
2270 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2694 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" 2695 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2272 fi 2696 fi
2273 2697
2274 if [[ "$#" -eq 0 ]]; then 2698 if [[ "$#" -eq 0 ]]; then
2275 ewarn 2699 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 2700 fi
2281 2701
2282 while (($#)); do 2702 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2703 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'" 2704 die "${FUNCNAME}(): Invalid argument '$1'"
2330 options+=("-q") 2750 options+=("-q")
2331 2751
2332 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2752 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2333 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then 2753 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2334 return_code="0" 2754 return_code="0"
2755 stderr=""
2335 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2756 ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)"
2336 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then 2757 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2337 for dir in "${site_packages_dirs[@]}"; do 2758 for dir in "${site_packages_dirs[@]}"; do
2338 dirs+=("${root}$(python_get_sitedir)/${dir}") 2759 dirs+=("${root}$(python_get_sitedir)/${dir}")
2339 done 2760 done
2340 for dir in "${evaluated_dirs[@]}"; do 2761 for dir in "${evaluated_dirs[@]}"; do
2341 eval "dirs+=(\"\${root}${dir}\")" 2762 eval "dirs+=(\"\${root}${dir}\")"
2342 done 2763 done
2343 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1" 2764 stderr+="${stderr:+$'\n'}$("$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1"
2344 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2765 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2345 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" 2766 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2346 fi 2767 fi
2347 _python_clean_compiled_modules "${dirs[@]}" 2768 _python_clean_compiled_modules "${dirs[@]}"
2348 fi 2769 fi
2351 files+=("${root}$(python_get_sitedir)/${file}") 2772 files+=("${root}$(python_get_sitedir)/${file}")
2352 done 2773 done
2353 for file in "${evaluated_files[@]}"; do 2774 for file in "${evaluated_files[@]}"; do
2354 eval "files+=(\"\${root}${file}\")" 2775 eval "files+=(\"\${root}${file}\")"
2355 done 2776 done
2356 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1" 2777 stderr+="${stderr:+$'\n'}$("$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" 2>&1)" || return_code="1"
2357 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2778 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2358 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1" 2779 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2359 fi 2780 fi
2360 _python_clean_compiled_modules "${files[@]}" 2781 _python_clean_compiled_modules "${files[@]}"
2361 fi 2782 fi
2362 eend "${return_code}" 2783 eend "${return_code}"
2784 if [[ -n "${stderr}" ]]; then
2785 eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &> /dev/null
2786 while read stderr_line; do
2787 eerror " ${stderr_line}"
2788 done <<< "${stderr}"
2789 fi
2363 fi 2790 fi
2364 unset dirs files 2791 unset dirs files
2365 done 2792 done
2366 2793
2367 if _python_package_supporting_installation_for_multiple_python_abis; then 2794 if _python_package_supporting_installation_for_multiple_python_abis; then
2373 fi 2800 fi
2374 fi 2801 fi
2375 2802
2376 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2803 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
2377 return_code="0" 2804 return_code="0"
2805 stderr=""
2378 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2806 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)"
2379 if ((${#other_dirs[@]})); then 2807 if ((${#other_dirs[@]})); then
2380 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2808 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1"
2381 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2809 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2382 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2810 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2383 fi 2811 fi
2384 _python_clean_compiled_modules "${other_dirs[@]}" 2812 _python_clean_compiled_modules "${other_dirs[@]}"
2385 fi 2813 fi
2386 if ((${#other_files[@]})); then 2814 if ((${#other_files[@]})); then
2387 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2815 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" 2>&1)" || return_code="1"
2388 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2816 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" 2817 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2390 fi 2818 fi
2391 _python_clean_compiled_modules "${other_dirs[@]}" 2819 _python_clean_compiled_modules "${other_files[@]}"
2392 fi 2820 fi
2393 eend "${return_code}" 2821 eend "${return_code}"
2822 if [[ -n "${stderr}" ]]; then
2823 eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &> /dev/null
2824 while read stderr_line; do
2825 eerror " ${stderr_line}"
2826 done <<< "${stderr}"
2827 fi
2394 fi 2828 fi
2395 else 2829 else
2396 # Deprecated part of python_mod_optimize() 2830 # Deprecated part of python_mod_optimize()
2831 ewarn
2832 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2833 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2834 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2835 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2836 ewarn
2397 2837
2398 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2838 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2399 2839
2400 # strip trailing slash 2840 # strip trailing slash
2401 myroot="${EROOT%/}" 2841 myroot="${EROOT%/}"
2423 esac 2863 esac
2424 shift 2864 shift
2425 done 2865 done
2426 2866
2427 if [[ "$#" -eq 0 ]]; then 2867 if [[ "$#" -eq 0 ]]; then
2428 ewarn 2868 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 2869 fi
2434 2870
2435 while (($#)); do 2871 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2872 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'" 2873 die "${FUNCNAME}(): Invalid argument '$1'"
2438 elif [[ -d "${myroot}/${1#/}" ]]; then 2874 elif [[ -d "${myroot}/${1#/}" ]]; then
2439 mydirs+=("${myroot}/${1#/}") 2875 mydirs+=("${myroot}/${1#/}")
2440 elif [[ -f "${myroot}/${1#/}" ]]; then 2876 elif [[ -f "${myroot}/${1#/}" ]]; then
2441 # Files are passed to python_mod_compile which is EROOT-aware 2877 myfiles+=("${myroot}/${1#/}")
2442 myfiles+=("$1")
2443 elif [[ -e "${myroot}/${1#/}" ]]; then 2878 elif [[ -e "${myroot}/${1#/}" ]]; then
2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" 2879 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2445 else 2880 else
2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" 2881 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2447 fi 2882 fi
2459 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2894 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2460 _python_clean_compiled_modules "${mydirs[@]}" 2895 _python_clean_compiled_modules "${mydirs[@]}"
2461 fi 2896 fi
2462 2897
2463 if ((${#myfiles[@]})); then 2898 if ((${#myfiles[@]})); then
2899 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2900 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2464 python_mod_compile "${myfiles[@]}" 2901 _python_clean_compiled_modules "${myfiles[@]}"
2465 fi 2902 fi
2466 2903
2467 eend "${return_code}" 2904 eend "${return_code}"
2468 fi 2905 fi
2469} 2906}
2470 2907
2471# @FUNCTION: python_mod_cleanup 2908# @FUNCTION: python_mod_cleanup
2472# @USAGE: [directory|file] 2909# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2473# @DESCRIPTION: 2910# @DESCRIPTION:
2474# Run with optional arguments, where arguments are Python modules. If none given, 2911# 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# 2912#
2481# This function can be used only in pkg_postrm() phase. 2913# This function can be used only in pkg_postrm() phase.
2482python_mod_cleanup() { 2914python_mod_cleanup() {
2915 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
2916 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2917 fi
2918
2483 _python_check_python_pkg_setup_execution 2919 _python_check_python_pkg_setup_execution
2484 _python_initialize_prefix_variables 2920 _python_initialize_prefix_variables
2485 2921
2486 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2922 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 2923
2491 if _python_package_supporting_installation_for_multiple_python_abis; then 2924 if _python_package_supporting_installation_for_multiple_python_abis; then
2492 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2925 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2493 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2926 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2494 fi 2927 fi
2525 2958
2526 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2959 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" 2960 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2528 fi 2961 fi
2529 2962
2530 if [[ "$#" -gt 0 ]]; then 2963 if [[ "$#" -eq 0 ]]; then
2531 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2964 die "${FUNCNAME}(): Missing files or directories"
2965 fi
2966
2967 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 2968 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2969 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'" 2970 die "${FUNCNAME}(): Invalid argument '$1'"
2535 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2971 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" 2972 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2537 elif [[ "$1" =~ ^/ ]]; then 2973 elif [[ "$1" =~ ^/ ]]; then
2538 if _python_package_supporting_installation_for_multiple_python_abis; then 2974 if _python_package_supporting_installation_for_multiple_python_abis; then
2539 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then 2975 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" 2976 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 2977 fi
2978 if [[ "$1" != *\$* ]]; then
2979 die "${FUNCNAME}(): '$1' has invalid syntax"
2980 fi
2981 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2982 eval "search_paths+=(\"\${root}$1\")"
2983 done
2551 else 2984 else
2985 search_paths+=("${root}$1")
2986 fi
2987 else
2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2988 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2553 search_paths+=("${root}$(python_get_sitedir)/$1") 2989 search_paths+=("${root}$(python_get_sitedir)/$1")
2554 done 2990 done
2555 fi 2991 fi
2556 shift 2992 shift
2557 done 2993 done
2558 else 2994 else
2559 # Deprecated part of python_mod_cleanup() 2995 # Deprecated part of python_mod_cleanup()
2560
2561 search_paths=("${@#/}")
2562 search_paths=("${search_paths[@]/#/${root}/}")
2563 fi
2564 else
2565 ewarn 2996 ewarn
2566 ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" 2997 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." 2998 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2999 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." 3000 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2569 ewarn 3001 ewarn
2570 3002
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}") 3003 search_paths=("${@#/}")
2583 fi 3004 search_paths=("${search_paths[@]/#/${root}/}")
2584 done
2585 fi 3005 fi
2586 3006
2587 _python_clean_compiled_modules "${search_paths[@]}" 3007 _python_clean_compiled_modules "${search_paths[@]}"
2588} 3008}
2589 3009
2590# ================================================================================================ 3010# ================================================================================================
2591# ===================================== DEPRECATED FUNCTIONS ===================================== 3011# ===================================== DEPRECATED FUNCTIONS =====================================
2592# ================================================================================================ 3012# ================================================================================================
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.125

  ViewVC Help
Powered by ViewVC 1.1.20