| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2012 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.139 2011/10/15 20:58:08 phajdan.jr Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.158 2012/09/27 15:41:56 floppym 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 |
| 9 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 10 | # The python eclass contains miscellaneous, useful functions for Python packages. |
10 | # The python eclass contains miscellaneous, useful functions for Python packages. |
| 11 | |
11 | |
|
|
12 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
|
|
13 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 12 | inherit multilib |
14 | inherit multilib |
|
|
15 | fi |
| 13 | |
16 | |
|
|
17 | # Export pkg_setup every time to avoid issues with eclass inheritance order. |
|
|
18 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
|
|
19 | EXPORT_FUNCTIONS pkg_setup |
|
|
20 | fi |
|
|
21 | |
|
|
22 | # Avoid processing this eclass more than once. |
|
|
23 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
|
|
24 | _PYTHON_ECLASS_INHERITED="1" |
|
|
25 | |
| 14 | if ! has "${EAPI:-0}" 0 1 2 3 4; then |
26 | if ! has "${EAPI:-0}" 0 1 2 3 4 5; then |
| 15 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
27 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
| 16 | fi |
28 | fi |
| 17 | |
29 | |
| 18 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 19 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| 20 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 21 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.5) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9) |
| 22 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 23 | |
35 | |
| 24 | # ================================================================================================ |
36 | # ================================================================================================ |
| 25 | # ===================================== HANDLING OF METADATA ===================================== |
37 | # ===================================== HANDLING OF METADATA ===================================== |
| 26 | # ================================================================================================ |
38 | # ================================================================================================ |
| … | |
… | |
| 86 | |
98 | |
| 87 | return 1 |
99 | return 1 |
| 88 | fi |
100 | fi |
| 89 | } |
101 | } |
| 90 | |
102 | |
|
|
103 | _python_implementation() { |
|
|
104 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
105 | return 0 |
|
|
106 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
107 | return 0 |
|
|
108 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
109 | return 0 |
|
|
110 | else |
|
|
111 | return 1 |
|
|
112 | fi |
|
|
113 | } |
|
|
114 | |
| 91 | _python_package_supporting_installation_for_multiple_python_abis() { |
115 | _python_package_supporting_installation_for_multiple_python_abis() { |
| 92 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 93 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
116 | [[ -n "${SUPPORT_PYTHON_ABIS}" ]] |
| 94 | return 0 |
|
|
| 95 | else |
|
|
| 96 | return 1 |
|
|
| 97 | fi |
|
|
| 98 | else |
|
|
| 99 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
| 100 | fi |
|
|
| 101 | } |
117 | } |
| 102 | |
118 | |
| 103 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
119 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
| 104 | # @DESCRIPTION: |
120 | # @DESCRIPTION: |
| 105 | # Specification of dependency on dev-lang/python. |
121 | # Specification of dependency on dev-lang/python. |
| … | |
… | |
| 231 | else |
247 | else |
| 232 | die "Invalid syntax of PYTHON_DEPEND" |
248 | die "Invalid syntax of PYTHON_DEPEND" |
| 233 | fi |
249 | fi |
| 234 | } |
250 | } |
| 235 | |
251 | |
|
|
252 | if _python_implementation; then |
| 236 | DEPEND=">=app-admin/eselect-python-20091230" |
253 | DEPEND=">=app-admin/eselect-python-20091230" |
| 237 | RDEPEND="${DEPEND}" |
254 | RDEPEND="${DEPEND}" |
|
|
255 | PDEPEND="app-admin/python-updater" |
|
|
256 | fi |
| 238 | |
257 | |
| 239 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
258 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
| 240 | _python_parse_PYTHON_DEPEND |
259 | _python_parse_PYTHON_DEPEND |
| 241 | else |
260 | else |
| 242 | _PYTHON_ATOMS=("dev-lang/python") |
261 | _PYTHON_ATOMS=("dev-lang/python") |
| … | |
… | |
| 281 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
300 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
| 282 | fi |
301 | fi |
| 283 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
302 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
| 284 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
303 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
| 285 | fi |
304 | fi |
| 286 | DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
305 | DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 287 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
306 | RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 288 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
307 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
| 289 | fi |
308 | fi |
| 290 | |
309 | |
| 291 | unset _PYTHON_ATOMS |
310 | unset _PYTHON_ATOMS |
| 292 | |
311 | |
| 293 | # ================================================================================================ |
312 | # ================================================================================================ |
| 294 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
313 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
| 295 | # ================================================================================================ |
314 | # ================================================================================================ |
| 296 | |
|
|
| 297 | _python_implementation() { |
|
|
| 298 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
| 299 | return 0 |
|
|
| 300 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
| 301 | return 0 |
|
|
| 302 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
| 303 | return 0 |
|
|
| 304 | else |
|
|
| 305 | return 1 |
|
|
| 306 | fi |
|
|
| 307 | } |
|
|
| 308 | |
315 | |
| 309 | _python_abi-specific_local_scope() { |
316 | _python_abi-specific_local_scope() { |
| 310 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
317 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
| 311 | } |
318 | } |
| 312 | |
319 | |
| … | |
… | |
| 384 | _CYAN= |
391 | _CYAN= |
| 385 | _NORMAL= |
392 | _NORMAL= |
| 386 | fi |
393 | fi |
| 387 | } |
394 | } |
| 388 | |
395 | |
| 389 | unset PYTHON_PKG_SETUP_EXECUTED |
|
|
| 390 | |
|
|
| 391 | _python_check_python_pkg_setup_execution() { |
396 | _python_check_python_pkg_setup_execution() { |
| 392 | [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return |
397 | [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return |
| 393 | |
398 | |
| 394 | if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then |
399 | if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then |
| 395 | die "python_pkg_setup() not called" |
400 | die "python_pkg_setup() not called" |
| … | |
… | |
| 463 | fi |
468 | fi |
| 464 | |
469 | |
| 465 | PYTHON_PKG_SETUP_EXECUTED="1" |
470 | PYTHON_PKG_SETUP_EXECUTED="1" |
| 466 | } |
471 | } |
| 467 | |
472 | |
| 468 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
|
|
| 469 | EXPORT_FUNCTIONS pkg_setup |
|
|
| 470 | fi |
|
|
| 471 | |
|
|
| 472 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)' |
473 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)' |
| 473 | |
474 | |
| 474 | # @FUNCTION: python_convert_shebangs |
475 | # @FUNCTION: python_convert_shebangs |
| 475 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
476 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
| 476 | # @DESCRIPTION: |
477 | # @DESCRIPTION: |
| 477 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
478 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| 478 | python_convert_shebangs() { |
479 | python_convert_shebangs() { |
| 479 | _python_check_python_pkg_setup_execution |
480 | _python_check_python_pkg_setup_execution |
| 480 | |
481 | |
| 481 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" |
482 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0" |
| 482 | |
483 | |
| 483 | while (($#)); do |
484 | while (($#)); do |
| 484 | case "$1" in |
485 | case "$1" in |
| 485 | -r|--recursive) |
486 | -r|--recursive) |
| 486 | recursive="1" |
487 | recursive="1" |
| … | |
… | |
| 541 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
542 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 542 | |
543 | |
| 543 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
544 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
| 544 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
545 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
| 545 | |
546 | |
|
|
547 | shebangs_converted="1" |
|
|
548 | |
| 546 | if [[ "${quiet}" == "0" ]]; then |
549 | if [[ "${quiet}" == "0" ]]; then |
| 547 | einfo "Converting shebang in '${file}'" |
550 | einfo "Converting shebang in '${file}'" |
| 548 | fi |
551 | fi |
| 549 | |
552 | |
| 550 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
553 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
| 551 | fi |
554 | fi |
|
|
555 | done |
|
|
556 | |
|
|
557 | if [[ "${shebangs_converted}" == "0" ]]; then |
|
|
558 | ewarn "${FUNCNAME}(): Python scripts not found" |
|
|
559 | fi |
|
|
560 | } |
|
|
561 | |
|
|
562 | # @FUNCTION: python_clean_py-compile_files |
|
|
563 | # @USAGE: [-q|--quiet] |
|
|
564 | # @DESCRIPTION: |
|
|
565 | # Clean py-compile files to disable byte-compilation. |
|
|
566 | python_clean_py-compile_files() { |
|
|
567 | _python_check_python_pkg_setup_execution |
|
|
568 | |
|
|
569 | local file files=() quiet="0" |
|
|
570 | |
|
|
571 | while (($#)); do |
|
|
572 | case "$1" in |
|
|
573 | -q|--quiet) |
|
|
574 | quiet="1" |
|
|
575 | ;; |
|
|
576 | -*) |
|
|
577 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
578 | ;; |
|
|
579 | *) |
|
|
580 | die "${FUNCNAME}(): Invalid usage" |
|
|
581 | ;; |
|
|
582 | esac |
|
|
583 | shift |
|
|
584 | done |
|
|
585 | |
|
|
586 | while read -d $'\0' -r file; do |
|
|
587 | files+=("${file#./}") |
|
|
588 | done < <(find -name py-compile -type f -print0) |
|
|
589 | |
|
|
590 | for file in "${files[@]}"; do |
|
|
591 | if [[ "${quiet}" == "0" ]]; then |
|
|
592 | einfo "Cleaning '${file}' file" |
|
|
593 | fi |
|
|
594 | echo "#!/bin/sh" > "${file}" |
| 552 | done |
595 | done |
| 553 | } |
596 | } |
| 554 | |
597 | |
| 555 | # @FUNCTION: python_clean_installation_image |
598 | # @FUNCTION: python_clean_installation_image |
| 556 | # @USAGE: [-q|--quiet] |
599 | # @USAGE: [-q|--quiet] |
| … | |
… | |
| 699 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
742 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 700 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
743 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
| 701 | fi |
744 | fi |
| 702 | fi |
745 | fi |
| 703 | |
746 | |
| 704 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 705 | unset PYTHON_ABIS |
747 | unset PYTHON_ABIS |
| 706 | fi |
|
|
| 707 | |
748 | |
| 708 | _python_calculate_PYTHON_ABIS() { |
749 | _python_calculate_PYTHON_ABIS() { |
| 709 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
750 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 710 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
751 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 711 | fi |
752 | fi |
| … | |
… | |
| 794 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
835 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
| 795 | fi |
836 | fi |
| 796 | else |
837 | else |
| 797 | python3_version="" |
838 | python3_version="" |
| 798 | fi |
839 | fi |
|
|
840 | fi |
|
|
841 | |
|
|
842 | if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then |
|
|
843 | eerror "${CATEGORY}/${PF} requires at least one of the following packages:" |
|
|
844 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
845 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
|
|
846 | eerror " dev-lang/python:${PYTHON_ABI}" |
|
|
847 | fi |
|
|
848 | done |
|
|
849 | die "No supported version of CPython installed" |
| 799 | fi |
850 | fi |
| 800 | |
851 | |
| 801 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
852 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
| 802 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
853 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
| 803 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
854 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
| … | |
… | |
| 961 | python_default_function() { |
1012 | python_default_function() { |
| 962 | emake "$@" |
1013 | emake "$@" |
| 963 | } |
1014 | } |
| 964 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1015 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| 965 | python_default_function() { |
1016 | python_default_function() { |
|
|
1017 | # Stolen from portage's _eapi0_src_test() |
|
|
1018 | local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}" |
| 966 | if emake -j1 -n check &> /dev/null; then |
1019 | if ${emake_cmd} -j1 -n check &> /dev/null; then |
| 967 | emake -j1 check "$@" |
1020 | ${emake_cmd} -j1 check "$@" |
| 968 | elif emake -j1 -n test &> /dev/null; then |
1021 | elif ${emake_cmd} -j1 -n test &> /dev/null; then |
| 969 | emake -j1 test "$@" |
1022 | ${emake_cmd} -j1 test "$@" |
| 970 | fi |
1023 | fi |
| 971 | } |
1024 | } |
| 972 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1025 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
| 973 | python_default_function() { |
1026 | python_default_function() { |
| 974 | emake DESTDIR="${D}" install "$@" |
1027 | emake DESTDIR="${D}" install "$@" |
| … | |
… | |
| 1242 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
1295 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
| 1243 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
1296 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
| 1244 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1297 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 1245 | |
1298 | |
| 1246 | pypy_versions_mapping = { |
1299 | pypy_versions_mapping = { |
| 1247 | "1.5": "2.7" |
1300 | "1.5": "2.7", |
|
|
1301 | "1.6": "2.7", |
|
|
1302 | "1.7": "2.7", |
|
|
1303 | "1.8": "2.7", |
|
|
1304 | "1.9": "2.7", |
| 1248 | } |
1305 | } |
| 1249 | |
1306 | |
| 1250 | def get_PYTHON_ABI(python_interpreter): |
1307 | def get_PYTHON_ABI(python_interpreter): |
| 1251 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
1308 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
| 1252 | jython_matched = jython_interpreter_re.match(python_interpreter) |
1309 | jython_matched = jython_interpreter_re.match(python_interpreter) |
| … | |
… | |
| 1592 | fi |
1649 | fi |
| 1593 | done |
1650 | done |
| 1594 | |
1651 | |
| 1595 | popd > /dev/null || die "popd failed" |
1652 | popd > /dev/null || die "popd failed" |
| 1596 | |
1653 | |
|
|
1654 | # This is per bug #390691, without the duplication refactor, and with |
|
|
1655 | # the 3-way structure per comment #6. This enable users with old |
|
|
1656 | # coreutils to upgrade a lot easier (you need to upgrade python+portage |
|
|
1657 | # before coreutils can be upgraded). |
| 1597 | if ROOT="/" has_version sys-apps/coreutils; then |
1658 | if ROOT="/" has_version '>=sys-apps/coreutils-6.9.90'; then |
| 1598 | cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
1659 | cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
|
|
1660 | elif ROOT="/" has_version sys-apps/coreutils; then |
|
|
1661 | 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" |
| 1599 | else |
1662 | else |
| 1600 | cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
1663 | cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
| 1601 | fi |
1664 | fi |
| 1602 | done |
1665 | done |
| 1603 | |
1666 | |
| … | |
… | |
| 2638 | fi |
2701 | fi |
| 2639 | |
2702 | |
| 2640 | export PYTHONDONTWRITEBYTECODE="1" |
2703 | export PYTHONDONTWRITEBYTECODE="1" |
| 2641 | } |
2704 | } |
| 2642 | |
2705 | |
|
|
2706 | _python_vecho() { |
|
|
2707 | [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@" |
|
|
2708 | } |
|
|
2709 | |
| 2643 | _python_clean_compiled_modules() { |
2710 | _python_clean_compiled_modules() { |
| 2644 | _python_initialize_prefix_variables |
2711 | _python_initialize_prefix_variables |
| 2645 | _python_set_color_variables |
2712 | _python_set_color_variables |
| 2646 | |
2713 | |
| 2647 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
2714 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
| … | |
… | |
| 2660 | |
2727 | |
| 2661 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
2728 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
| 2662 | # Delete empty child directories. |
2729 | # Delete empty child directories. |
| 2663 | find "${path}" -type d | sort -r | while read -r dir; do |
2730 | find "${path}" -type d | sort -r | while read -r dir; do |
| 2664 | if rmdir "${dir}" 2> /dev/null; then |
2731 | if rmdir "${dir}" 2> /dev/null; then |
| 2665 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2732 | _python_vecho "<<< ${dir}" |
| 2666 | fi |
2733 | fi |
| 2667 | done |
2734 | done |
| 2668 | fi |
2735 | fi |
| 2669 | elif [[ "${path}" == *.py ]]; then |
2736 | elif [[ "${path}" == *.py ]]; then |
| 2670 | base_module_name="${path##*/}" |
2737 | base_module_name="${path##*/}" |
| … | |
… | |
| 2693 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2760 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2694 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2761 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2695 | else |
2762 | else |
| 2696 | [[ -f "${py_file}" ]] && continue |
2763 | [[ -f "${py_file}" ]] && continue |
| 2697 | fi |
2764 | fi |
| 2698 | echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" |
2765 | _python_vecho "<<< ${compiled_file%[co]}[co]" |
| 2699 | rm -f "${compiled_file%[co]}"[co] |
2766 | rm -f "${compiled_file%[co]}"[co] |
| 2700 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
2767 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
| 2701 | if [[ "${dir}" == "__pycache__" ]]; then |
2768 | if [[ "${dir}" == "__pycache__" ]]; then |
| 2702 | base_module_name="${compiled_file##*/}" |
2769 | base_module_name="${compiled_file##*/}" |
| 2703 | base_module_name="${base_module_name%\$py.class}" |
2770 | base_module_name="${base_module_name%\$py.class}" |
| … | |
… | |
| 2708 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2775 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2709 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2776 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2710 | else |
2777 | else |
| 2711 | [[ -f "${py_file}" ]] && continue |
2778 | [[ -f "${py_file}" ]] && continue |
| 2712 | fi |
2779 | fi |
| 2713 | echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" |
2780 | _python_vecho "<<< ${compiled_file}" |
| 2714 | rm -f "${compiled_file}" |
2781 | rm -f "${compiled_file}" |
| 2715 | else |
2782 | else |
| 2716 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
2783 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
| 2717 | fi |
2784 | fi |
| 2718 | |
2785 | |
| 2719 | # Delete empty parent directories. |
2786 | # Delete empty parent directories. |
| 2720 | dir="${compiled_file%/*}" |
2787 | dir="${compiled_file%/*}" |
| 2721 | while [[ "${dir}" != "${root}" ]]; do |
2788 | while [[ "${dir}" != "${root}" ]]; do |
| 2722 | if rmdir "${dir}" 2> /dev/null; then |
2789 | if rmdir "${dir}" 2> /dev/null; then |
| 2723 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2790 | _python_vecho "<<< ${dir}" |
| 2724 | else |
2791 | else |
| 2725 | break |
2792 | break |
| 2726 | fi |
2793 | fi |
| 2727 | dir="${dir%/*}" |
2794 | dir="${dir%/*}" |
| 2728 | done |
2795 | done |
| … | |
… | |
| 3108 | } |
3175 | } |
| 3109 | |
3176 | |
| 3110 | # ================================================================================================ |
3177 | # ================================================================================================ |
| 3111 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
3178 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
| 3112 | # ================================================================================================ |
3179 | # ================================================================================================ |
|
|
3180 | |
|
|
3181 | fi # _PYTHON_ECLASS_INHERITED |