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

Diff of /eclass/python.eclass

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

Revision 1.101 Revision 1.116
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.101 2010/07/17 23:02:14 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.116 2011/07/04 11:27:53 djc Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
13 13
14if ! has "${EAPI:-0}" 0 1 2 3; then 14if ! has "${EAPI:-0}" 0 1 2 3; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) 19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.0 3.1 3.2 3.3)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
26
27_python_check_python_abi_matching() {
28 local pattern patterns patterns_list="0" PYTHON_ABI
29
30 while (($#)); do
31 case "$1" in
32 --patterns-list)
33 patterns_list="1"
34 ;;
35 --)
36 shift
37 break
38 ;;
39 -*)
40 die "${FUNCNAME}(): Unrecognized option '$1'"
41 ;;
42 *)
43 break
44 ;;
45 esac
46 shift
47 done
48
49 if [[ "$#" -ne 2 ]]; then
50 die "${FUNCNAME}() requires 2 arguments"
51 fi
52
53 PYTHON_ABI="$1"
54
55 if [[ "${patterns_list}" == "0" ]]; then
56 pattern="$2"
57
58 if [[ "${pattern}" == *"-cpython" ]]; then
59 [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]]
60 elif [[ "${pattern}" == *"-jython" ]]; then
61 [[ "${PYTHON_ABI}" == ${pattern} ]]
62 else
63 if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
64 [[ "${PYTHON_ABI}" == ${pattern} ]]
65 elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
66 [[ "${PYTHON_ABI%-jython}" == ${pattern} ]]
67 else
68 die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'"
69 fi
70 fi
71 else
72 patterns="${2// /$'\n'}"
73
74 while read pattern; do
75 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
76 return 0
77 fi
78 done <<< "${patterns}"
79
80 return 1
81 fi
82}
21 83
22# @ECLASS-VARIABLE: PYTHON_DEPEND 84# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 85# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 86# Specification of dependency on dev-lang/python.
25# Syntax: 87# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 89# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 90# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 91# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 92# maximal_version: <maximal_major_version.maximal_minor_version>
31 93
32_parse_PYTHON_DEPEND() { 94_python_parse_PYTHON_DEPEND() {
33 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups 95 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
34 96
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 97 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 98 version_components_groups="${PYTHON_DEPEND}"
37 99
60 fi 122 fi
61 fi 123 fi
62 124
63 if [[ "${major_version}" == "2" ]]; then 125 if [[ "${major_version}" == "2" ]]; then
64 python2="1" 126 python2="1"
65 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 127 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
66 python2_minimal_version="${minimal_version}" 128 python2_minimal_version="${minimal_version}"
67 python2_maximal_version="${maximal_version}" 129 python2_maximal_version="${maximal_version}"
68 elif [[ "${major_version}" == "3" ]]; then 130 elif [[ "${major_version}" == "3" ]]; then
69 python3="1" 131 python3="1"
70 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 132 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
71 python3_minimal_version="${minimal_version}" 133 python3_minimal_version="${minimal_version}"
72 python3_maximal_version="${maximal_version}" 134 python3_maximal_version="${maximal_version}"
73 else 135 else
74 python_all="1" 136 python_all="1"
75 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 137 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
76 python_minimal_version="${minimal_version}" 138 python_minimal_version="${minimal_version}"
77 python_maximal_version="${maximal_version}" 139 python_maximal_version="${maximal_version}"
78 fi 140 fi
79 141
80 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then 142 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
108 170
109 if [[ "${python_all}" == "1" ]]; then 171 if [[ "${python_all}" == "1" ]]; then
110 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then 172 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
111 _PYTHON_ATOMS+=("dev-lang/python") 173 _PYTHON_ATOMS+=("dev-lang/python")
112 else 174 else
113 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}") 175 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
114 python_minimal_version="${python_minimal_version:-${python_versions[0]}}" 176 python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
115 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 177 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
116 _append_accepted_versions_range 178 _append_accepted_versions_range
117 fi 179 fi
118 else 180 else
119 if [[ "${python3}" == "1" ]]; then 181 if [[ "${python3}" == "1" ]]; then
120 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then 182 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
121 _PYTHON_ATOMS+=("=dev-lang/python-3*") 183 _PYTHON_ATOMS+=("=dev-lang/python-3*")
122 else 184 else
123 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}") 185 python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
124 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}" 186 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
125 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 187 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
126 _append_accepted_versions_range 188 _append_accepted_versions_range
127 fi 189 fi
128 fi 190 fi
129 if [[ "${python2}" == "1" ]]; then 191 if [[ "${python2}" == "1" ]]; then
130 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then 192 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
131 _PYTHON_ATOMS+=("=dev-lang/python-2*") 193 _PYTHON_ATOMS+=("=dev-lang/python-2*")
132 else 194 else
133 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}") 195 python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
134 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}" 196 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
135 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}" 197 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
136 _append_accepted_versions_range 198 _append_accepted_versions_range
137 fi 199 fi
138 fi 200 fi
153} 215}
154 216
155DEPEND=">=app-admin/eselect-python-20091230" 217DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 218RDEPEND="${DEPEND}"
157 219
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 220if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 221 _python_parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
165 die "NEED_PYTHON variable cannot be used in this EAPI"
166 fi
167
168 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
169 _RED=$'\e[1;31m'
170 _NORMAL=$'\e[0m'
171 else
172 _RED=
173 _NORMAL=
174 fi
175
176 echo
177 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01.${_NORMAL}"
178 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_DEPEND variable instead of NEED_PYTHON variable.${_NORMAL}"
179 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
180 echo
181
182 unset _BOLD _NORMAL
183
184 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
185 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
186 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
187else 222else
188 _PYTHON_ATOMS=("dev-lang/python") 223 _PYTHON_ATOMS=("dev-lang/python")
224fi
225unset -f _python_parse_PYTHON_DEPEND
226
227if [[ -n "${NEED_PYTHON}" ]]; then
228 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
229 die "NEED_PYTHON variable is banned"
189fi 230fi
190 231
191# @ECLASS-VARIABLE: PYTHON_USE_WITH 232# @ECLASS-VARIABLE: PYTHON_USE_WITH
192# @DESCRIPTION: 233# @DESCRIPTION:
193# Set this to a space separated list of USE flags the Python slot in use must be built with. 234# Set this to a space separated list of USE flags the Python slot in use must be built with.
315 done 356 done
316 fi 357 fi
317 PYTHON_SANITY_CHECKS_EXECUTED="1" 358 PYTHON_SANITY_CHECKS_EXECUTED="1"
318} 359}
319 360
361# @ECLASS-VARIABLE: PYTHON_COLORS
362# @DESCRIPTION:
363# User-configurable colored output.
364PYTHON_COLORS="${PYTHON_COLORS:-0}"
365
320_python_set_color_variables() { 366_python_set_color_variables() {
321 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 367 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
322 _BOLD=$'\e[1m' 368 _BOLD=$'\e[1m'
323 _RED=$'\e[1;31m' 369 _RED=$'\e[1;31m'
324 _GREEN=$'\e[1;32m' 370 _GREEN=$'\e[1;32m'
325 _BLUE=$'\e[1;34m' 371 _BLUE=$'\e[1;34m'
326 _CYAN=$'\e[1;36m' 372 _CYAN=$'\e[1;36m'
349# @DESCRIPTION: 395# @DESCRIPTION:
350# Perform sanity checks and initialize environment. 396# Perform sanity checks and initialize environment.
351# 397#
352# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable 398# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
353# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. 399# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
354#
355# This function can be used only in pkg_setup() phase.
356python_pkg_setup() { 400python_pkg_setup() {
357 # Check if phase is pkg_setup(). 401 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
358 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 402 die "${FUNCNAME}() can be used only in pkg_setup() phase"
403 fi
359 404
360 if [[ "$#" -ne 0 ]]; then 405 if [[ "$#" -ne 0 ]]; then
361 die "${FUNCNAME}() does not accept arguments" 406 die "${FUNCNAME}() does not accept arguments"
362 fi 407 fi
408
409 export JYTHON_SYSTEM_CACHEDIR="1"
410 addwrite "${EPREFIX}/var/cache/jython"
363 411
364 if _python_package_supporting_installation_for_multiple_python_abis; then 412 if _python_package_supporting_installation_for_multiple_python_abis; then
365 _python_calculate_PYTHON_ABIS 413 _python_calculate_PYTHON_ABIS
366 export EPYTHON="$(PYTHON -f)" 414 export EPYTHON="$(PYTHON -f)"
367 else 415 else
410 fi 458 fi
411 459
412 PYTHON_PKG_SETUP_EXECUTED="1" 460 PYTHON_PKG_SETUP_EXECUTED="1"
413} 461}
414 462
415if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 463if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
416 EXPORT_FUNCTIONS pkg_setup 464 EXPORT_FUNCTIONS pkg_setup
417fi 465fi
418 466
467_PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|python)'
468
419# @FUNCTION: python_convert_shebangs 469# @FUNCTION: python_convert_shebangs
420# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 470# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories]
421# @DESCRIPTION: 471# @DESCRIPTION:
422# Convert shebangs in specified files. Directories can be specified only with --recursive option. 472# Convert shebangs in specified files. Directories can be specified only with --recursive option.
423python_convert_shebangs() { 473python_convert_shebangs() {
424 _python_check_python_pkg_setup_execution 474 _python_check_python_pkg_setup_execution
425 475
426 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 476 local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0"
427 477
428 while (($#)); do 478 while (($#)); do
429 case "$1" in 479 case "$1" in
430 -r|--recursive) 480 -r|--recursive)
431 recursive="1" 481 recursive="1"
454 die "${FUNCNAME}(): Missing Python version and files or directories" 504 die "${FUNCNAME}(): Missing Python version and files or directories"
455 elif [[ "$#" -eq 1 ]]; then 505 elif [[ "$#" -eq 1 ]]; then
456 die "${FUNCNAME}(): Missing files or directories" 506 die "${FUNCNAME}(): Missing files or directories"
457 fi 507 fi
458 508
459 python_version="$1" 509 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
510 python_interpreter="$(PYTHON "$1")"
511 else
512 python_interpreter="python$1"
513 fi
460 shift 514 shift
461 515
462 for argument in "$@"; do 516 for argument in "$@"; do
463 if [[ ! -e "${argument}" ]]; then 517 if [[ ! -e "${argument}" ]]; then
464 die "${FUNCNAME}(): '${argument}' does not exist" 518 die "${FUNCNAME}(): '${argument}' does not exist"
479 533
480 for file in "${files[@]}"; do 534 for file in "${files[@]}"; do
481 file="${file#./}" 535 file="${file#./}"
482 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 536 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
483 537
484 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 538 if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
485 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue 539 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
486 540
487 if [[ "${quiet}" == "0" ]]; then 541 if [[ "${quiet}" == "0" ]]; then
488 einfo "Converting shebang in '${file}'" 542 einfo "Converting shebang in '${file}'"
489 fi 543 fi
490 544
491 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 545 sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed"
492
493 # Delete potential whitespace after "#!".
494 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
495 fi 546 fi
496 done 547 done
497} 548}
498 549
499# @FUNCTION: python_clean_installation_image 550# @FUNCTION: python_clean_installation_image
500# @USAGE: [-q|--quiet] 551# @USAGE: [-q|--quiet]
501# @DESCRIPTION: 552# @DESCRIPTION:
502# Delete needless files in installation image. 553# Delete needless files in installation image.
554#
555# This function can be used only in src_install() phase.
503python_clean_installation_image() { 556python_clean_installation_image() {
557 if [[ "${EBUILD_PHASE}" != "install" ]]; then
558 die "${FUNCNAME}() can be used only in src_install() phase"
559 fi
560
504 _python_check_python_pkg_setup_execution 561 _python_check_python_pkg_setup_execution
505 _python_initialize_prefix_variables 562 _python_initialize_prefix_variables
506 563
507 local file files=() quiet="0" 564 local file files=() quiet="0"
508
509 # Check if phase is src_install().
510 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
511 565
512 while (($#)); do 566 while (($#)); do
513 case "$1" in 567 case "$1" in
514 -q|--quiet) 568 -q|--quiet)
515 quiet="1" 569 quiet="1"
566# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 620# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
567# @DESCRIPTION: 621# @DESCRIPTION:
568# Set this in EAPI <= 4 to indicate that current package supports installation for 622# Set this in EAPI <= 4 to indicate that current package supports installation for
569# multiple Python ABIs. 623# multiple Python ABIs.
570 624
625# @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS
626# @DESCRIPTION:
627# Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI
628# patterns specified in this list is skipped.
629
571# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 630# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
572# @DESCRIPTION: 631# @DESCRIPTION:
573# Set this to export phase functions for the following ebuild phases: 632# Set this to export phase functions for the following ebuild phases:
574# src_prepare, src_configure, src_compile, src_test, src_install. 633# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
575if ! has "${EAPI:-0}" 0 1; then 634if ! has "${EAPI:-0}" 0 1; then
576 python_src_prepare() { 635 python_src_prepare() {
577 _python_check_python_pkg_setup_execution 636 if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
637 die "${FUNCNAME}() can be used only in src_prepare() phase"
638 fi
578 639
579 if ! _python_package_supporting_installation_for_multiple_python_abis; then 640 if ! _python_package_supporting_installation_for_multiple_python_abis; then
580 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 641 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
581 fi 642 fi
582 643
644 _python_check_python_pkg_setup_execution
645
583 if [[ "$#" -ne 0 ]]; then 646 if [[ "$#" -ne 0 ]]; then
584 die "${FUNCNAME}() does not accept arguments" 647 die "${FUNCNAME}() does not accept arguments"
585 fi 648 fi
586 649
587 python_copy_sources 650 python_copy_sources
588 } 651 }
589 652
590 for python_default_function in src_configure src_compile src_test src_install; do 653 for python_default_function in src_configure src_compile src_test; do
591 eval "python_${python_default_function}() { 654 eval "python_${python_default_function}() {
592 _python_check_python_pkg_setup_execution 655 if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
656 die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
657 fi
593 658
594 if ! _python_package_supporting_installation_for_multiple_python_abis; then 659 if ! _python_package_supporting_installation_for_multiple_python_abis; then
595 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 660 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
596 fi 661 fi
597 662
663 _python_check_python_pkg_setup_execution
664
598 python_execute_function -d -s -- \"\$@\" 665 python_execute_function -d -s -- \"\$@\"
599 }" 666 }"
600 done 667 done
601 unset python_default_function 668 unset python_default_function
602 669
670 python_src_install() {
671 if [[ "${EBUILD_PHASE}" != "install" ]]; then
672 die "${FUNCNAME}() can be used only in src_install() phase"
673 fi
674
675 if ! _python_package_supporting_installation_for_multiple_python_abis; then
676 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
677 fi
678
679 _python_check_python_pkg_setup_execution
680
681 if has "${EAPI:-0}" 0 1 2 3; then
682 python_execute_function -d -s -- "$@"
683 else
684 python_installation() {
685 emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
686 }
687 python_execute_function -s python_installation "$@"
688 unset python_installation
689
690 python_merge_intermediate_installation_images "${T}/images"
691 fi
692 }
693
603 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 694 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
604 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 695 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
605 fi 696 fi
606fi 697fi
607 698
699if has "${EAPI:-0}" 0 1 2 3 4; then
608unset PYTHON_ABIS 700 unset PYTHON_ABIS
701fi
609 702
610_python_calculate_PYTHON_ABIS() { 703_python_calculate_PYTHON_ABIS() {
611 if ! _python_package_supporting_installation_for_multiple_python_abis; then 704 if ! _python_package_supporting_installation_for_multiple_python_abis; then
612 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 705 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
613 fi 706 fi
614 707
615 _python_initial_sanity_checks 708 _python_initial_sanity_checks
616 709
617 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
618 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 710 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
619 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 711 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
620 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 712
713 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
621 714
622 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 715 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
623 local cpython_enabled="0" 716 local cpython_enabled="0"
624 717
625 if [[ -z "${USE_PYTHON}" ]]; then 718 if [[ -z "${USE_PYTHON}" ]]; then
626 die "USE_PYTHON variable is empty" 719 die "USE_PYTHON variable is empty"
627 fi 720 fi
628 721
629 for PYTHON_ABI in ${USE_PYTHON}; do 722 for PYTHON_ABI in ${USE_PYTHON}; do
630 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 723 if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
631 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 724 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
632 fi 725 fi
633 726
634 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 727 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
635 cpython_enabled="1" 728 cpython_enabled="1"
636 fi 729 fi
637 730
638 support_ABI="1" 731 support_ABI="1"
639 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 732 while read restricted_ABI; do
640 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 733 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
641 support_ABI="0" 734 support_ABI="0"
642 break 735 break
643 fi 736 fi
644 done 737 done <<< "${restricted_ABIs}"
645 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 738 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
646 done 739 done
647 740
648 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 741 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
649 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 742 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
651 744
652 if [[ "${cpython_enabled}" == "0" ]]; then 745 if [[ "${cpython_enabled}" == "0" ]]; then
653 die "USE_PYTHON variable does not enable any CPython ABI" 746 die "USE_PYTHON variable does not enable any CPython ABI"
654 fi 747 fi
655 else 748 else
656 local python_version python2_version= python3_version= support_python_major_version 749 local python_version python2_version python3_version support_python_major_version
657 750
658 if ! has_version "dev-lang/python"; then 751 if ! has_version "dev-lang/python"; then
659 die "${FUNCNAME}(): 'dev-lang/python' is not installed" 752 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
660 fi 753 fi
661 754
666 die "'${EPREFIX}/usr/bin/python2' is not valid symlink" 759 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
667 fi 760 fi
668 761
669 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 762 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
670 763
671 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 764 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
672 support_python_major_version="1" 765 support_python_major_version="1"
673 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 766 while read restricted_ABI; do
674 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 767 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
675 support_python_major_version="0" 768 support_python_major_version="0"
676 fi 769 fi
677 done 770 done <<< "${restricted_ABIs}"
678 [[ "${support_python_major_version}" == "1" ]] && break 771 [[ "${support_python_major_version}" == "1" ]] && break
679 done 772 done
680 if [[ "${support_python_major_version}" == "1" ]]; then 773 if [[ "${support_python_major_version}" == "1" ]]; then
681 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 774 while read restricted_ABI; do
682 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 775 if _python_check_python_abi_matching "${python2_version}" "${restricted_ABI}"; then
683 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 776 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
684 fi 777 fi
685 done 778 done <<< "${restricted_ABIs}"
686 else 779 else
687 python2_version="" 780 python2_version=""
688 fi 781 fi
689 fi 782 fi
690 783
693 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 786 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
694 fi 787 fi
695 788
696 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 789 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
697 790
698 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 791 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
699 support_python_major_version="1" 792 support_python_major_version="1"
700 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 793 while read restricted_ABI; do
701 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 794 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
702 support_python_major_version="0" 795 support_python_major_version="0"
703 fi 796 fi
704 done 797 done <<< "${restricted_ABIs}"
705 [[ "${support_python_major_version}" == "1" ]] && break 798 [[ "${support_python_major_version}" == "1" ]] && break
706 done 799 done
707 if [[ "${support_python_major_version}" == "1" ]]; then 800 if [[ "${support_python_major_version}" == "1" ]]; then
708 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 801 while read restricted_ABI; do
709 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 802 if _python_check_python_abi_matching "${python3_version}" "${restricted_ABI}"; then
710 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 803 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
711 fi 804 fi
712 done 805 done <<< "${restricted_ABIs}"
713 else 806 else
714 python3_version="" 807 python3_version=""
715 fi 808 fi
716 fi 809 fi
717 810
747 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then 840 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
748 pattern="${element%% *}" 841 pattern="${element%% *}"
749 element="${element#* }" 842 element="${element#* }"
750 operator="${element%% *}" 843 operator="${element%% *}"
751 flags="${element#* }" 844 flags="${element#* }"
752 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then 845 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
753 if [[ "${operator}" == "+" ]]; then 846 if [[ "${operator}" == "+" ]]; then
754 eval "export ${variable}+=\"\${variable:+ }${flags}\"" 847 eval "export ${variable}+=\"\${variable:+ }${flags}\""
755 elif [[ "${operator}" == "-" ]]; then 848 elif [[ "${operator}" == "-" ]]; then
756 flags="${flags// /$'\n'}" 849 flags="${flags// /$'\n'}"
757 old_value="${!variable// /$'\n'}" 850 old_value="${!variable// /$'\n'}"
791# @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] 884# @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]
792# @DESCRIPTION: 885# @DESCRIPTION:
793# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 886# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
794# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 887# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
795python_execute_function() { 888python_execute_function() {
796 _python_check_python_pkg_setup_execution
797
798 if ! _python_package_supporting_installation_for_multiple_python_abis; then 889 if ! _python_package_supporting_installation_for_multiple_python_abis; then
799 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 890 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
800 fi 891 fi
801 892
893 _python_check_python_pkg_setup_execution
802 _python_set_color_variables 894 _python_set_color_variables
803 895
804 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= 896 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
805 897
806 while (($#)); do 898 while (($#)); do
807 case "$1" in 899 case "$1" in
808 --action-message) 900 --action-message)
809 action_message_template="$2" 901 action_message_template="$2"
921 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 1013 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
922 else 1014 else
923 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 1015 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
924 fi 1016 fi
925 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1017 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1018 if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
1019 if [[ "${quiet}" == "0" ]]; then
1020 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version) skipped${_NORMAL}"
1021 fi
1022 continue
1023 fi
1024
926 _python_prepare_flags 1025 _python_prepare_flags
927 1026
928 if [[ "${quiet}" == "0" ]]; then 1027 if [[ "${quiet}" == "0" ]]; then
929 if [[ -n "${action_message_template}" ]]; then 1028 if [[ -n "${action_message_template}" ]]; then
930 action_message="$(eval echo -n "${action_message_template}")" 1029 eval "action_message=\"${action_message_template}\""
931 else 1030 else
932 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 1031 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
933 fi 1032 fi
934 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 1033 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
935 fi 1034 fi
959 1058
960 _python_restore_flags 1059 _python_restore_flags
961 1060
962 if [[ "${return_code}" -ne 0 ]]; then 1061 if [[ "${return_code}" -ne 0 ]]; then
963 if [[ -n "${failure_message_template}" ]]; then 1062 if [[ -n "${failure_message_template}" ]]; then
964 failure_message="$(eval echo -n "${failure_message_template}")" 1063 eval "failure_message=\"${failure_message_template}\""
965 else 1064 else
966 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 1065 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
967 fi 1066 fi
968 1067
969 if [[ "${nonfatal}" == "1" ]]; then 1068 if [[ "${nonfatal}" == "1" ]]; then
970 if [[ "${quiet}" == "0" ]]; then 1069 if [[ "${quiet}" == "0" ]]; then
971 ewarn "${_RED}${failure_message}${_NORMAL}" 1070 ewarn "${failure_message}"
972 fi 1071 fi
973 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 1072 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
974 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 1073 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
975 local enabled_PYTHON_ABIS= other_PYTHON_ABI 1074 local enabled_PYTHON_ABIS= other_PYTHON_ABI
976 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 1075 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
977 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 1076 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
978 done 1077 done
979 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 1078 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
980 fi 1079 fi
981 if [[ "${quiet}" == "0" ]]; then 1080 if [[ "${quiet}" == "0" ]]; then
982 ewarn "${_RED}${failure_message}${_NORMAL}" 1081 ewarn "${failure_message}"
983 fi 1082 fi
984 if [[ -z "${PYTHON_ABIS}" ]]; then 1083 if [[ -z "${PYTHON_ABIS}" ]]; then
985 die "${function}() function failed with all enabled Python ABIs" 1084 die "${function}() function failed with all enabled Python ABIs"
986 fi 1085 fi
987 else 1086 else
1024# @FUNCTION: python_copy_sources 1123# @FUNCTION: python_copy_sources
1025# @USAGE: <directory="${S}"> [directory] 1124# @USAGE: <directory="${S}"> [directory]
1026# @DESCRIPTION: 1125# @DESCRIPTION:
1027# Copy unpacked sources of current package to separate build directory for each Python ABI. 1126# Copy unpacked sources of current package to separate build directory for each Python ABI.
1028python_copy_sources() { 1127python_copy_sources() {
1029 _python_check_python_pkg_setup_execution
1030
1031 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1128 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1032 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1129 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1033 fi 1130 fi
1131
1132 _python_check_python_pkg_setup_execution
1034 1133
1035 local dir dirs=() PYTHON_ABI 1134 local dir dirs=() PYTHON_ABI
1036 1135
1037 if [[ "$#" -eq 0 ]]; then 1136 if [[ "$#" -eq 0 ]]; then
1038 if [[ "${WORKDIR}" == "${S}" ]]; then 1137 if [[ "${WORKDIR}" == "${S}" ]]; then
1055# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1154# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1056# @DESCRIPTION: 1155# @DESCRIPTION:
1057# Generate wrapper scripts. Existing files are overwritten only with --force option. 1156# Generate wrapper scripts. Existing files are overwritten only with --force option.
1058# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1157# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1059# respect EPYTHON variable at run time. 1158# respect EPYTHON variable at run time.
1159#
1160# This function can be used only in src_install() phase.
1060python_generate_wrapper_scripts() { 1161python_generate_wrapper_scripts() {
1061 _python_check_python_pkg_setup_execution 1162 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1163 die "${FUNCNAME}() can be used only in src_install() phase"
1164 fi
1062 1165
1063 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1166 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1064 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1167 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1065 fi 1168 fi
1066 1169
1170 _python_check_python_pkg_setup_execution
1067 _python_initialize_prefix_variables 1171 _python_initialize_prefix_variables
1068 1172
1069 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 1173 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1070 1174
1071 while (($#)); do 1175 while (($#)); do
1072 case "$1" in 1176 case "$1" in
1073 -E|--respect-EPYTHON) 1177 -E|--respect-EPYTHON)
1074 respect_EPYTHON="1" 1178 respect_EPYTHON="1"
1096 if [[ "$#" -eq 0 ]]; then 1200 if [[ "$#" -eq 0 ]]; then
1097 die "${FUNCNAME}(): Missing arguments" 1201 die "${FUNCNAME}(): Missing arguments"
1098 fi 1202 fi
1099 1203
1100 _python_calculate_PYTHON_ABIS 1204 _python_calculate_PYTHON_ABIS
1101 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1205 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1102 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1206 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1103 python2_enabled="1" 1207 python2_enabled="1"
1104 fi 1208 fi
1105 done 1209 done
1106 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 1210 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1107 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1211 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1108 python3_enabled="1" 1212 python3_enabled="1"
1109 fi 1213 fi
1110 done 1214 done
1111 1215
1117 eselect_python_option="--python3" 1221 eselect_python_option="--python3"
1118 else 1222 else
1119 die "${FUNCNAME}(): Unsupported environment" 1223 die "${FUNCNAME}(): Unsupported environment"
1120 fi 1224 fi
1121 1225
1226 PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")"
1227
1122 for file in "$@"; do 1228 for file in "$@"; do
1123 if [[ -f "${file}" && "${force}" == "0" ]]; then 1229 if [[ -f "${file}" && "${force}" == "0" ]]; then
1124 die "${FUNCNAME}(): '$1' already exists" 1230 die "${FUNCNAME}(): '${file}' already exists"
1125 fi 1231 fi
1126 1232
1127 if [[ "${quiet}" == "0" ]]; then 1233 if [[ "${quiet}" == "0" ]]; then
1128 einfo "Generating '${file#${ED%/}}' wrapper script" 1234 einfo "Generating '${file#${ED%/}}' wrapper script"
1129 fi 1235 fi
1135import os 1241import os
1136import re 1242import re
1137import subprocess 1243import subprocess
1138import sys 1244import sys
1139 1245
1140EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 1246cpython_re = re.compile(r"^python(\d+\.\d+)$")
1247jython_re = re.compile(r"^jython(\d+\.\d+)$")
1141python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") 1248python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
1142python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") 1249python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1250
1251def get_PYTHON_ABI(EPYTHON):
1252 cpython_matched = cpython_re.match(EPYTHON)
1253 jython_matched = jython_re.match(EPYTHON)
1254 if cpython_matched is not None:
1255 PYTHON_ABI = cpython_matched.group(1)
1256 elif jython_matched is not None:
1257 PYTHON_ABI = jython_matched.group(1) + "-jython"
1258 else:
1259 PYTHON_ABI = None
1260 return PYTHON_ABI
1143 1261
1144EOF 1262EOF
1145 if [[ "$?" != "0" ]]; then 1263 if [[ "$?" != "0" ]]; then
1146 die "${FUNCNAME}(): Generation of '$1' failed" 1264 die "${FUNCNAME}(): Generation of '$1' failed"
1147 fi 1265 fi
1148 if [[ "${respect_EPYTHON}" == "1" ]]; then 1266 if [[ "${respect_EPYTHON}" == "1" ]]; then
1149 cat << EOF >> "${file}" 1267 cat << EOF >> "${file}"
1150EPYTHON = os.environ.get("EPYTHON") 1268EPYTHON = os.environ.get("EPYTHON")
1151if EPYTHON: 1269if EPYTHON:
1152 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1270 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1153 if EPYTHON_matched: 1271 if PYTHON_ABI is None:
1154 PYTHON_ABI = EPYTHON_matched.group(1)
1155 else:
1156 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) 1272 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON)
1157 sys.exit(1) 1273 sys.exit(1)
1158else: 1274else:
1159 try: 1275 try:
1160 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1276 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
1168 if not isinstance(EPYTHON, str): 1284 if not isinstance(EPYTHON, str):
1169 # Python 3 1285 # Python 3
1170 EPYTHON = EPYTHON.decode() 1286 EPYTHON = EPYTHON.decode()
1171 EPYTHON = EPYTHON.rstrip("\n") 1287 EPYTHON = EPYTHON.rstrip("\n")
1172 1288
1173 EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1289 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1174 if EPYTHON_matched: 1290 if PYTHON_ABI is None:
1175 PYTHON_ABI = EPYTHON_matched.group(1)
1176 else:
1177 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1291 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1178 sys.exit(1) 1292 sys.exit(1)
1293
1294wrapper_script_path = os.path.realpath(sys.argv[0])
1295target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1296if not os.path.exists(target_executable_path):
1297 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
1298 sys.exit(1)
1179EOF 1299EOF
1180 if [[ "$?" != "0" ]]; then 1300 if [[ "$?" != "0" ]]; then
1181 die "${FUNCNAME}(): Generation of '$1' failed" 1301 die "${FUNCNAME}(): Generation of '$1' failed"
1182 fi 1302 fi
1183 else 1303 else
1194if not isinstance(EPYTHON, str): 1314if not isinstance(EPYTHON, str):
1195 # Python 3 1315 # Python 3
1196 EPYTHON = EPYTHON.decode() 1316 EPYTHON = EPYTHON.decode()
1197EPYTHON = EPYTHON.rstrip("\n") 1317EPYTHON = EPYTHON.rstrip("\n")
1198 1318
1199EPYTHON_matched = EPYTHON_re.match(EPYTHON) 1319PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1200if EPYTHON_matched: 1320if PYTHON_ABI is None:
1201 PYTHON_ABI = EPYTHON_matched.group(1) 1321 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
1322 sys.exit(1)
1323
1324wrapper_script_path = os.path.realpath(sys.argv[0])
1325for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1326 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1327 if os.path.exists(target_executable_path):
1328 break
1202else: 1329else:
1203 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1330 sys.stderr.write("No target script exists for '%s'\n" % wrapper_script_path)
1204 sys.exit(1) 1331 sys.exit(1)
1205EOF 1332EOF
1206 if [[ "$?" != "0" ]]; then 1333 if [[ "$?" != "0" ]]; then
1207 die "${FUNCNAME}(): Generation of '$1' failed" 1334 die "${FUNCNAME}(): Generation of '$1' failed"
1208 fi 1335 fi
1209 fi 1336 fi
1210 cat << EOF >> "${file}" 1337 cat << EOF >> "${file}"
1211
1212wrapper_script_path = os.path.realpath(sys.argv[0])
1213target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1214os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1215os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1216os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1217if not os.path.exists(target_executable_path):
1218 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
1219 sys.exit(1)
1220 1338
1221target_executable = open(target_executable_path, "rb") 1339target_executable = open(target_executable_path, "rb")
1222target_executable_first_line = target_executable.readline() 1340target_executable_first_line = target_executable.readline()
1223if not isinstance(target_executable_first_line, str): 1341if not isinstance(target_executable_first_line, str):
1224 # Python 3 1342 # Python 3
1225 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1343 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1226 1344
1227python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1345python_shebang_matched = python_shebang_re.match(target_executable_first_line)
1228target_executable.close() 1346target_executable.close()
1229 1347
1230if python_shebang_matched: 1348if python_shebang_matched is not None:
1231 try: 1349 try:
1232 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1350 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1233 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1351 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1234 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1352 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1235 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1353 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1242 python_verification_output = python_verification_output.decode() 1360 python_verification_output = python_verification_output.decode()
1243 1361
1244 if not python_verification_output_re.match(python_verification_output): 1362 if not python_verification_output_re.match(python_verification_output):
1245 raise ValueError 1363 raise ValueError
1246 1364
1365 if cpython_re.match(EPYTHON) is not None:
1366 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1367 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1368 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1369
1370 if hasattr(os, "execv"):
1247 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1371 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
1372 else:
1373 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait())
1374 except (KeyboardInterrupt, SystemExit):
1375 raise
1248 except: 1376 except:
1249 pass 1377 pass
1250 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: 1378 for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
1251 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1379 if variable in os.environ:
1380 del os.environ[variable]
1252 1381
1382if hasattr(os, "execv"):
1253os.execv(target_executable_path, sys.argv) 1383 os.execv(target_executable_path, sys.argv)
1384else:
1385 sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
1254EOF 1386EOF
1255 if [[ "$?" != "0" ]]; then 1387 if [[ "$?" != "0" ]]; then
1256 die "${FUNCNAME}(): Generation of '$1' failed" 1388 die "${FUNCNAME}(): Generation of '$1' failed"
1257 fi 1389 fi
1258 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 1390 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
1259 done 1391 done
1260} 1392}
1261 1393
1394# @ECLASS-VARIABLE: PYTHON_VERSIONED_SCRIPTS
1395# @DESCRIPTION:
1396# Array of regular expressions of paths to versioned Python scripts.
1397# Python scripts in /usr/bin and /usr/sbin are versioned by default.
1398
1399# @ECLASS-VARIABLE: PYTHON_VERSIONED_EXECUTABLES
1400# @DESCRIPTION:
1401# Array of regular expressions of paths to versioned executables (including Python scripts).
1402
1403# @ECLASS-VARIABLE: PYTHON_NONVERSIONED_EXECUTABLES
1404# @DESCRIPTION:
1405# Array of regular expressions of paths to nonversioned executables (including Python scripts).
1406
1407# @FUNCTION: python_merge_intermediate_installation_images
1408# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
1409# @DESCRIPTION:
1410# Merge intermediate installation images into installation image.
1411#
1412# This function can be used only in src_install() phase.
1413python_merge_intermediate_installation_images() {
1414 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1415 die "${FUNCNAME}() can be used only in src_install() phase"
1416 fi
1417
1418 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1419 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1420 fi
1421
1422 _python_check_python_pkg_setup_execution
1423 _python_initialize_prefix_variables
1424
1425 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1426
1427 while (($#)); do
1428 case "$1" in
1429 -q|--quiet)
1430 quiet="1"
1431 ;;
1432 --)
1433 shift
1434 break
1435 ;;
1436 -*)
1437 die "${FUNCNAME}(): Unrecognized option '$1'"
1438 ;;
1439 *)
1440 break
1441 ;;
1442 esac
1443 shift
1444 done
1445
1446 if [[ "$#" -ne 1 ]]; then
1447 die "${FUNCNAME}() requires 1 argument"
1448 fi
1449
1450 intermediate_installation_images_directory="$1"
1451
1452 if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
1453 die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist"
1454 fi
1455
1456 _python_calculate_PYTHON_ABIS
1457 if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
1458 b="b"
1459 fi
1460
1461 while read -d $'\0' -r file; do
1462 files+=("${file}")
1463 done < <("$(PYTHON -f)" -c \
1464"import os
1465import sys
1466
1467if hasattr(sys.stdout, 'buffer'):
1468 # Python 3
1469 stdout = sys.stdout.buffer
1470else:
1471 # Python 2
1472 stdout = sys.stdout
1473
1474files_set = set()
1475
1476os.chdir(${b}'${intermediate_installation_images_directory}')
1477
1478for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
1479 for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
1480 root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
1481 files_set.update(root + ${b}'/' + file for file in files)
1482
1483for file in sorted(files_set):
1484 stdout.write(file)
1485 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images")
1486
1487 for PYTHON_ABI in ${PYTHON_ABIS}; do
1488 if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
1489 die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist"
1490 fi
1491
1492 pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed"
1493
1494 for file in "${files[@]}"; do
1495 version_executable="0"
1496 for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}"; do
1497 if [[ "/${file}" =~ ^${regex}$ ]]; then
1498 version_executable="1"
1499 break
1500 fi
1501 done
1502 for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}"; do
1503 if [[ "/${file}" =~ ^${regex}$ ]]; then
1504 version_executable="2"
1505 break
1506 fi
1507 done
1508 if [[ "${version_executable}" != "0" ]]; then
1509 for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}"; do
1510 if [[ "/${file}" =~ ^${regex}$ ]]; then
1511 version_executable="0"
1512 break
1513 fi
1514 done
1515 fi
1516
1517 [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue
1518
1519 shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed"
1520
1521 if [[ "${version_executable}" == "2" ]]; then
1522 wrapper_scripts+=("${ED}${file}")
1523 elif [[ "${version_executable}" == "1" ]]; then
1524 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
1525 wrapper_scripts+=("${ED}${file}")
1526 else
1527 version_executable="0"
1528 fi
1529 fi
1530
1531 [[ "${version_executable}" == "0" ]] && continue
1532
1533 if [[ -e "${file}-${PYTHON_ABI}" ]]; then
1534 die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists"
1535 fi
1536
1537 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
1538
1539 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
1540 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
1541 fi
1542 done
1543
1544 popd > /dev/null || die "popd failed"
1545
1546 if ROOT="/" has_version sys-apps/coreutils; then
1547 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"
1548 else
1549 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1550 fi
1551 done
1552
1553 rm -fr "${intermediate_installation_images_directory}"
1554
1555 if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
1556 rm -f "${T}/python_wrapper_scripts"
1557
1558 for file in "${wrapper_scripts[@]}"; do
1559 echo -n "${file}" >> "${T}/python_wrapper_scripts"
1560 echo -en "\x00" >> "${T}/python_wrapper_scripts"
1561 done
1562
1563 while read -d $'\0' -r file; do
1564 wrapper_scripts_set+=("${file}")
1565 done < <("$(PYTHON -f)" -c \
1566"import sys
1567
1568if hasattr(sys.stdout, 'buffer'):
1569 # Python 3
1570 stdout = sys.stdout.buffer
1571else:
1572 # Python 2
1573 stdout = sys.stdout
1574
1575files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00'))
1576
1577for file in sorted(files):
1578 stdout.write(file)
1579 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1580
1581 python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}"
1582 fi
1583}
1584
1262# ================================================================================================ 1585# ================================================================================================
1263# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1586# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1264# ================================================================================================ 1587# ================================================================================================
1265 1588
1266unset EPYTHON PYTHON_ABI 1589unset EPYTHON PYTHON_ABI
1267 1590
1268# @FUNCTION: python_set_active_version 1591# @FUNCTION: python_set_active_version
1269# @USAGE: <CPython_ABI|2|3> 1592# @USAGE: <Python_ABI|2|3>
1270# @DESCRIPTION: 1593# @DESCRIPTION:
1271# Set specified version of CPython as active version of Python. 1594# Set locally active version of Python.
1595# If Python_ABI argument is specified, then version of Python corresponding to Python_ABI is used.
1596# If 2 argument is specified, then active version of CPython 2 is used.
1597# If 3 argument is specified, then active version of CPython 3 is used.
1272# 1598#
1273# This function can be used only in pkg_setup() phase. 1599# This function can be used only in pkg_setup() phase.
1274python_set_active_version() { 1600python_set_active_version() {
1275 # Check if phase is pkg_setup(). 1601 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1276 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 1602 die "${FUNCNAME}() can be used only in pkg_setup() phase"
1603 fi
1277 1604
1278 if _python_package_supporting_installation_for_multiple_python_abis; then 1605 if _python_package_supporting_installation_for_multiple_python_abis; then
1279 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1606 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1280 fi 1607 fi
1281 1608
1284 fi 1611 fi
1285 1612
1286 _python_initial_sanity_checks 1613 _python_initial_sanity_checks
1287 1614
1288 if [[ -z "${PYTHON_ABI}" ]]; then 1615 if [[ -z "${PYTHON_ABI}" ]]; then
1289 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1616 if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
1290 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1617 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1291 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1618 # so it does not need to be exported to subprocesses.
1619 PYTHON_ABI="$1"
1620 if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
1621 die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed"
1292 fi 1622 fi
1293 export EPYTHON="$(PYTHON "$1")" 1623 export EPYTHON="$(PYTHON "$1")"
1294 elif [[ "$1" == "2" ]]; then 1624 elif [[ "$1" == "2" ]]; then
1295 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1625 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1296 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1626 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1297 fi 1627 fi
1298 export EPYTHON="$(PYTHON -2)" 1628 export EPYTHON="$(PYTHON -2)"
1629 PYTHON_ABI="${EPYTHON#python}"
1630 PYTHON_ABI="${PYTHON_ABI%%-*}"
1299 elif [[ "$1" == "3" ]]; then 1631 elif [[ "$1" == "3" ]]; then
1300 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1632 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1301 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1633 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1302 fi 1634 fi
1303 export EPYTHON="$(PYTHON -3)" 1635 export EPYTHON="$(PYTHON -3)"
1636 PYTHON_ABI="${EPYTHON#python}"
1637 PYTHON_ABI="${PYTHON_ABI%%-*}"
1304 else 1638 else
1305 die "${FUNCNAME}(): Unrecognized argument '$1'" 1639 die "${FUNCNAME}(): Unrecognized argument '$1'"
1306 fi 1640 fi
1307
1308 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1309 # so it does not need to be exported to subprocesses.
1310 PYTHON_ABI="${EPYTHON#python}"
1311 PYTHON_ABI="${PYTHON_ABI%%-*}"
1312 fi 1641 fi
1313 1642
1314 _python_final_sanity_checks 1643 _python_final_sanity_checks
1315 1644
1316 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1645 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1319 1648
1320# @FUNCTION: python_need_rebuild 1649# @FUNCTION: python_need_rebuild
1321# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1650# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1322# switching of active version of Python. 1651# switching of active version of Python.
1323python_need_rebuild() { 1652python_need_rebuild() {
1324 _python_check_python_pkg_setup_execution
1325
1326 if _python_package_supporting_installation_for_multiple_python_abis; then 1653 if _python_package_supporting_installation_for_multiple_python_abis; then
1327 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1654 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1328 fi 1655 fi
1656
1657 _python_check_python_pkg_setup_execution
1329 1658
1330 if [[ "$#" -ne 0 ]]; then 1659 if [[ "$#" -ne 0 ]]; then
1331 die "${FUNCNAME}() does not accept arguments" 1660 die "${FUNCNAME}() does not accept arguments"
1332 fi 1661 fi
1333 1662
1343sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) 1672sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
1344if platform.system()[:4] == "Java": 1673if platform.system()[:4] == "Java":
1345 sys.stdout.write("-jython")' 1674 sys.stdout.write("-jython")'
1346 1675
1347_python_get_implementation() { 1676_python_get_implementation() {
1677 local ignore_invalid="0"
1678
1679 while (($#)); do
1680 case "$1" in
1681 --ignore-invalid)
1682 ignore_invalid="1"
1683 ;;
1684 --)
1685 shift
1686 break
1687 ;;
1688 -*)
1689 die "${FUNCNAME}(): Unrecognized option '$1'"
1690 ;;
1691 *)
1692 break
1693 ;;
1694 esac
1695 shift
1696 done
1697
1348 if [[ "$#" -ne 1 ]]; then 1698 if [[ "$#" -ne 1 ]]; then
1349 die "${FUNCNAME}() requires 1 argument" 1699 die "${FUNCNAME}() requires 1 argument"
1350 fi 1700 fi
1351 1701
1352 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1702 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1353 echo "CPython" 1703 echo "CPython"
1354 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then 1704 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
1355 echo "Jython" 1705 echo "Jython"
1356 else 1706 else
1707 if [[ "${ignore_invalid}" == "0" ]]; then
1357 die "${FUNCNAME}(): Unrecognized Python ABI '$1'" 1708 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
1709 fi
1358 fi 1710 fi
1359} 1711}
1360 1712
1361# @FUNCTION: PYTHON 1713# @FUNCTION: PYTHON
1362# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 1714# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
1363# @DESCRIPTION: 1715# @DESCRIPTION:
1364# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument 1716# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument
1365# is ommitted, then PYTHON_ABI environment variable must be set and is used. 1717# is ommitted, then PYTHON_ABI environment variable must be set and is used.
1366# If -2 option is specified, then active version of Python 2 is used. 1718# If -2 option is specified, then active version of CPython 2 is used.
1367# If -3 option is specified, then active version of Python 3 is used. 1719# If -3 option is specified, then active version of CPython 3 is used.
1368# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1720# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1369# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously. 1721# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
1370# If --ABI option is specified, then only specified Python ABI is printed instead of 1722# If --ABI option is specified, then only specified Python ABI is printed instead of
1371# filename of Python interpreter. 1723# filename of Python interpreter.
1372# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1724# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1423 _python_calculate_PYTHON_ABIS 1775 _python_calculate_PYTHON_ABIS
1424 PYTHON_ABI="${PYTHON_ABIS##* }" 1776 PYTHON_ABI="${PYTHON_ABIS##* }"
1425 elif [[ "${python2}" == "1" ]]; then 1777 elif [[ "${python2}" == "1" ]]; then
1426 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1778 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1427 if [[ -z "${PYTHON_ABI}" ]]; then 1779 if [[ -z "${PYTHON_ABI}" ]]; then
1428 die "${FUNCNAME}(): Active version of Python 2 not set" 1780 die "${FUNCNAME}(): Active version of CPython 2 not set"
1429 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1781 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1430 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1782 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1431 fi 1783 fi
1432 elif [[ "${python3}" == "1" ]]; then 1784 elif [[ "${python3}" == "1" ]]; then
1433 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1785 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1434 if [[ -z "${PYTHON_ABI}" ]]; then 1786 if [[ -z "${PYTHON_ABI}" ]]; then
1435 die "${FUNCNAME}(): Active version of Python 3 not set" 1787 die "${FUNCNAME}(): Active version of CPython 3 not set"
1436 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1788 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1437 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1789 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1438 fi 1790 fi
1439 elif _python_package_supporting_installation_for_multiple_python_abis; then 1791 elif _python_package_supporting_installation_for_multiple_python_abis; then
1440 if ! _python_abi-specific_local_scope; then 1792 if ! _python_abi-specific_local_scope; then
1466 return 1818 return
1467 else 1819 else
1468 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1820 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1469 python_interpreter="python${PYTHON_ABI}" 1821 python_interpreter="python${PYTHON_ABI}"
1470 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1822 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1471 python_interpreter="jython-${PYTHON_ABI%-jython}" 1823 python_interpreter="jython${PYTHON_ABI%-jython}"
1472 fi 1824 fi
1473 1825
1474 if [[ "${absolute_path_output}" == "1" ]]; then 1826 if [[ "${absolute_path_output}" == "1" ]]; then
1475 echo -n "${EPREFIX}/usr/bin/${python_interpreter}" 1827 echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
1476 else 1828 else
1564 else 1916 else
1565 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 1917 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1566 fi 1918 fi
1567 fi 1919 fi
1568 1920
1921 if [[ "${EAPI:-0}" == "0" ]]; then
1569 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1922 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1570 echo "dev-lang/python:${PYTHON_ABI}" 1923 echo "=dev-lang/python-${PYTHON_ABI}*"
1571 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1924 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1925 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1926 fi
1927 else
1928 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1929 echo "dev-lang/python:${PYTHON_ABI}"
1930 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1572 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1931 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1932 fi
1573 fi 1933 fi
1574} 1934}
1575 1935
1576# @FUNCTION: python_get_includedir 1936# @FUNCTION: python_get_includedir
1577# @USAGE: [-b|--base-path] [-f|--final-ABI] 1937# @USAGE: [-b|--base-path] [-f|--final-ABI]
1897# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2257# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1898python_execute_nosetests() { 2258python_execute_nosetests() {
1899 _python_check_python_pkg_setup_execution 2259 _python_check_python_pkg_setup_execution
1900 _python_set_color_variables 2260 _python_set_color_variables
1901 2261
1902 local PYTHONPATH_template= separate_build_dirs= 2262 local PYTHONPATH_template separate_build_dirs
1903 2263
1904 while (($#)); do 2264 while (($#)); do
1905 case "$1" in 2265 case "$1" in
1906 -P|--PYTHONPATH) 2266 -P|--PYTHONPATH)
1907 PYTHONPATH_template="$2" 2267 PYTHONPATH_template="$2"
1925 done 2285 done
1926 2286
1927 python_test_function() { 2287 python_test_function() {
1928 local evaluated_PYTHONPATH 2288 local evaluated_PYTHONPATH
1929 2289
1930 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2290 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1931 2291
1932 _python_test_hook pre 2292 _python_test_hook pre
1933 2293
1934 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2294 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1935 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2295 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1961# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2321# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1962python_execute_py.test() { 2322python_execute_py.test() {
1963 _python_check_python_pkg_setup_execution 2323 _python_check_python_pkg_setup_execution
1964 _python_set_color_variables 2324 _python_set_color_variables
1965 2325
1966 local PYTHONPATH_template= separate_build_dirs= 2326 local PYTHONPATH_template separate_build_dirs
1967 2327
1968 while (($#)); do 2328 while (($#)); do
1969 case "$1" in 2329 case "$1" in
1970 -P|--PYTHONPATH) 2330 -P|--PYTHONPATH)
1971 PYTHONPATH_template="$2" 2331 PYTHONPATH_template="$2"
1989 done 2349 done
1990 2350
1991 python_test_function() { 2351 python_test_function() {
1992 local evaluated_PYTHONPATH 2352 local evaluated_PYTHONPATH
1993 2353
1994 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2354 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1995 2355
1996 _python_test_hook pre 2356 _python_test_hook pre
1997 2357
1998 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2358 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1999 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 2359 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
2025# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2385# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2026python_execute_trial() { 2386python_execute_trial() {
2027 _python_check_python_pkg_setup_execution 2387 _python_check_python_pkg_setup_execution
2028 _python_set_color_variables 2388 _python_set_color_variables
2029 2389
2030 local PYTHONPATH_template= separate_build_dirs= 2390 local PYTHONPATH_template separate_build_dirs
2031 2391
2032 while (($#)); do 2392 while (($#)); do
2033 case "$1" in 2393 case "$1" in
2034 -P|--PYTHONPATH) 2394 -P|--PYTHONPATH)
2035 PYTHONPATH_template="$2" 2395 PYTHONPATH_template="$2"
2053 done 2413 done
2054 2414
2055 python_test_function() { 2415 python_test_function() {
2056 local evaluated_PYTHONPATH 2416 local evaluated_PYTHONPATH
2057 2417
2058 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2418 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2059 2419
2060 _python_test_hook pre 2420 _python_test_hook pre
2061 2421
2062 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2422 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2063 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2423 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2116 2476
2117_python_clean_compiled_modules() { 2477_python_clean_compiled_modules() {
2118 _python_initialize_prefix_variables 2478 _python_initialize_prefix_variables
2119 _python_set_color_variables 2479 _python_set_color_variables
2120 2480
2121 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2481 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2122 2482
2123 local base_module_name compiled_file compiled_files=() dir path py_file root 2483 local base_module_name compiled_file compiled_files=() dir path py_file root
2124 2484
2125 # Strip trailing slash from EROOT. 2485 # Strip trailing slash from EROOT.
2126 root="${EROOT%/}" 2486 root="${EROOT%/}"
2175 if [[ "${dir}" == "__pycache__" ]]; then 2535 if [[ "${dir}" == "__pycache__" ]]; then
2176 base_module_name="${compiled_file##*/}" 2536 base_module_name="${compiled_file##*/}"
2177 base_module_name="${base_module_name%\$py.class}" 2537 base_module_name="${base_module_name%\$py.class}"
2178 py_file="${compiled_file%__pycache__/*}${base_module_name}.py" 2538 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2179 else 2539 else
2180 py_file="${compiled_file%\$py.class}" 2540 py_file="${compiled_file%\$py.class}.py"
2181 fi 2541 fi
2182 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2542 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2183 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2543 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2184 else 2544 else
2185 [[ -f "${py_file}" ]] && continue 2545 [[ -f "${py_file}" ]] && continue
2203 done 2563 done
2204 done 2564 done
2205} 2565}
2206 2566
2207# @FUNCTION: python_mod_optimize 2567# @FUNCTION: python_mod_optimize
2208# @USAGE: [options] [directory|file] 2568# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
2209# @DESCRIPTION: 2569# @DESCRIPTION:
2210# If no arguments supplied, it will recompile not recursively all modules 2570# Byte-compile specified Python modules.
2211# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
2212#
2213# If supplied with arguments, it will recompile all modules recursively
2214# in the supplied directory.
2215#
2216# Options passed to this function are passed to compileall.py. 2571# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2217# 2572#
2218# This function can be used only in pkg_postinst() phase. 2573# This function can be used only in pkg_postinst() phase.
2219python_mod_optimize() { 2574python_mod_optimize() {
2575 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
2576 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2577 fi
2578
2220 _python_check_python_pkg_setup_execution 2579 _python_check_python_pkg_setup_execution
2221 _python_initialize_prefix_variables 2580 _python_initialize_prefix_variables
2222 2581
2223 # Check if phase is pkg_postinst(). 2582 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2224 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2225
2226 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2227 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2583 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2228 local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 2584 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=()
2229 2585
2230 if _python_package_supporting_installation_for_multiple_python_abis; then 2586 if _python_package_supporting_installation_for_multiple_python_abis; then
2231 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2587 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2232 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2588 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2233 fi 2589 fi
2243 # Strip trailing slash from EROOT. 2599 # Strip trailing slash from EROOT.
2244 root="${EROOT%/}" 2600 root="${EROOT%/}"
2245 2601
2246 while (($#)); do 2602 while (($#)); do
2247 case "$1" in 2603 case "$1" in
2604 --allow-evaluated-non-sitedir-paths)
2605 allow_evaluated_non_sitedir_paths="1"
2606 ;;
2248 -l|-f|-q) 2607 -l|-f|-q)
2249 options+=("$1") 2608 options+=("$1")
2250 ;; 2609 ;;
2251 -d|-x) 2610 -d|-x)
2252 options+=("$1" "$2") 2611 options+=("$1" "$2")
2264 ;; 2623 ;;
2265 esac 2624 esac
2266 shift 2625 shift
2267 done 2626 done
2268 2627
2628 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2629 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2630 fi
2631
2269 if [[ "$#" -eq 0 ]]; then 2632 if [[ "$#" -eq 0 ]]; then
2270 _python_set_color_variables 2633 die "${FUNCNAME}(): Missing files or directories"
2271
2272 echo
2273 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2274 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2275 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2276 echo
2277
2278 einfo &> /dev/null
2279 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2280 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2281 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2282 einfo &> /dev/null
2283 fi 2634 fi
2284 2635
2285 while (($#)); do 2636 while (($#)); do
2286 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2637 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2287 die "${FUNCNAME}(): Invalid argument '$1'" 2638 die "${FUNCNAME}(): Invalid argument '$1'"
2288 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2639 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2289 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2640 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2290 elif [[ "$1" =~ ^/ ]]; then 2641 elif [[ "$1" =~ ^/ ]]; then
2291 if _python_package_supporting_installation_for_multiple_python_abis; then 2642 if _python_package_supporting_installation_for_multiple_python_abis; then
2643 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2292 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2644 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2293 fi 2645 fi
2294 if [[ -d "${root}$1" ]]; then 2646 if [[ "$1" != *\$* ]]; then
2295 other_dirs+=("${root}$1") 2647 die "${FUNCNAME}(): '$1' has invalid syntax"
2296 elif [[ -f "${root}$1" ]]; then 2648 fi
2297 other_files+=("${root}$1") 2649 if [[ "$1" == *.py ]]; then
2298 elif [[ -e "${root}$1" ]]; then 2650 evaluated_files+=("$1")
2299 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory" 2651 else
2652 evaluated_dirs+=("$1")
2653 fi
2300 else 2654 else
2655 if [[ -d "${root}$1" ]]; then
2656 other_dirs+=("${root}$1")
2657 elif [[ -f "${root}$1" ]]; then
2658 other_files+=("${root}$1")
2659 elif [[ -e "${root}$1" ]]; then
2660 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2661 else
2301 eerror "${FUNCNAME}(): '${root}$1' does not exist" 2662 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2663 fi
2302 fi 2664 fi
2303 else 2665 else
2304 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2666 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2305 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 2667 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2306 site_packages_dirs+=("$1") 2668 site_packages_dirs+=("$1")
2320 2682
2321 # Set additional options. 2683 # Set additional options.
2322 options+=("-q") 2684 options+=("-q")
2323 2685
2324 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2686 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2325 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2687 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2326 return_code="0" 2688 return_code="0"
2327 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2689 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
2328 if ((${#site_packages_dirs[@]})); then 2690 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2329 for dir in "${site_packages_dirs[@]}"; do 2691 for dir in "${site_packages_dirs[@]}"; do
2330 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2692 dirs+=("${root}$(python_get_sitedir)/${dir}")
2331 done 2693 done
2694 for dir in "${evaluated_dirs[@]}"; do
2695 eval "dirs+=(\"\${root}${dir}\")"
2696 done
2332 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2697 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
2333 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2698 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2334 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2699 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2335 fi 2700 fi
2336 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" 2701 _python_clean_compiled_modules "${dirs[@]}"
2337 fi 2702 fi
2338 if ((${#site_packages_files[@]})); then 2703 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2339 for file in "${site_packages_files[@]}"; do 2704 for file in "${site_packages_files[@]}"; do
2340 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2705 files+=("${root}$(python_get_sitedir)/${file}")
2341 done 2706 done
2707 for file in "${evaluated_files[@]}"; do
2708 eval "files+=(\"\${root}${file}\")"
2709 done
2342 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2710 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
2343 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2711 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2344 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2712 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2345 fi 2713 fi
2346 _python_clean_compiled_modules "${site_packages_absolute_files[@]}" 2714 _python_clean_compiled_modules "${files[@]}"
2347 fi 2715 fi
2348 eend "${return_code}" 2716 eend "${return_code}"
2349 fi 2717 fi
2350 unset site_packages_absolute_dirs site_packages_absolute_files 2718 unset dirs files
2351 done 2719 done
2352 2720
2353 if _python_package_supporting_installation_for_multiple_python_abis; then 2721 if _python_package_supporting_installation_for_multiple_python_abis; then
2354 # Restore previous value of PYTHON_ABI. 2722 # Restore previous value of PYTHON_ABI.
2355 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2723 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2372 if ((${#other_files[@]})); then 2740 if ((${#other_files[@]})); then
2373 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2741 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2374 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2742 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2375 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2743 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2376 fi 2744 fi
2377 _python_clean_compiled_modules "${other_dirs[@]}" 2745 _python_clean_compiled_modules "${other_files[@]}"
2378 fi 2746 fi
2379 eend "${return_code}" 2747 eend "${return_code}"
2380 fi 2748 fi
2381 else 2749 else
2382 # Deprecated part of python_mod_optimize() 2750 # Deprecated part of python_mod_optimize()
2751 ewarn
2752 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2753 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2754 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2755 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2756 ewarn
2383 2757
2384 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2758 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2385 2759
2386 # strip trailing slash 2760 # strip trailing slash
2387 myroot="${EROOT%/}" 2761 myroot="${EROOT%/}"
2409 esac 2783 esac
2410 shift 2784 shift
2411 done 2785 done
2412 2786
2413 if [[ "$#" -eq 0 ]]; then 2787 if [[ "$#" -eq 0 ]]; then
2414 _python_set_color_variables 2788 die "${FUNCNAME}(): Missing files or directories"
2415
2416 echo
2417 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2418 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2419 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2420 echo
2421
2422 einfo &> /dev/null
2423 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2424 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2425 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2426 einfo &> /dev/null
2427 fi 2789 fi
2428 2790
2429 while (($#)); do 2791 while (($#)); do
2430 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2792 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2431 die "${FUNCNAME}(): Invalid argument '$1'" 2793 die "${FUNCNAME}(): Invalid argument '$1'"
2432 elif [[ -d "${myroot}/${1#/}" ]]; then 2794 elif [[ -d "${myroot}/${1#/}" ]]; then
2433 mydirs+=("${myroot}/${1#/}") 2795 mydirs+=("${myroot}/${1#/}")
2434 elif [[ -f "${myroot}/${1#/}" ]]; then 2796 elif [[ -f "${myroot}/${1#/}" ]]; then
2435 # Files are passed to python_mod_compile which is EROOT-aware 2797 myfiles+=("${myroot}/${1#/}")
2436 myfiles+=("$1")
2437 elif [[ -e "${myroot}/${1#/}" ]]; then 2798 elif [[ -e "${myroot}/${1#/}" ]]; then
2438 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" 2799 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2439 else 2800 else
2440 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" 2801 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2441 fi 2802 fi
2453 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2814 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2454 _python_clean_compiled_modules "${mydirs[@]}" 2815 _python_clean_compiled_modules "${mydirs[@]}"
2455 fi 2816 fi
2456 2817
2457 if ((${#myfiles[@]})); then 2818 if ((${#myfiles[@]})); then
2819 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2820 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2458 python_mod_compile "${myfiles[@]}" 2821 _python_clean_compiled_modules "${myfiles[@]}"
2459 fi 2822 fi
2460 2823
2461 eend "${return_code}" 2824 eend "${return_code}"
2462 fi 2825 fi
2463} 2826}
2464 2827
2465# @FUNCTION: python_mod_cleanup 2828# @FUNCTION: python_mod_cleanup
2466# @USAGE: [directory|file] 2829# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2467# @DESCRIPTION: 2830# @DESCRIPTION:
2468# Run with optional arguments, where arguments are Python modules. If none given, 2831# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2469# it will look in /usr/lib/python[0-9].[0-9].
2470#
2471# It will recursively scan all compiled Python modules in the directories and
2472# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2473# If they are, then it will remove their corresponding .pyc and .pyo files.
2474# 2832#
2475# This function can be used only in pkg_postrm() phase. 2833# This function can be used only in pkg_postrm() phase.
2476python_mod_cleanup() { 2834python_mod_cleanup() {
2835 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
2836 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2837 fi
2838
2477 _python_check_python_pkg_setup_execution 2839 _python_check_python_pkg_setup_execution
2478 _python_initialize_prefix_variables 2840 _python_initialize_prefix_variables
2479 2841
2480 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2842 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2481
2482 # Check if phase is pkg_postrm().
2483 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2484 2843
2485 if _python_package_supporting_installation_for_multiple_python_abis; then 2844 if _python_package_supporting_installation_for_multiple_python_abis; then
2486 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2845 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2487 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2846 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2488 fi 2847 fi
2496 fi 2855 fi
2497 2856
2498 # Strip trailing slash from EROOT. 2857 # Strip trailing slash from EROOT.
2499 root="${EROOT%/}" 2858 root="${EROOT%/}"
2500 2859
2860 while (($#)); do
2861 case "$1" in
2862 --allow-evaluated-non-sitedir-paths)
2863 allow_evaluated_non_sitedir_paths="1"
2864 ;;
2865 --)
2866 shift
2867 break
2868 ;;
2869 -*)
2870 die "${FUNCNAME}(): Unrecognized option '$1'"
2871 ;;
2872 *)
2873 break
2874 ;;
2875 esac
2876 shift
2877 done
2878
2879 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2880 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2881 fi
2882
2501 if [[ "$#" -gt 0 ]]; then 2883 if [[ "$#" -eq 0 ]]; then
2502 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2884 die "${FUNCNAME}(): Missing files or directories"
2885 fi
2886
2887 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2503 while (($#)); do 2888 while (($#)); do
2504 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2889 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2505 die "${FUNCNAME}(): Invalid argument '$1'" 2890 die "${FUNCNAME}(): Invalid argument '$1'"
2506 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2891 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2507 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2892 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2508 elif [[ "$1" =~ ^/ ]]; then 2893 elif [[ "$1" =~ ^/ ]]; then
2509 if _python_package_supporting_installation_for_multiple_python_abis; then 2894 if _python_package_supporting_installation_for_multiple_python_abis; then
2895 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2510 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2896 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2511 fi 2897 fi
2898 if [[ "$1" != *\$* ]]; then
2899 die "${FUNCNAME}(): '$1' has invalid syntax"
2900 fi
2901 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2902 eval "search_paths+=(\"\${root}$1\")"
2903 done
2904 else
2512 search_paths+=("${root}$1") 2905 search_paths+=("${root}$1")
2906 fi
2513 else 2907 else
2514 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2908 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2515 search_paths+=("${root}$(python_get_sitedir)/$1") 2909 search_paths+=("${root}$(python_get_sitedir)/$1")
2516 done
2517 fi
2518 shift
2519 done
2520 else
2521 # Deprecated part of python_mod_cleanup()
2522
2523 search_paths=("${@#/}")
2524 search_paths=("${search_paths[@]/#/${root}/}")
2525 fi
2526 else
2527 _python_set_color_variables
2528
2529 echo
2530 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2531 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2532 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2533 echo
2534
2535 einfo &> /dev/null
2536 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2537 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2538 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2539 einfo &> /dev/null
2540
2541 for dir in "${root}"/usr/lib*; do
2542 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2543 for sitedir in "${dir}"/python*/site-packages; do
2544 if [[ -d "${sitedir}" ]]; then
2545 search_paths+=("${sitedir}")
2546 fi
2547 done 2910 done
2548 fi 2911 fi
2912 shift
2549 done 2913 done
2550 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2914 else
2551 if [[ -d "${sitedir}" ]]; then 2915 # Deprecated part of python_mod_cleanup()
2916 ewarn
2917 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2918 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
2919 ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2920 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2921 ewarn
2922
2552 search_paths+=("${sitedir}") 2923 search_paths=("${@#/}")
2553 fi 2924 search_paths=("${search_paths[@]/#/${root}/}")
2554 done
2555 fi 2925 fi
2556 2926
2557 _python_clean_compiled_modules "${search_paths[@]}" 2927 _python_clean_compiled_modules "${search_paths[@]}"
2558} 2928}
2559 2929
2560# ================================================================================================ 2930# ================================================================================================
2561# ===================================== DEPRECATED FUNCTIONS ===================================== 2931# ===================================== DEPRECATED FUNCTIONS =====================================
2562# ================================================================================================ 2932# ================================================================================================
2563
2564# Scheduled for deletion on 2011-01-01.
2565python_version() {
2566 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2567 die "${FUNCNAME}() is banned"
2568}
2569
2570# Scheduled for deletion on 2011-01-01.
2571python_mod_exists() {
2572 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2573 die "${FUNCNAME}() is banned"
2574}
2575
2576# Scheduled for deletion on 2011-01-01.
2577python_tkinter_exists() {
2578 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2579 die "${FUNCNAME}() is banned"
2580}
2581
2582# @FUNCTION: python_mod_compile
2583# @USAGE: <file> [more files ...]
2584# @DESCRIPTION:
2585# Given filenames, it will pre-compile the module's .pyc and .pyo.
2586# This function can be used only in pkg_postinst() phase.
2587#
2588# Example:
2589# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2590#
2591python_mod_compile() {
2592 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2593 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2594 die "${FUNCNAME}() cannot be used in this EAPI"
2595 fi
2596
2597 _python_initialize_prefix_variables
2598 _python_set_color_variables
2599
2600 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2601 echo
2602 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2603 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2604 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2605 echo
2606
2607 einfo &> /dev/null
2608 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2609 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2610 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2611 einfo &> /dev/null
2612 fi
2613
2614 local f myroot myfiles=()
2615
2616 # Check if phase is pkg_postinst()
2617 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2618
2619 # strip trailing slash
2620 myroot="${EROOT%/}"
2621
2622 # respect EROOT
2623 for f in "$@"; do
2624 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2625 done
2626
2627 PYTHON_ABI="$(PYTHON --ABI)"
2628
2629 if ((${#myfiles[@]})); then
2630 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2631 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2632 _python_clean_compiled_modules "${myfiles[@]}"
2633 else
2634 ewarn "No files to compile!"
2635 fi
2636}

Legend:
Removed from v.1.101  
changed lines
  Added in v.1.116

  ViewVC Help
Powered by ViewVC 1.1.20