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