| 1 | # Copyright 1999-2010 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.103 2010/10/03 00:38:13 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.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 | |
| 14 | if ! has "${EAPI:-0}" 0 1 2 3; then |
14 | if ! 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" |
| 16 | fi |
16 | fi |
| 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 | |
| 155 | DEPEND=">=app-admin/eselect-python-20091230" |
217 | DEPEND=">=app-admin/eselect-python-20091230" |
| 156 | RDEPEND="${DEPEND}" |
218 | RDEPEND="${DEPEND}" |
| 157 | |
219 | |
| 158 | if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then |
|
|
| 159 | die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" |
|
|
| 160 | elif [[ -n "${PYTHON_DEPEND}" ]]; then |
220 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
| 161 | _parse_PYTHON_DEPEND |
221 | _python_parse_PYTHON_DEPEND |
| 162 | elif [[ -n "${NEED_PYTHON}" ]]; then |
|
|
| 163 | if ! has "${EAPI:-0}" 0 1 2; then |
|
|
| 164 | eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
| 165 | die "NEED_PYTHON variable cannot be used in this EAPI" |
|
|
| 166 | fi |
|
|
| 167 | |
|
|
| 168 | ewarn |
|
|
| 169 | ewarn "\"${EBUILD}\":" |
|
|
| 170 | ewarn "Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01." |
|
|
| 171 | ewarn "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
| 172 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 173 | ewarn |
|
|
| 174 | |
|
|
| 175 | unset _BOLD _NORMAL |
|
|
| 176 | |
|
|
| 177 | _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}") |
|
|
| 178 | DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}" |
|
|
| 179 | RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}" |
|
|
| 180 | else |
222 | else |
| 181 | _PYTHON_ATOMS=("dev-lang/python") |
223 | _PYTHON_ATOMS=("dev-lang/python") |
|
|
224 | fi |
|
|
225 | unset -f _python_parse_PYTHON_DEPEND |
|
|
226 | |
|
|
227 | if [[ -n "${NEED_PYTHON}" ]]; then |
|
|
228 | eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
229 | die "NEED_PYTHON variable is banned" |
| 182 | fi |
230 | fi |
| 183 | |
231 | |
| 184 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
232 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
| 185 | # @DESCRIPTION: |
233 | # @DESCRIPTION: |
| 186 | # Set this to a space separated list of USE flags the Python slot in use must be built with. |
234 | # Set this to a space separated list of USE flags the Python slot in use must be built with. |
| … | |
… | |
| 347 | # @DESCRIPTION: |
395 | # @DESCRIPTION: |
| 348 | # Perform sanity checks and initialize environment. |
396 | # Perform sanity checks and initialize environment. |
| 349 | # |
397 | # |
| 350 | # This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable |
398 | # This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable |
| 351 | # is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. |
399 | # is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. |
| 352 | # |
|
|
| 353 | # This function can be used only in pkg_setup() phase. |
|
|
| 354 | python_pkg_setup() { |
400 | python_pkg_setup() { |
| 355 | # Check if phase is pkg_setup(). |
401 | if [[ "${EBUILD_PHASE}" != "setup" ]]; then |
| 356 | [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" |
402 | die "${FUNCNAME}() can be used only in pkg_setup() phase" |
|
|
403 | fi |
| 357 | |
404 | |
| 358 | if [[ "$#" -ne 0 ]]; then |
405 | if [[ "$#" -ne 0 ]]; then |
| 359 | die "${FUNCNAME}() does not accept arguments" |
406 | die "${FUNCNAME}() does not accept arguments" |
| 360 | fi |
407 | fi |
|
|
408 | |
|
|
409 | export JYTHON_SYSTEM_CACHEDIR="1" |
|
|
410 | addwrite "${EPREFIX}/var/cache/jython" |
| 361 | |
411 | |
| 362 | if _python_package_supporting_installation_for_multiple_python_abis; then |
412 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 363 | _python_calculate_PYTHON_ABIS |
413 | _python_calculate_PYTHON_ABIS |
| 364 | export EPYTHON="$(PYTHON -f)" |
414 | export EPYTHON="$(PYTHON -f)" |
| 365 | else |
415 | else |
| … | |
… | |
| 408 | fi |
458 | fi |
| 409 | |
459 | |
| 410 | PYTHON_PKG_SETUP_EXECUTED="1" |
460 | PYTHON_PKG_SETUP_EXECUTED="1" |
| 411 | } |
461 | } |
| 412 | |
462 | |
| 413 | if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then |
463 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
| 414 | EXPORT_FUNCTIONS pkg_setup |
464 | EXPORT_FUNCTIONS pkg_setup |
| 415 | fi |
465 | fi |
| 416 | |
466 | |
|
|
467 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|python)' |
|
|
468 | |
| 417 | # @FUNCTION: python_convert_shebangs |
469 | # @FUNCTION: python_convert_shebangs |
| 418 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
470 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
| 419 | # @DESCRIPTION: |
471 | # @DESCRIPTION: |
| 420 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
472 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| 421 | python_convert_shebangs() { |
473 | python_convert_shebangs() { |
| 422 | _python_check_python_pkg_setup_execution |
474 | _python_check_python_pkg_setup_execution |
| 423 | |
475 | |
| 424 | local argument file files=() only_executables="0" python_version quiet="0" recursive="0" |
476 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" |
| 425 | |
477 | |
| 426 | while (($#)); do |
478 | while (($#)); do |
| 427 | case "$1" in |
479 | case "$1" in |
| 428 | -r|--recursive) |
480 | -r|--recursive) |
| 429 | recursive="1" |
481 | recursive="1" |
| … | |
… | |
| 452 | die "${FUNCNAME}(): Missing Python version and files or directories" |
504 | die "${FUNCNAME}(): Missing Python version and files or directories" |
| 453 | elif [[ "$#" -eq 1 ]]; then |
505 | elif [[ "$#" -eq 1 ]]; then |
| 454 | die "${FUNCNAME}(): Missing files or directories" |
506 | die "${FUNCNAME}(): Missing files or directories" |
| 455 | fi |
507 | fi |
| 456 | |
508 | |
| 457 | python_version="$1" |
509 | if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then |
|
|
510 | python_interpreter="$(PYTHON "$1")" |
|
|
511 | else |
|
|
512 | python_interpreter="python$1" |
|
|
513 | fi |
| 458 | shift |
514 | shift |
| 459 | |
515 | |
| 460 | for argument in "$@"; do |
516 | for argument in "$@"; do |
| 461 | if [[ ! -e "${argument}" ]]; then |
517 | if [[ ! -e "${argument}" ]]; then |
| 462 | die "${FUNCNAME}(): '${argument}' does not exist" |
518 | die "${FUNCNAME}(): '${argument}' does not exist" |
| … | |
… | |
| 477 | |
533 | |
| 478 | for file in "${files[@]}"; do |
534 | for file in "${files[@]}"; do |
| 479 | file="${file#./}" |
535 | file="${file#./}" |
| 480 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
536 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 481 | |
537 | |
| 482 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
538 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
| 483 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
539 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
| 484 | |
540 | |
| 485 | if [[ "${quiet}" == "0" ]]; then |
541 | if [[ "${quiet}" == "0" ]]; then |
| 486 | einfo "Converting shebang in '${file}'" |
542 | einfo "Converting shebang in '${file}'" |
| 487 | fi |
543 | fi |
| 488 | |
544 | |
| 489 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
545 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
| 490 | |
|
|
| 491 | # Delete potential whitespace after "#!". |
|
|
| 492 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
|
|
| 493 | fi |
546 | fi |
| 494 | done |
547 | done |
| 495 | } |
548 | } |
| 496 | |
549 | |
| 497 | # @FUNCTION: python_clean_installation_image |
550 | # @FUNCTION: python_clean_installation_image |
| 498 | # @USAGE: [-q|--quiet] |
551 | # @USAGE: [-q|--quiet] |
| 499 | # @DESCRIPTION: |
552 | # @DESCRIPTION: |
| 500 | # Delete needless files in installation image. |
553 | # Delete needless files in installation image. |
|
|
554 | # |
|
|
555 | # This function can be used only in src_install() phase. |
| 501 | python_clean_installation_image() { |
556 | python_clean_installation_image() { |
|
|
557 | if [[ "${EBUILD_PHASE}" != "install" ]]; then |
|
|
558 | die "${FUNCNAME}() can be used only in src_install() phase" |
|
|
559 | fi |
|
|
560 | |
| 502 | _python_check_python_pkg_setup_execution |
561 | _python_check_python_pkg_setup_execution |
| 503 | _python_initialize_prefix_variables |
562 | _python_initialize_prefix_variables |
| 504 | |
563 | |
| 505 | local file files=() quiet="0" |
564 | local file files=() quiet="0" |
| 506 | |
|
|
| 507 | # Check if phase is src_install(). |
|
|
| 508 | [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase" |
|
|
| 509 | |
565 | |
| 510 | while (($#)); do |
566 | while (($#)); do |
| 511 | case "$1" in |
567 | case "$1" in |
| 512 | -q|--quiet) |
568 | -q|--quiet) |
| 513 | quiet="1" |
569 | quiet="1" |
| … | |
… | |
| 564 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
620 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
| 565 | # @DESCRIPTION: |
621 | # @DESCRIPTION: |
| 566 | # Set this in EAPI <= 4 to indicate that current package supports installation for |
622 | # Set this in EAPI <= 4 to indicate that current package supports installation for |
| 567 | # multiple Python ABIs. |
623 | # multiple Python ABIs. |
| 568 | |
624 | |
|
|
625 | # @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS |
|
|
626 | # @DESCRIPTION: |
|
|
627 | # Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI |
|
|
628 | # patterns specified in this list is skipped. |
|
|
629 | |
| 569 | # @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS |
630 | # @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS |
| 570 | # @DESCRIPTION: |
631 | # @DESCRIPTION: |
| 571 | # Set this to export phase functions for the following ebuild phases: |
632 | # Set this to export phase functions for the following ebuild phases: |
| 572 | # src_prepare, src_configure, src_compile, src_test, src_install. |
633 | # src_prepare(), src_configure(), src_compile(), src_test(), src_install(). |
| 573 | if ! has "${EAPI:-0}" 0 1; then |
634 | if ! has "${EAPI:-0}" 0 1; then |
| 574 | python_src_prepare() { |
635 | python_src_prepare() { |
| 575 | _python_check_python_pkg_setup_execution |
636 | if [[ "${EBUILD_PHASE}" != "prepare" ]]; then |
|
|
637 | die "${FUNCNAME}() can be used only in src_prepare() phase" |
|
|
638 | fi |
| 576 | |
639 | |
| 577 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
640 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 578 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
641 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 579 | fi |
642 | fi |
| 580 | |
643 | |
|
|
644 | _python_check_python_pkg_setup_execution |
|
|
645 | |
| 581 | if [[ "$#" -ne 0 ]]; then |
646 | if [[ "$#" -ne 0 ]]; then |
| 582 | die "${FUNCNAME}() does not accept arguments" |
647 | die "${FUNCNAME}() does not accept arguments" |
| 583 | fi |
648 | fi |
| 584 | |
649 | |
| 585 | python_copy_sources |
650 | python_copy_sources |
| 586 | } |
651 | } |
| 587 | |
652 | |
| 588 | for python_default_function in src_configure src_compile src_test src_install; do |
653 | for python_default_function in src_configure src_compile src_test; do |
| 589 | eval "python_${python_default_function}() { |
654 | eval "python_${python_default_function}() { |
| 590 | _python_check_python_pkg_setup_execution |
655 | if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then |
|
|
656 | die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\" |
|
|
657 | fi |
| 591 | |
658 | |
| 592 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
659 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 593 | die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" |
660 | die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" |
| 594 | fi |
661 | fi |
| 595 | |
662 | |
|
|
663 | _python_check_python_pkg_setup_execution |
|
|
664 | |
| 596 | python_execute_function -d -s -- \"\$@\" |
665 | python_execute_function -d -s -- \"\$@\" |
| 597 | }" |
666 | }" |
| 598 | done |
667 | done |
| 599 | unset python_default_function |
668 | unset python_default_function |
| 600 | |
669 | |
|
|
670 | python_src_install() { |
|
|
671 | if [[ "${EBUILD_PHASE}" != "install" ]]; then |
|
|
672 | die "${FUNCNAME}() can be used only in src_install() phase" |
|
|
673 | fi |
|
|
674 | |
|
|
675 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
676 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
677 | fi |
|
|
678 | |
|
|
679 | _python_check_python_pkg_setup_execution |
|
|
680 | |
|
|
681 | if has "${EAPI:-0}" 0 1 2 3; then |
|
|
682 | python_execute_function -d -s -- "$@" |
|
|
683 | else |
|
|
684 | python_installation() { |
|
|
685 | emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@" |
|
|
686 | } |
|
|
687 | python_execute_function -s python_installation "$@" |
|
|
688 | unset python_installation |
|
|
689 | |
|
|
690 | python_merge_intermediate_installation_images "${T}/images" |
|
|
691 | fi |
|
|
692 | } |
|
|
693 | |
| 601 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
694 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 602 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
695 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
| 603 | fi |
696 | fi |
| 604 | fi |
697 | fi |
| 605 | |
698 | |
|
|
699 | if has "${EAPI:-0}" 0 1 2 3 4; then |
| 606 | unset PYTHON_ABIS |
700 | unset PYTHON_ABIS |
|
|
701 | fi |
| 607 | |
702 | |
| 608 | _python_calculate_PYTHON_ABIS() { |
703 | _python_calculate_PYTHON_ABIS() { |
| 609 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
704 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 610 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
705 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 611 | fi |
706 | fi |
| 612 | |
707 | |
| 613 | _python_initial_sanity_checks |
708 | _python_initial_sanity_checks |
| 614 | |
709 | |
| 615 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. |
|
|
| 616 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
710 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
| 617 | local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= |
711 | local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS |
| 618 | PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" |
712 | |
|
|
713 | restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}" |
| 619 | |
714 | |
| 620 | 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 |
| 621 | local cpython_enabled="0" |
716 | local cpython_enabled="0" |
| 622 | |
717 | |
| 623 | if [[ -z "${USE_PYTHON}" ]]; then |
718 | if [[ -z "${USE_PYTHON}" ]]; then |
| 624 | die "USE_PYTHON variable is empty" |
719 | die "USE_PYTHON variable is empty" |
| 625 | fi |
720 | fi |
| 626 | |
721 | |
| 627 | for PYTHON_ABI in ${USE_PYTHON}; do |
722 | for PYTHON_ABI in ${USE_PYTHON}; do |
| 628 | if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
723 | if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then |
| 629 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
724 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
| 630 | fi |
725 | fi |
| 631 | |
726 | |
| 632 | 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 |
| 633 | cpython_enabled="1" |
728 | cpython_enabled="1" |
| 634 | fi |
729 | fi |
| 635 | |
730 | |
| 636 | support_ABI="1" |
731 | support_ABI="1" |
| 637 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
732 | while read restricted_ABI; do |
| 638 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
733 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
| 639 | support_ABI="0" |
734 | support_ABI="0" |
| 640 | break |
735 | break |
| 641 | fi |
736 | fi |
| 642 | done |
737 | done <<< "${restricted_ABIs}" |
| 643 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
738 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
| 644 | done |
739 | done |
| 645 | |
740 | |
| 646 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
741 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
| 647 | 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}" |
| … | |
… | |
| 649 | |
744 | |
| 650 | if [[ "${cpython_enabled}" == "0" ]]; then |
745 | if [[ "${cpython_enabled}" == "0" ]]; then |
| 651 | die "USE_PYTHON variable does not enable any CPython ABI" |
746 | die "USE_PYTHON variable does not enable any CPython ABI" |
| 652 | fi |
747 | fi |
| 653 | else |
748 | else |
| 654 | local python_version python2_version= python3_version= support_python_major_version |
749 | local python_version python2_version python3_version support_python_major_version |
| 655 | |
750 | |
| 656 | if ! has_version "dev-lang/python"; then |
751 | if ! has_version "dev-lang/python"; then |
| 657 | die "${FUNCNAME}(): 'dev-lang/python' is not installed" |
752 | die "${FUNCNAME}(): 'dev-lang/python' is not installed" |
| 658 | fi |
753 | fi |
| 659 | |
754 | |
| … | |
… | |
| 664 | die "'${EPREFIX}/usr/bin/python2' is not valid symlink" |
759 | die "'${EPREFIX}/usr/bin/python2' is not valid symlink" |
| 665 | fi |
760 | fi |
| 666 | |
761 | |
| 667 | 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]))')" |
| 668 | |
763 | |
| 669 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
764 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
| 670 | support_python_major_version="1" |
765 | support_python_major_version="1" |
| 671 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
766 | while read restricted_ABI; do |
| 672 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
767 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
| 673 | support_python_major_version="0" |
768 | support_python_major_version="0" |
| 674 | fi |
769 | fi |
| 675 | done |
770 | done <<< "${restricted_ABIs}" |
| 676 | [[ "${support_python_major_version}" == "1" ]] && break |
771 | [[ "${support_python_major_version}" == "1" ]] && break |
| 677 | done |
772 | done |
| 678 | if [[ "${support_python_major_version}" == "1" ]]; then |
773 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 679 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
774 | while read restricted_ABI; do |
| 680 | if [[ "${python2_version}" == ${restricted_ABI} ]]; then |
775 | if _python_check_python_abi_matching "${python2_version}" "${restricted_ABI}"; then |
| 681 | 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}" |
| 682 | fi |
777 | fi |
| 683 | done |
778 | done <<< "${restricted_ABIs}" |
| 684 | else |
779 | else |
| 685 | python2_version="" |
780 | python2_version="" |
| 686 | fi |
781 | fi |
| 687 | fi |
782 | fi |
| 688 | |
783 | |
| … | |
… | |
| 691 | die "'${EPREFIX}/usr/bin/python3' is not valid symlink" |
786 | die "'${EPREFIX}/usr/bin/python3' is not valid symlink" |
| 692 | fi |
787 | fi |
| 693 | |
788 | |
| 694 | 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]))')" |
| 695 | |
790 | |
| 696 | for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do |
791 | for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
| 697 | support_python_major_version="1" |
792 | support_python_major_version="1" |
| 698 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
793 | while read restricted_ABI; do |
| 699 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
794 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
| 700 | support_python_major_version="0" |
795 | support_python_major_version="0" |
| 701 | fi |
796 | fi |
| 702 | done |
797 | done <<< "${restricted_ABIs}" |
| 703 | [[ "${support_python_major_version}" == "1" ]] && break |
798 | [[ "${support_python_major_version}" == "1" ]] && break |
| 704 | done |
799 | done |
| 705 | if [[ "${support_python_major_version}" == "1" ]]; then |
800 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 706 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
801 | while read restricted_ABI; do |
| 707 | if [[ "${python3_version}" == ${restricted_ABI} ]]; then |
802 | if _python_check_python_abi_matching "${python3_version}" "${restricted_ABI}"; then |
| 708 | 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}" |
| 709 | fi |
804 | fi |
| 710 | done |
805 | done <<< "${restricted_ABIs}" |
| 711 | else |
806 | else |
| 712 | python3_version="" |
807 | python3_version="" |
| 713 | fi |
808 | fi |
| 714 | fi |
809 | fi |
| 715 | |
810 | |
| … | |
… | |
| 745 | if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then |
840 | if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then |
| 746 | pattern="${element%% *}" |
841 | pattern="${element%% *}" |
| 747 | element="${element#* }" |
842 | element="${element#* }" |
| 748 | operator="${element%% *}" |
843 | operator="${element%% *}" |
| 749 | flags="${element#* }" |
844 | flags="${element#* }" |
| 750 | if [[ "${PYTHON_ABI}" == ${pattern} ]]; then |
845 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then |
| 751 | if [[ "${operator}" == "+" ]]; then |
846 | if [[ "${operator}" == "+" ]]; then |
| 752 | eval "export ${variable}+=\"\${variable:+ }${flags}\"" |
847 | eval "export ${variable}+=\"\${variable:+ }${flags}\"" |
| 753 | elif [[ "${operator}" == "-" ]]; then |
848 | elif [[ "${operator}" == "-" ]]; then |
| 754 | flags="${flags// /$'\n'}" |
849 | flags="${flags// /$'\n'}" |
| 755 | old_value="${!variable// /$'\n'}" |
850 | old_value="${!variable// /$'\n'}" |
| … | |
… | |
| 789 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
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] |
| 790 | # @DESCRIPTION: |
885 | # @DESCRIPTION: |
| 791 | # 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 |
| 792 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
887 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| 793 | python_execute_function() { |
888 | python_execute_function() { |
| 794 | _python_check_python_pkg_setup_execution |
|
|
| 795 | |
|
|
| 796 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
889 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 797 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
890 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 798 | fi |
891 | fi |
| 799 | |
892 | |
|
|
893 | _python_check_python_pkg_setup_execution |
| 800 | _python_set_color_variables |
894 | _python_set_color_variables |
| 801 | |
895 | |
| 802 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir= |
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 |
| 803 | |
897 | |
| 804 | while (($#)); do |
898 | while (($#)); do |
| 805 | case "$1" in |
899 | case "$1" in |
| 806 | --action-message) |
900 | --action-message) |
| 807 | action_message_template="$2" |
901 | action_message_template="$2" |
| … | |
… | |
| 919 | iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
1013 | iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
| 920 | else |
1014 | else |
| 921 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
1015 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
| 922 | fi |
1016 | fi |
| 923 | 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 | |
| 924 | _python_prepare_flags |
1025 | _python_prepare_flags |
| 925 | |
1026 | |
| 926 | if [[ "${quiet}" == "0" ]]; then |
1027 | if [[ "${quiet}" == "0" ]]; then |
| 927 | if [[ -n "${action_message_template}" ]]; then |
1028 | if [[ -n "${action_message_template}" ]]; then |
| 928 | eval "action_message=\"${action_message_template}\"" |
1029 | eval "action_message=\"${action_message_template}\"" |
| … | |
… | |
| 1022 | # @FUNCTION: python_copy_sources |
1123 | # @FUNCTION: python_copy_sources |
| 1023 | # @USAGE: <directory="${S}"> [directory] |
1124 | # @USAGE: <directory="${S}"> [directory] |
| 1024 | # @DESCRIPTION: |
1125 | # @DESCRIPTION: |
| 1025 | # 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. |
| 1026 | python_copy_sources() { |
1127 | python_copy_sources() { |
| 1027 | _python_check_python_pkg_setup_execution |
|
|
| 1028 | |
|
|
| 1029 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
1128 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 1030 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
1129 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 1031 | fi |
1130 | fi |
|
|
1131 | |
|
|
1132 | _python_check_python_pkg_setup_execution |
| 1032 | |
1133 | |
| 1033 | local dir dirs=() PYTHON_ABI |
1134 | local dir dirs=() PYTHON_ABI |
| 1034 | |
1135 | |
| 1035 | if [[ "$#" -eq 0 ]]; then |
1136 | if [[ "$#" -eq 0 ]]; then |
| 1036 | if [[ "${WORKDIR}" == "${S}" ]]; then |
1137 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| … | |
… | |
| 1053 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
1154 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
| 1054 | # @DESCRIPTION: |
1155 | # @DESCRIPTION: |
| 1055 | # Generate wrapper scripts. Existing files are overwritten only with --force option. |
1156 | # Generate wrapper scripts. Existing files are overwritten only with --force option. |
| 1056 | # If --respect-EPYTHON option is specified, then generated wrapper scripts will |
1157 | # If --respect-EPYTHON option is specified, then generated wrapper scripts will |
| 1057 | # 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. |
| 1058 | python_generate_wrapper_scripts() { |
1161 | python_generate_wrapper_scripts() { |
| 1059 | _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 |
| 1060 | |
1165 | |
| 1061 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
1166 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 1062 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
1167 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 1063 | fi |
1168 | fi |
| 1064 | |
1169 | |
|
|
1170 | _python_check_python_pkg_setup_execution |
| 1065 | _python_initialize_prefix_variables |
1171 | _python_initialize_prefix_variables |
| 1066 | |
1172 | |
| 1067 | 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" |
| 1068 | |
1174 | |
| 1069 | while (($#)); do |
1175 | while (($#)); do |
| 1070 | case "$1" in |
1176 | case "$1" in |
| 1071 | -E|--respect-EPYTHON) |
1177 | -E|--respect-EPYTHON) |
| 1072 | respect_EPYTHON="1" |
1178 | respect_EPYTHON="1" |
| … | |
… | |
| 1094 | if [[ "$#" -eq 0 ]]; then |
1200 | if [[ "$#" -eq 0 ]]; then |
| 1095 | die "${FUNCNAME}(): Missing arguments" |
1201 | die "${FUNCNAME}(): Missing arguments" |
| 1096 | fi |
1202 | fi |
| 1097 | |
1203 | |
| 1098 | _python_calculate_PYTHON_ABIS |
1204 | _python_calculate_PYTHON_ABIS |
| 1099 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
1205 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
| 1100 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
1206 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
| 1101 | python2_enabled="1" |
1207 | python2_enabled="1" |
| 1102 | fi |
1208 | fi |
| 1103 | done |
1209 | done |
| 1104 | for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do |
1210 | for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
| 1105 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
1211 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
| 1106 | python3_enabled="1" |
1212 | python3_enabled="1" |
| 1107 | fi |
1213 | fi |
| 1108 | done |
1214 | done |
| 1109 | |
1215 | |
| … | |
… | |
| 1115 | eselect_python_option="--python3" |
1221 | eselect_python_option="--python3" |
| 1116 | else |
1222 | else |
| 1117 | die "${FUNCNAME}(): Unsupported environment" |
1223 | die "${FUNCNAME}(): Unsupported environment" |
| 1118 | fi |
1224 | fi |
| 1119 | |
1225 | |
|
|
1226 | PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")" |
|
|
1227 | |
| 1120 | for file in "$@"; do |
1228 | for file in "$@"; do |
| 1121 | if [[ -f "${file}" && "${force}" == "0" ]]; then |
1229 | if [[ -f "${file}" && "${force}" == "0" ]]; then |
| 1122 | die "${FUNCNAME}(): '$1' already exists" |
1230 | die "${FUNCNAME}(): '${file}' already exists" |
| 1123 | fi |
1231 | fi |
| 1124 | |
1232 | |
| 1125 | if [[ "${quiet}" == "0" ]]; then |
1233 | if [[ "${quiet}" == "0" ]]; then |
| 1126 | einfo "Generating '${file#${ED%/}}' wrapper script" |
1234 | einfo "Generating '${file#${ED%/}}' wrapper script" |
| 1127 | fi |
1235 | fi |
| … | |
… | |
| 1133 | import os |
1241 | import os |
| 1134 | import re |
1242 | import re |
| 1135 | import subprocess |
1243 | import subprocess |
| 1136 | import sys |
1244 | import sys |
| 1137 | |
1245 | |
| 1138 | EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") |
1246 | cpython_re = re.compile(r"^python(\d+\.\d+)$") |
|
|
1247 | jython_re = re.compile(r"^jython(\d+\.\d+)$") |
| 1139 | python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
1248 | python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
| 1140 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1249 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
|
|
1250 | |
|
|
1251 | def 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 |
| 1141 | |
1261 | |
| 1142 | EOF |
1262 | EOF |
| 1143 | if [[ "$?" != "0" ]]; then |
1263 | if [[ "$?" != "0" ]]; then |
| 1144 | die "${FUNCNAME}(): Generation of '$1' failed" |
1264 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1145 | fi |
1265 | fi |
| 1146 | if [[ "${respect_EPYTHON}" == "1" ]]; then |
1266 | if [[ "${respect_EPYTHON}" == "1" ]]; then |
| 1147 | cat << EOF >> "${file}" |
1267 | cat << EOF >> "${file}" |
| 1148 | EPYTHON = os.environ.get("EPYTHON") |
1268 | EPYTHON = os.environ.get("EPYTHON") |
| 1149 | if EPYTHON: |
1269 | if EPYTHON: |
| 1150 | EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
1270 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1151 | if EPYTHON_matched: |
1271 | if PYTHON_ABI is None: |
| 1152 | PYTHON_ABI = EPYTHON_matched.group(1) |
|
|
| 1153 | else: |
|
|
| 1154 | sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) |
1272 | sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) |
| 1155 | sys.exit(1) |
1273 | sys.exit(1) |
| 1156 | else: |
1274 | else: |
| 1157 | try: |
1275 | try: |
| 1158 | eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
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) |
| … | |
… | |
| 1166 | if not isinstance(EPYTHON, str): |
1284 | if not isinstance(EPYTHON, str): |
| 1167 | # Python 3 |
1285 | # Python 3 |
| 1168 | EPYTHON = EPYTHON.decode() |
1286 | EPYTHON = EPYTHON.decode() |
| 1169 | EPYTHON = EPYTHON.rstrip("\n") |
1287 | EPYTHON = EPYTHON.rstrip("\n") |
| 1170 | |
1288 | |
| 1171 | EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
1289 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1172 | if EPYTHON_matched: |
1290 | if PYTHON_ABI is None: |
| 1173 | PYTHON_ABI = EPYTHON_matched.group(1) |
|
|
| 1174 | else: |
|
|
| 1175 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
1291 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
| 1176 | sys.exit(1) |
1292 | sys.exit(1) |
|
|
1293 | |
|
|
1294 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
|
|
1295 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
|
|
1296 | if not os.path.exists(target_executable_path): |
|
|
1297 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
|
|
1298 | sys.exit(1) |
| 1177 | EOF |
1299 | EOF |
| 1178 | if [[ "$?" != "0" ]]; then |
1300 | if [[ "$?" != "0" ]]; then |
| 1179 | die "${FUNCNAME}(): Generation of '$1' failed" |
1301 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1180 | fi |
1302 | fi |
| 1181 | else |
1303 | else |
| … | |
… | |
| 1192 | if not isinstance(EPYTHON, str): |
1314 | if not isinstance(EPYTHON, str): |
| 1193 | # Python 3 |
1315 | # Python 3 |
| 1194 | EPYTHON = EPYTHON.decode() |
1316 | EPYTHON = EPYTHON.decode() |
| 1195 | EPYTHON = EPYTHON.rstrip("\n") |
1317 | EPYTHON = EPYTHON.rstrip("\n") |
| 1196 | |
1318 | |
| 1197 | EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
1319 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1198 | if EPYTHON_matched: |
1320 | if PYTHON_ABI is None: |
| 1199 | 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 | |
|
|
1324 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
|
|
1325 | for 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 |
| 1200 | else: |
1329 | else: |
| 1201 | 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) |
| 1202 | sys.exit(1) |
1331 | sys.exit(1) |
| 1203 | EOF |
1332 | EOF |
| 1204 | if [[ "$?" != "0" ]]; then |
1333 | if [[ "$?" != "0" ]]; then |
| 1205 | die "${FUNCNAME}(): Generation of '$1' failed" |
1334 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1206 | fi |
1335 | fi |
| 1207 | fi |
1336 | fi |
| 1208 | cat << EOF >> "${file}" |
1337 | cat << EOF >> "${file}" |
| 1209 | |
|
|
| 1210 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
|
|
| 1211 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
|
|
| 1212 | os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) |
|
|
| 1213 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
|
|
| 1214 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
|
|
| 1215 | if not os.path.exists(target_executable_path): |
|
|
| 1216 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
|
|
| 1217 | sys.exit(1) |
|
|
| 1218 | |
1338 | |
| 1219 | target_executable = open(target_executable_path, "rb") |
1339 | target_executable = open(target_executable_path, "rb") |
| 1220 | target_executable_first_line = target_executable.readline() |
1340 | target_executable_first_line = target_executable.readline() |
| 1221 | if not isinstance(target_executable_first_line, str): |
1341 | if not isinstance(target_executable_first_line, str): |
| 1222 | # Python 3 |
1342 | # Python 3 |
| 1223 | 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") |
| 1224 | |
1344 | |
| 1225 | python_shebang_matched = python_shebang_re.match(target_executable_first_line) |
1345 | python_shebang_matched = python_shebang_re.match(target_executable_first_line) |
| 1226 | target_executable.close() |
1346 | target_executable.close() |
| 1227 | |
1347 | |
| 1228 | if python_shebang_matched: |
1348 | if python_shebang_matched is not None: |
| 1229 | try: |
1349 | try: |
| 1230 | python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
1350 | python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
| 1231 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
1351 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
| 1232 | 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) |
| 1233 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
1353 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
| … | |
… | |
| 1240 | python_verification_output = python_verification_output.decode() |
1360 | python_verification_output = python_verification_output.decode() |
| 1241 | |
1361 | |
| 1242 | if not python_verification_output_re.match(python_verification_output): |
1362 | if not python_verification_output_re.match(python_verification_output): |
| 1243 | raise ValueError |
1363 | raise ValueError |
| 1244 | |
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"): |
| 1245 | 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 |
| 1246 | except: |
1376 | except: |
| 1247 | pass |
1377 | pass |
| 1248 | 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"): |
| 1249 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
1379 | if variable in os.environ: |
|
|
1380 | del os.environ[variable] |
| 1250 | |
1381 | |
|
|
1382 | if hasattr(os, "execv"): |
| 1251 | os.execv(target_executable_path, sys.argv) |
1383 | os.execv(target_executable_path, sys.argv) |
|
|
1384 | else: |
|
|
1385 | sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait()) |
| 1252 | EOF |
1386 | EOF |
| 1253 | if [[ "$?" != "0" ]]; then |
1387 | if [[ "$?" != "0" ]]; then |
| 1254 | die "${FUNCNAME}(): Generation of '$1' failed" |
1388 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1255 | fi |
1389 | fi |
| 1256 | fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" |
1390 | fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" |
| 1257 | done |
1391 | done |
| 1258 | } |
1392 | } |
| 1259 | |
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. |
|
|
1413 | python_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 |
|
|
1465 | import sys |
|
|
1466 | |
|
|
1467 | if hasattr(sys.stdout, 'buffer'): |
|
|
1468 | # Python 3 |
|
|
1469 | stdout = sys.stdout.buffer |
|
|
1470 | else: |
|
|
1471 | # Python 2 |
|
|
1472 | stdout = sys.stdout |
|
|
1473 | |
|
|
1474 | files_set = set() |
|
|
1475 | |
|
|
1476 | os.chdir(${b}'${intermediate_installation_images_directory}') |
|
|
1477 | |
|
|
1478 | for 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 | |
|
|
1483 | for 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 | |
|
|
1568 | if hasattr(sys.stdout, 'buffer'): |
|
|
1569 | # Python 3 |
|
|
1570 | stdout = sys.stdout.buffer |
|
|
1571 | else: |
|
|
1572 | # Python 2 |
|
|
1573 | stdout = sys.stdout |
|
|
1574 | |
|
|
1575 | files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00')) |
|
|
1576 | |
|
|
1577 | for 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 | |
| 1260 | # ================================================================================================ |
1585 | # ================================================================================================ |
| 1261 | # ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== |
1586 | # ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== |
| 1262 | # ================================================================================================ |
1587 | # ================================================================================================ |
| 1263 | |
1588 | |
| 1264 | unset EPYTHON PYTHON_ABI |
1589 | unset EPYTHON PYTHON_ABI |
| 1265 | |
1590 | |
| 1266 | # @FUNCTION: python_set_active_version |
1591 | # @FUNCTION: python_set_active_version |
| 1267 | # @USAGE: <CPython_ABI|2|3> |
1592 | # @USAGE: <Python_ABI|2|3> |
| 1268 | # @DESCRIPTION: |
1593 | # @DESCRIPTION: |
| 1269 | # 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. |
| 1270 | # |
1598 | # |
| 1271 | # This function can be used only in pkg_setup() phase. |
1599 | # This function can be used only in pkg_setup() phase. |
| 1272 | python_set_active_version() { |
1600 | python_set_active_version() { |
| 1273 | # Check if phase is pkg_setup(). |
1601 | if [[ "${EBUILD_PHASE}" != "setup" ]]; then |
| 1274 | [[ "${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 |
| 1275 | |
1604 | |
| 1276 | if _python_package_supporting_installation_for_multiple_python_abis; then |
1605 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1277 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
1606 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 1278 | fi |
1607 | fi |
| 1279 | |
1608 | |
| … | |
… | |
| 1282 | fi |
1611 | fi |
| 1283 | |
1612 | |
| 1284 | _python_initial_sanity_checks |
1613 | _python_initial_sanity_checks |
| 1285 | |
1614 | |
| 1286 | if [[ -z "${PYTHON_ABI}" ]]; then |
1615 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1287 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
1616 | if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then |
| 1288 | if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
1617 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
| 1289 | 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" |
| 1290 | fi |
1622 | fi |
| 1291 | export EPYTHON="$(PYTHON "$1")" |
1623 | export EPYTHON="$(PYTHON "$1")" |
| 1292 | elif [[ "$1" == "2" ]]; then |
1624 | elif [[ "$1" == "2" ]]; then |
| 1293 | if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then |
1625 | if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then |
| 1294 | die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" |
1626 | die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" |
| 1295 | fi |
1627 | fi |
| 1296 | export EPYTHON="$(PYTHON -2)" |
1628 | export EPYTHON="$(PYTHON -2)" |
|
|
1629 | PYTHON_ABI="${EPYTHON#python}" |
|
|
1630 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
| 1297 | elif [[ "$1" == "3" ]]; then |
1631 | elif [[ "$1" == "3" ]]; then |
| 1298 | if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then |
1632 | if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then |
| 1299 | die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" |
1633 | die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" |
| 1300 | fi |
1634 | fi |
| 1301 | export EPYTHON="$(PYTHON -3)" |
1635 | export EPYTHON="$(PYTHON -3)" |
|
|
1636 | PYTHON_ABI="${EPYTHON#python}" |
|
|
1637 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
| 1302 | else |
1638 | else |
| 1303 | die "${FUNCNAME}(): Unrecognized argument '$1'" |
1639 | die "${FUNCNAME}(): Unrecognized argument '$1'" |
| 1304 | fi |
1640 | fi |
| 1305 | |
|
|
| 1306 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
|
|
| 1307 | # so it does not need to be exported to subprocesses. |
|
|
| 1308 | PYTHON_ABI="${EPYTHON#python}" |
|
|
| 1309 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
|
|
| 1310 | fi |
1641 | fi |
| 1311 | |
1642 | |
| 1312 | _python_final_sanity_checks |
1643 | _python_final_sanity_checks |
| 1313 | |
1644 | |
| 1314 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
1645 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
| … | |
… | |
| 1317 | |
1648 | |
| 1318 | # @FUNCTION: python_need_rebuild |
1649 | # @FUNCTION: python_need_rebuild |
| 1319 | # @DESCRIPTION: Mark current package for rebuilding by python-updater after |
1650 | # @DESCRIPTION: Mark current package for rebuilding by python-updater after |
| 1320 | # switching of active version of Python. |
1651 | # switching of active version of Python. |
| 1321 | python_need_rebuild() { |
1652 | python_need_rebuild() { |
| 1322 | _python_check_python_pkg_setup_execution |
|
|
| 1323 | |
|
|
| 1324 | if _python_package_supporting_installation_for_multiple_python_abis; then |
1653 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1325 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
1654 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 1326 | fi |
1655 | fi |
|
|
1656 | |
|
|
1657 | _python_check_python_pkg_setup_execution |
| 1327 | |
1658 | |
| 1328 | if [[ "$#" -ne 0 ]]; then |
1659 | if [[ "$#" -ne 0 ]]; then |
| 1329 | die "${FUNCNAME}() does not accept arguments" |
1660 | die "${FUNCNAME}() does not accept arguments" |
| 1330 | fi |
1661 | fi |
| 1331 | |
1662 | |
| … | |
… | |
| 1341 | sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) |
1672 | sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) |
| 1342 | if platform.system()[:4] == "Java": |
1673 | if platform.system()[:4] == "Java": |
| 1343 | sys.stdout.write("-jython")' |
1674 | sys.stdout.write("-jython")' |
| 1344 | |
1675 | |
| 1345 | _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 | |
| 1346 | if [[ "$#" -ne 1 ]]; then |
1698 | if [[ "$#" -ne 1 ]]; then |
| 1347 | die "${FUNCNAME}() requires 1 argument" |
1699 | die "${FUNCNAME}() requires 1 argument" |
| 1348 | fi |
1700 | fi |
| 1349 | |
1701 | |
| 1350 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
1702 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
| 1351 | echo "CPython" |
1703 | echo "CPython" |
| 1352 | elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
1704 | elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
| 1353 | echo "Jython" |
1705 | echo "Jython" |
| 1354 | else |
1706 | else |
|
|
1707 | if [[ "${ignore_invalid}" == "0" ]]; then |
| 1355 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
1708 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
|
|
1709 | fi |
| 1356 | fi |
1710 | fi |
| 1357 | } |
1711 | } |
| 1358 | |
1712 | |
| 1359 | # @FUNCTION: PYTHON |
1713 | # @FUNCTION: PYTHON |
| 1360 | # @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}"> |
| 1361 | # @DESCRIPTION: |
1715 | # @DESCRIPTION: |
| 1362 | # 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 |
| 1363 | # 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. |
| 1364 | # 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. |
| 1365 | # 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. |
| 1366 | # 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. |
| 1367 | # -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. |
| 1368 | # 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 |
| 1369 | # filename of Python interpreter. |
1723 | # filename of Python interpreter. |
| 1370 | # 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. |
| … | |
… | |
| 1421 | _python_calculate_PYTHON_ABIS |
1775 | _python_calculate_PYTHON_ABIS |
| 1422 | PYTHON_ABI="${PYTHON_ABIS##* }" |
1776 | PYTHON_ABI="${PYTHON_ABIS##* }" |
| 1423 | elif [[ "${python2}" == "1" ]]; then |
1777 | elif [[ "${python2}" == "1" ]]; then |
| 1424 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
1778 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
| 1425 | if [[ -z "${PYTHON_ABI}" ]]; then |
1779 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1426 | die "${FUNCNAME}(): Active version of Python 2 not set" |
1780 | die "${FUNCNAME}(): Active version of CPython 2 not set" |
| 1427 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
1781 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
| 1428 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
1782 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
| 1429 | fi |
1783 | fi |
| 1430 | elif [[ "${python3}" == "1" ]]; then |
1784 | elif [[ "${python3}" == "1" ]]; then |
| 1431 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
1785 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
| 1432 | if [[ -z "${PYTHON_ABI}" ]]; then |
1786 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1433 | die "${FUNCNAME}(): Active version of Python 3 not set" |
1787 | die "${FUNCNAME}(): Active version of CPython 3 not set" |
| 1434 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
1788 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
| 1435 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
1789 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
| 1436 | fi |
1790 | fi |
| 1437 | elif _python_package_supporting_installation_for_multiple_python_abis; then |
1791 | elif _python_package_supporting_installation_for_multiple_python_abis; then |
| 1438 | if ! _python_abi-specific_local_scope; then |
1792 | if ! _python_abi-specific_local_scope; then |
| … | |
… | |
| 1464 | return |
1818 | return |
| 1465 | else |
1819 | else |
| 1466 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1820 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1467 | python_interpreter="python${PYTHON_ABI}" |
1821 | python_interpreter="python${PYTHON_ABI}" |
| 1468 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1822 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1469 | python_interpreter="jython-${PYTHON_ABI%-jython}" |
1823 | python_interpreter="jython${PYTHON_ABI%-jython}" |
| 1470 | fi |
1824 | fi |
| 1471 | |
1825 | |
| 1472 | if [[ "${absolute_path_output}" == "1" ]]; then |
1826 | if [[ "${absolute_path_output}" == "1" ]]; then |
| 1473 | echo -n "${EPREFIX}/usr/bin/${python_interpreter}" |
1827 | echo -n "${EPREFIX}/usr/bin/${python_interpreter}" |
| 1474 | else |
1828 | else |
| … | |
… | |
| 1562 | else |
1916 | else |
| 1563 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
1917 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
| 1564 | fi |
1918 | fi |
| 1565 | fi |
1919 | fi |
| 1566 | |
1920 | |
|
|
1921 | if [[ "${EAPI:-0}" == "0" ]]; then |
| 1567 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1922 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1568 | echo "dev-lang/python:${PYTHON_ABI}" |
1923 | echo "=dev-lang/python-${PYTHON_ABI}*" |
| 1569 | 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 |
| 1570 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
1931 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
|
|
1932 | fi |
| 1571 | fi |
1933 | fi |
| 1572 | } |
1934 | } |
| 1573 | |
1935 | |
| 1574 | # @FUNCTION: python_get_includedir |
1936 | # @FUNCTION: python_get_includedir |
| 1575 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
1937 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
| … | |
… | |
| 1895 | # 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. |
| 1896 | python_execute_nosetests() { |
2258 | python_execute_nosetests() { |
| 1897 | _python_check_python_pkg_setup_execution |
2259 | _python_check_python_pkg_setup_execution |
| 1898 | _python_set_color_variables |
2260 | _python_set_color_variables |
| 1899 | |
2261 | |
| 1900 | local PYTHONPATH_template= separate_build_dirs= |
2262 | local PYTHONPATH_template separate_build_dirs |
| 1901 | |
2263 | |
| 1902 | while (($#)); do |
2264 | while (($#)); do |
| 1903 | case "$1" in |
2265 | case "$1" in |
| 1904 | -P|--PYTHONPATH) |
2266 | -P|--PYTHONPATH) |
| 1905 | PYTHONPATH_template="$2" |
2267 | PYTHONPATH_template="$2" |
| … | |
… | |
| 1959 | # 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. |
| 1960 | python_execute_py.test() { |
2322 | python_execute_py.test() { |
| 1961 | _python_check_python_pkg_setup_execution |
2323 | _python_check_python_pkg_setup_execution |
| 1962 | _python_set_color_variables |
2324 | _python_set_color_variables |
| 1963 | |
2325 | |
| 1964 | local PYTHONPATH_template= separate_build_dirs= |
2326 | local PYTHONPATH_template separate_build_dirs |
| 1965 | |
2327 | |
| 1966 | while (($#)); do |
2328 | while (($#)); do |
| 1967 | case "$1" in |
2329 | case "$1" in |
| 1968 | -P|--PYTHONPATH) |
2330 | -P|--PYTHONPATH) |
| 1969 | PYTHONPATH_template="$2" |
2331 | PYTHONPATH_template="$2" |
| … | |
… | |
| 2023 | # 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. |
| 2024 | python_execute_trial() { |
2386 | python_execute_trial() { |
| 2025 | _python_check_python_pkg_setup_execution |
2387 | _python_check_python_pkg_setup_execution |
| 2026 | _python_set_color_variables |
2388 | _python_set_color_variables |
| 2027 | |
2389 | |
| 2028 | local PYTHONPATH_template= separate_build_dirs= |
2390 | local PYTHONPATH_template separate_build_dirs |
| 2029 | |
2391 | |
| 2030 | while (($#)); do |
2392 | while (($#)); do |
| 2031 | case "$1" in |
2393 | case "$1" in |
| 2032 | -P|--PYTHONPATH) |
2394 | -P|--PYTHONPATH) |
| 2033 | PYTHONPATH_template="$2" |
2395 | PYTHONPATH_template="$2" |
| … | |
… | |
| 2114 | |
2476 | |
| 2115 | _python_clean_compiled_modules() { |
2477 | _python_clean_compiled_modules() { |
| 2116 | _python_initialize_prefix_variables |
2478 | _python_initialize_prefix_variables |
| 2117 | _python_set_color_variables |
2479 | _python_set_color_variables |
| 2118 | |
2480 | |
| 2119 | [[ "${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" |
| 2120 | |
2482 | |
| 2121 | 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 |
| 2122 | |
2484 | |
| 2123 | # Strip trailing slash from EROOT. |
2485 | # Strip trailing slash from EROOT. |
| 2124 | root="${EROOT%/}" |
2486 | root="${EROOT%/}" |
| … | |
… | |
| 2173 | if [[ "${dir}" == "__pycache__" ]]; then |
2535 | if [[ "${dir}" == "__pycache__" ]]; then |
| 2174 | base_module_name="${compiled_file##*/}" |
2536 | base_module_name="${compiled_file##*/}" |
| 2175 | base_module_name="${base_module_name%\$py.class}" |
2537 | base_module_name="${base_module_name%\$py.class}" |
| 2176 | py_file="${compiled_file%__pycache__/*}${base_module_name}.py" |
2538 | py_file="${compiled_file%__pycache__/*}${base_module_name}.py" |
| 2177 | else |
2539 | else |
| 2178 | py_file="${compiled_file%\$py.class}" |
2540 | py_file="${compiled_file%\$py.class}.py" |
| 2179 | fi |
2541 | fi |
| 2180 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2542 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2181 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2543 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2182 | else |
2544 | else |
| 2183 | [[ -f "${py_file}" ]] && continue |
2545 | [[ -f "${py_file}" ]] && continue |
| … | |
… | |
| 2201 | done |
2563 | done |
| 2202 | done |
2564 | done |
| 2203 | } |
2565 | } |
| 2204 | |
2566 | |
| 2205 | # @FUNCTION: python_mod_optimize |
2567 | # @FUNCTION: python_mod_optimize |
| 2206 | # @USAGE: [options] [directory|file] |
2568 | # @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories] |
| 2207 | # @DESCRIPTION: |
2569 | # @DESCRIPTION: |
| 2208 | # If no arguments supplied, it will recompile not recursively all modules |
2570 | # Byte-compile specified Python modules. |
| 2209 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
|
|
| 2210 | # |
|
|
| 2211 | # If supplied with arguments, it will recompile all modules recursively |
|
|
| 2212 | # in the supplied directory. |
|
|
| 2213 | # |
|
|
| 2214 | # Options passed to this function are passed to compileall.py. |
2571 | # -d, -f, -l, -q and -x options passed to this function are passed to compileall.py. |
| 2215 | # |
2572 | # |
| 2216 | # This function can be used only in pkg_postinst() phase. |
2573 | # This function can be used only in pkg_postinst() phase. |
| 2217 | python_mod_optimize() { |
2574 | python_mod_optimize() { |
|
|
2575 | if [[ "${EBUILD_PHASE}" != "postinst" ]]; then |
|
|
2576 | die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
|
|
2577 | fi |
|
|
2578 | |
| 2218 | _python_check_python_pkg_setup_execution |
2579 | _python_check_python_pkg_setup_execution |
| 2219 | _python_initialize_prefix_variables |
2580 | _python_initialize_prefix_variables |
| 2220 | |
2581 | |
| 2221 | # 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 |
| 2222 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
|
|
| 2223 | |
|
|
| 2224 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
| 2225 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
2583 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
| 2226 | local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() |
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=() |
| 2227 | |
2585 | |
| 2228 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2586 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2229 | 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 |
| … | |
… | |
| 2270 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
2628 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2271 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2629 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2272 | fi |
2630 | fi |
| 2273 | |
2631 | |
| 2274 | if [[ "$#" -eq 0 ]]; then |
2632 | if [[ "$#" -eq 0 ]]; then |
| 2275 | ewarn |
2633 | die "${FUNCNAME}(): Missing files or directories" |
| 2276 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
|
|
| 2277 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
|
|
| 2278 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2279 | ewarn |
|
|
| 2280 | fi |
2634 | fi |
| 2281 | |
2635 | |
| 2282 | while (($#)); do |
2636 | while (($#)); do |
| 2283 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2637 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2284 | die "${FUNCNAME}(): Invalid argument '$1'" |
2638 | die "${FUNCNAME}(): Invalid argument '$1'" |
| … | |
… | |
| 2386 | if ((${#other_files[@]})); then |
2740 | if ((${#other_files[@]})); then |
| 2387 | "$(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" |
| 2388 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2742 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2389 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
2743 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 2390 | fi |
2744 | fi |
| 2391 | _python_clean_compiled_modules "${other_dirs[@]}" |
2745 | _python_clean_compiled_modules "${other_files[@]}" |
| 2392 | fi |
2746 | fi |
| 2393 | eend "${return_code}" |
2747 | eend "${return_code}" |
| 2394 | fi |
2748 | fi |
| 2395 | else |
2749 | else |
| 2396 | # 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 |
| 2397 | |
2757 | |
| 2398 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
2758 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 2399 | |
2759 | |
| 2400 | # strip trailing slash |
2760 | # strip trailing slash |
| 2401 | myroot="${EROOT%/}" |
2761 | myroot="${EROOT%/}" |
| … | |
… | |
| 2423 | esac |
2783 | esac |
| 2424 | shift |
2784 | shift |
| 2425 | done |
2785 | done |
| 2426 | |
2786 | |
| 2427 | if [[ "$#" -eq 0 ]]; then |
2787 | if [[ "$#" -eq 0 ]]; then |
| 2428 | ewarn |
2788 | die "${FUNCNAME}(): Missing files or directories" |
| 2429 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
|
|
| 2430 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
|
|
| 2431 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2432 | ewarn |
|
|
| 2433 | fi |
2789 | fi |
| 2434 | |
2790 | |
| 2435 | while (($#)); do |
2791 | while (($#)); do |
| 2436 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2792 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2437 | die "${FUNCNAME}(): Invalid argument '$1'" |
2793 | die "${FUNCNAME}(): Invalid argument '$1'" |
| 2438 | elif [[ -d "${myroot}/${1#/}" ]]; then |
2794 | elif [[ -d "${myroot}/${1#/}" ]]; then |
| 2439 | mydirs+=("${myroot}/${1#/}") |
2795 | mydirs+=("${myroot}/${1#/}") |
| 2440 | elif [[ -f "${myroot}/${1#/}" ]]; then |
2796 | elif [[ -f "${myroot}/${1#/}" ]]; then |
| 2441 | # Files are passed to python_mod_compile which is EROOT-aware |
2797 | myfiles+=("${myroot}/${1#/}") |
| 2442 | myfiles+=("$1") |
|
|
| 2443 | elif [[ -e "${myroot}/${1#/}" ]]; then |
2798 | elif [[ -e "${myroot}/${1#/}" ]]; then |
| 2444 | eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" |
2799 | eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" |
| 2445 | else |
2800 | else |
| 2446 | eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" |
2801 | eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" |
| 2447 | fi |
2802 | fi |
| … | |
… | |
| 2459 | "$(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" |
| 2460 | _python_clean_compiled_modules "${mydirs[@]}" |
2815 | _python_clean_compiled_modules "${mydirs[@]}" |
| 2461 | fi |
2816 | fi |
| 2462 | |
2817 | |
| 2463 | 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" |
| 2464 | python_mod_compile "${myfiles[@]}" |
2821 | _python_clean_compiled_modules "${myfiles[@]}" |
| 2465 | fi |
2822 | fi |
| 2466 | |
2823 | |
| 2467 | eend "${return_code}" |
2824 | eend "${return_code}" |
| 2468 | fi |
2825 | fi |
| 2469 | } |
2826 | } |
| 2470 | |
2827 | |
| 2471 | # @FUNCTION: python_mod_cleanup |
2828 | # @FUNCTION: python_mod_cleanup |
| 2472 | # @USAGE: [directory|file] |
2829 | # @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories] |
| 2473 | # @DESCRIPTION: |
2830 | # @DESCRIPTION: |
| 2474 | # Run with optional arguments, where arguments are Python modules. If none given, |
2831 | # Delete orphaned byte-compiled Python modules corresponding to specified Python modules. |
| 2475 | # it will look in /usr/lib/python[0-9].[0-9]. |
|
|
| 2476 | # |
|
|
| 2477 | # It will recursively scan all compiled Python modules in the directories and |
|
|
| 2478 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
|
|
| 2479 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
|
|
| 2480 | # |
2832 | # |
| 2481 | # This function can be used only in pkg_postrm() phase. |
2833 | # This function can be used only in pkg_postrm() phase. |
| 2482 | python_mod_cleanup() { |
2834 | python_mod_cleanup() { |
|
|
2835 | if [[ "${EBUILD_PHASE}" != "postrm" ]]; then |
|
|
2836 | die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
|
|
2837 | fi |
|
|
2838 | |
| 2483 | _python_check_python_pkg_setup_execution |
2839 | _python_check_python_pkg_setup_execution |
| 2484 | _python_initialize_prefix_variables |
2840 | _python_initialize_prefix_variables |
| 2485 | |
2841 | |
| 2486 | local allow_evaluated_non_sitedir_paths="0" 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 |
| 2487 | |
|
|
| 2488 | # Check if phase is pkg_postrm(). |
|
|
| 2489 | [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
|
|
| 2490 | |
2843 | |
| 2491 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2844 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2492 | 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 |
| 2493 | die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" |
2846 | die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" |
| 2494 | fi |
2847 | fi |
| … | |
… | |
| 2525 | |
2878 | |
| 2526 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
2879 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2527 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2880 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2528 | fi |
2881 | fi |
| 2529 | |
2882 | |
| 2530 | if [[ "$#" -gt 0 ]]; then |
2883 | if [[ "$#" -eq 0 ]]; then |
| 2531 | 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 |
| 2532 | while (($#)); do |
2888 | while (($#)); do |
| 2533 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2889 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2534 | die "${FUNCNAME}(): Invalid argument '$1'" |
2890 | die "${FUNCNAME}(): Invalid argument '$1'" |
| 2535 | 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 |
| 2536 | 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" |
| 2537 | elif [[ "$1" =~ ^/ ]]; then |
2893 | elif [[ "$1" =~ ^/ ]]; then |
| 2538 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2894 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2539 | if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then |
2895 | if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then |
| 2540 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
2896 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 2541 | fi |
|
|
| 2542 | if [[ "$1" != *\$* ]]; then |
|
|
| 2543 | die "${FUNCNAME}(): '$1' has invalid syntax" |
|
|
| 2544 | fi |
|
|
| 2545 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
|
|
| 2546 | eval "search_paths+=(\"\${root}$1\")" |
|
|
| 2547 | done |
|
|
| 2548 | else |
|
|
| 2549 | search_paths+=("${root}$1") |
|
|
| 2550 | fi |
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 |
| 2551 | else |
2904 | else |
|
|
2905 | search_paths+=("${root}$1") |
|
|
2906 | fi |
|
|
2907 | else |
| 2552 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
2908 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 2553 | search_paths+=("${root}$(python_get_sitedir)/$1") |
2909 | search_paths+=("${root}$(python_get_sitedir)/$1") |
| 2554 | done |
2910 | done |
| 2555 | fi |
2911 | fi |
| 2556 | shift |
2912 | shift |
| 2557 | done |
2913 | done |
| 2558 | else |
2914 | else |
| 2559 | # Deprecated part of python_mod_cleanup() |
2915 | # Deprecated part of python_mod_cleanup() |
| 2560 | |
|
|
| 2561 | search_paths=("${@#/}") |
|
|
| 2562 | search_paths=("${search_paths[@]/#/${root}/}") |
|
|
| 2563 | fi |
|
|
| 2564 | else |
|
|
| 2565 | ewarn |
2916 | ewarn |
| 2566 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
2917 | ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" |
| 2567 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
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." |
| 2568 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
2920 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
| 2569 | ewarn |
2921 | ewarn |
| 2570 | |
2922 | |
| 2571 | for dir in "${root}"/usr/lib*; do |
|
|
| 2572 | if [[ -d "${dir}" && ! -L "${dir}" ]]; then |
|
|
| 2573 | for sitedir in "${dir}"/python*/site-packages; do |
|
|
| 2574 | if [[ -d "${sitedir}" ]]; then |
|
|
| 2575 | search_paths+=("${sitedir}") |
|
|
| 2576 | fi |
|
|
| 2577 | done |
|
|
| 2578 | fi |
|
|
| 2579 | done |
|
|
| 2580 | for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do |
|
|
| 2581 | if [[ -d "${sitedir}" ]]; then |
|
|
| 2582 | search_paths+=("${sitedir}") |
2923 | search_paths=("${@#/}") |
| 2583 | fi |
2924 | search_paths=("${search_paths[@]/#/${root}/}") |
| 2584 | done |
|
|
| 2585 | fi |
2925 | fi |
| 2586 | |
2926 | |
| 2587 | _python_clean_compiled_modules "${search_paths[@]}" |
2927 | _python_clean_compiled_modules "${search_paths[@]}" |
| 2588 | } |
2928 | } |
| 2589 | |
2929 | |
| 2590 | # ================================================================================================ |
2930 | # ================================================================================================ |
| 2591 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
2931 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
| 2592 | # ================================================================================================ |
2932 | # ================================================================================================ |
| 2593 | |
|
|
| 2594 | # Scheduled for deletion on 2011-01-01. |
|
|
| 2595 | python_version() { |
|
|
| 2596 | eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." |
|
|
| 2597 | die "${FUNCNAME}() is banned" |
|
|
| 2598 | } |
|
|
| 2599 | |
|
|
| 2600 | # Scheduled for deletion on 2011-01-01. |
|
|
| 2601 | python_mod_exists() { |
|
|
| 2602 | eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." |
|
|
| 2603 | die "${FUNCNAME}() is banned" |
|
|
| 2604 | } |
|
|
| 2605 | |
|
|
| 2606 | # Scheduled for deletion on 2011-01-01. |
|
|
| 2607 | python_tkinter_exists() { |
|
|
| 2608 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
|
|
| 2609 | die "${FUNCNAME}() is banned" |
|
|
| 2610 | } |
|
|
| 2611 | |
|
|
| 2612 | # @FUNCTION: python_mod_compile |
|
|
| 2613 | # @USAGE: <file> [more files ...] |
|
|
| 2614 | # @DESCRIPTION: |
|
|
| 2615 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
|
|
| 2616 | # This function can be used only in pkg_postinst() phase. |
|
|
| 2617 | # |
|
|
| 2618 | # Example: |
|
|
| 2619 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
|
|
| 2620 | # |
|
|
| 2621 | python_mod_compile() { |
|
|
| 2622 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
| 2623 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
|
|
| 2624 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
| 2625 | fi |
|
|
| 2626 | |
|
|
| 2627 | _python_initialize_prefix_variables |
|
|
| 2628 | _python_set_color_variables |
|
|
| 2629 | |
|
|
| 2630 | if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then |
|
|
| 2631 | ewarn |
|
|
| 2632 | ewarn "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." |
|
|
| 2633 | ewarn "Use python_mod_optimize() instead of ${FUNCNAME}()." |
|
|
| 2634 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2635 | ewarn |
|
|
| 2636 | fi |
|
|
| 2637 | |
|
|
| 2638 | local f myroot myfiles=() |
|
|
| 2639 | |
|
|
| 2640 | # Check if phase is pkg_postinst() |
|
|
| 2641 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
|
|
| 2642 | |
|
|
| 2643 | # strip trailing slash |
|
|
| 2644 | myroot="${EROOT%/}" |
|
|
| 2645 | |
|
|
| 2646 | # respect EROOT |
|
|
| 2647 | for f in "$@"; do |
|
|
| 2648 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
|
|
| 2649 | done |
|
|
| 2650 | |
|
|
| 2651 | PYTHON_ABI="$(PYTHON --ABI)" |
|
|
| 2652 | |
|
|
| 2653 | if ((${#myfiles[@]})); then |
|
|
| 2654 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
|
|
| 2655 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
|
|
| 2656 | _python_clean_compiled_modules "${myfiles[@]}" |
|
|
| 2657 | else |
|
|
| 2658 | ewarn "No files to compile!" |
|
|
| 2659 | fi |
|
|
| 2660 | } |
|
|