| 1 | # Copyright 1999-2011 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.116 2011/07/04 11:27:53 djc Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.134 2011/10/07 10:49:26 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 |
| … | |
… | |
| 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_GLOBALLY_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_GLOBALLY_SUPPORTED_ABIS=(3.0 3.1 3.2 3.3) |
19 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| 20 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
20 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
|
|
21 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.5) |
| 21 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]}) |
22 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 22 | |
23 | |
| 23 | # ================================================================================================ |
24 | # ================================================================================================ |
| 24 | # ===================================== HANDLING OF METADATA ===================================== |
25 | # ===================================== HANDLING OF METADATA ===================================== |
| 25 | # ================================================================================================ |
26 | # ================================================================================================ |
|
|
27 | |
|
|
28 | _PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\.|-|\*|\[|\])+" |
| 26 | |
29 | |
| 27 | _python_check_python_abi_matching() { |
30 | _python_check_python_abi_matching() { |
| 28 | local pattern patterns patterns_list="0" PYTHON_ABI |
31 | local pattern patterns patterns_list="0" PYTHON_ABI |
| 29 | |
32 | |
| 30 | while (($#)); do |
33 | while (($#)); do |
| … | |
… | |
| 57 | |
60 | |
| 58 | if [[ "${pattern}" == *"-cpython" ]]; then |
61 | if [[ "${pattern}" == *"-cpython" ]]; then |
| 59 | [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]] |
62 | [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]] |
| 60 | elif [[ "${pattern}" == *"-jython" ]]; then |
63 | elif [[ "${pattern}" == *"-jython" ]]; then |
| 61 | [[ "${PYTHON_ABI}" == ${pattern} ]] |
64 | [[ "${PYTHON_ABI}" == ${pattern} ]] |
|
|
65 | elif [[ "${pattern}" == *"-pypy-"* ]]; then |
|
|
66 | [[ "${PYTHON_ABI}" == ${pattern} ]] |
| 62 | else |
67 | else |
| 63 | if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
68 | if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
| 64 | [[ "${PYTHON_ABI}" == ${pattern} ]] |
69 | [[ "${PYTHON_ABI}" == ${pattern} ]] |
| 65 | elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
70 | elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
| 66 | [[ "${PYTHON_ABI%-jython}" == ${pattern} ]] |
71 | [[ "${PYTHON_ABI%-jython}" == ${pattern} ]] |
|
|
72 | elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then |
|
|
73 | [[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]] |
| 67 | else |
74 | else |
| 68 | die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'" |
75 | die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'" |
| 69 | fi |
76 | fi |
| 70 | fi |
77 | fi |
| 71 | else |
78 | else |
| … | |
… | |
| 76 | return 0 |
83 | return 0 |
| 77 | fi |
84 | fi |
| 78 | done <<< "${patterns}" |
85 | done <<< "${patterns}" |
| 79 | |
86 | |
| 80 | return 1 |
87 | return 1 |
|
|
88 | fi |
|
|
89 | } |
|
|
90 | |
|
|
91 | _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 |
|
|
94 | return 0 |
|
|
95 | else |
|
|
96 | return 1 |
|
|
97 | fi |
|
|
98 | else |
|
|
99 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
| 81 | fi |
100 | fi |
| 82 | } |
101 | } |
| 83 | |
102 | |
| 84 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
103 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
| 85 | # @DESCRIPTION: |
104 | # @DESCRIPTION: |
| … | |
… | |
| 278 | _python_implementation() { |
297 | _python_implementation() { |
| 279 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
298 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
| 280 | return 0 |
299 | return 0 |
| 281 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
300 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
| 282 | return 0 |
301 | return 0 |
|
|
302 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
303 | return 0 |
| 283 | else |
304 | else |
| 284 | return 1 |
305 | return 1 |
| 285 | fi |
|
|
| 286 | } |
|
|
| 287 | |
|
|
| 288 | _python_package_supporting_installation_for_multiple_python_abis() { |
|
|
| 289 | if [[ "${EBUILD_PHASE}" == "depend" ]]; then |
|
|
| 290 | die "${FUNCNAME}() cannot be used in global scope" |
|
|
| 291 | fi |
|
|
| 292 | |
|
|
| 293 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 294 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
| 295 | return 0 |
|
|
| 296 | else |
|
|
| 297 | return 1 |
|
|
| 298 | fi |
|
|
| 299 | else |
|
|
| 300 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
| 301 | fi |
306 | fi |
| 302 | } |
307 | } |
| 303 | |
308 | |
| 304 | _python_abi-specific_local_scope() { |
309 | _python_abi-specific_local_scope() { |
| 305 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
310 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
| … | |
… | |
| 462 | |
467 | |
| 463 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
468 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
| 464 | EXPORT_FUNCTIONS pkg_setup |
469 | EXPORT_FUNCTIONS pkg_setup |
| 465 | fi |
470 | fi |
| 466 | |
471 | |
| 467 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|python)' |
472 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)' |
| 468 | |
473 | |
| 469 | # @FUNCTION: python_convert_shebangs |
474 | # @FUNCTION: python_convert_shebangs |
| 470 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
475 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
| 471 | # @DESCRIPTION: |
476 | # @DESCRIPTION: |
| 472 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
477 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| … | |
… | |
| 540 | |
545 | |
| 541 | if [[ "${quiet}" == "0" ]]; then |
546 | if [[ "${quiet}" == "0" ]]; then |
| 542 | einfo "Converting shebang in '${file}'" |
547 | einfo "Converting shebang in '${file}'" |
| 543 | fi |
548 | fi |
| 544 | |
549 | |
| 545 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
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" |
| 546 | fi |
551 | fi |
| 547 | done |
552 | done |
| 548 | } |
553 | } |
| 549 | |
554 | |
| 550 | # @FUNCTION: python_clean_installation_image |
555 | # @FUNCTION: python_clean_installation_image |
| … | |
… | |
| 706 | fi |
711 | fi |
| 707 | |
712 | |
| 708 | _python_initial_sanity_checks |
713 | _python_initial_sanity_checks |
| 709 | |
714 | |
| 710 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
715 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
| 711 | local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS |
716 | local PYTHON_ABI |
| 712 | |
|
|
| 713 | restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}" |
|
|
| 714 | |
717 | |
| 715 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
718 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
| 716 | local cpython_enabled="0" |
719 | local cpython_enabled="0" |
| 717 | |
720 | |
| 718 | if [[ -z "${USE_PYTHON}" ]]; then |
721 | if [[ -z "${USE_PYTHON}" ]]; then |
| … | |
… | |
| 726 | |
729 | |
| 727 | if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then |
730 | if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then |
| 728 | cpython_enabled="1" |
731 | cpython_enabled="1" |
| 729 | fi |
732 | fi |
| 730 | |
733 | |
| 731 | support_ABI="1" |
|
|
| 732 | while read restricted_ABI; do |
|
|
| 733 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
734 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
| 734 | support_ABI="0" |
735 | export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
| 735 | break |
|
|
| 736 | fi |
736 | fi |
| 737 | done <<< "${restricted_ABIs}" |
|
|
| 738 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
|
|
| 739 | done |
737 | done |
| 740 | |
738 | |
| 741 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
739 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
| 742 | die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" |
740 | die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" |
| 743 | fi |
741 | fi |
| … | |
… | |
| 759 | die "'${EPREFIX}/usr/bin/python2' is not valid symlink" |
757 | die "'${EPREFIX}/usr/bin/python2' is not valid symlink" |
| 760 | fi |
758 | fi |
| 761 | |
759 | |
| 762 | python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
760 | python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| 763 | |
761 | |
|
|
762 | support_python_major_version="0" |
| 764 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
763 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
764 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
| 765 | support_python_major_version="1" |
765 | support_python_major_version="1" |
| 766 | while read restricted_ABI; do |
766 | break |
| 767 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
|
|
| 768 | support_python_major_version="0" |
|
|
| 769 | fi |
767 | fi |
| 770 | done <<< "${restricted_ABIs}" |
|
|
| 771 | [[ "${support_python_major_version}" == "1" ]] && break |
|
|
| 772 | done |
768 | done |
| 773 | if [[ "${support_python_major_version}" == "1" ]]; then |
769 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 774 | while read restricted_ABI; do |
|
|
| 775 | if _python_check_python_abi_matching "${python2_version}" "${restricted_ABI}"; then |
770 | if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then |
| 776 | die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}" |
771 | die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}" |
| 777 | fi |
772 | fi |
| 778 | done <<< "${restricted_ABIs}" |
|
|
| 779 | else |
773 | else |
| 780 | python2_version="" |
774 | python2_version="" |
| 781 | fi |
775 | fi |
| 782 | fi |
776 | fi |
| 783 | |
777 | |
| … | |
… | |
| 786 | die "'${EPREFIX}/usr/bin/python3' is not valid symlink" |
780 | die "'${EPREFIX}/usr/bin/python3' is not valid symlink" |
| 787 | fi |
781 | fi |
| 788 | |
782 | |
| 789 | python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
783 | python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| 790 | |
784 | |
|
|
785 | support_python_major_version="0" |
| 791 | for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
786 | for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
787 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
| 792 | support_python_major_version="1" |
788 | support_python_major_version="1" |
| 793 | while read restricted_ABI; do |
789 | break |
| 794 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then |
|
|
| 795 | support_python_major_version="0" |
|
|
| 796 | fi |
790 | fi |
| 797 | done <<< "${restricted_ABIs}" |
|
|
| 798 | [[ "${support_python_major_version}" == "1" ]] && break |
|
|
| 799 | done |
791 | done |
| 800 | if [[ "${support_python_major_version}" == "1" ]]; then |
792 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 801 | while read restricted_ABI; do |
|
|
| 802 | if _python_check_python_abi_matching "${python3_version}" "${restricted_ABI}"; then |
793 | if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then |
| 803 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
794 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
| 804 | fi |
795 | fi |
| 805 | done <<< "${restricted_ABIs}" |
|
|
| 806 | else |
796 | else |
| 807 | python3_version="" |
797 | python3_version="" |
| 808 | fi |
798 | fi |
| 809 | fi |
799 | fi |
| 810 | |
800 | |
| … | |
… | |
| 835 | eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"" |
825 | eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"" |
| 836 | for prefix in PYTHON_USER_ PYTHON_; do |
826 | for prefix in PYTHON_USER_ PYTHON_; do |
| 837 | if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then |
827 | if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then |
| 838 | eval "array=(\"\${${prefix}${variable}[@]}\")" |
828 | eval "array=(\"\${${prefix}${variable}[@]}\")" |
| 839 | for element in "${array[@]}"; do |
829 | for element in "${array[@]}"; do |
| 840 | if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then |
830 | if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then |
| 841 | pattern="${element%% *}" |
831 | pattern="${element%% *}" |
| 842 | element="${element#* }" |
832 | element="${element#* }" |
| 843 | operator="${element%% *}" |
833 | operator="${element%% *}" |
| 844 | flags="${element#* }" |
834 | flags="${element#* }" |
| 845 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then |
835 | if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then |
| … | |
… | |
| 1015 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
1005 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
| 1016 | fi |
1006 | fi |
| 1017 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
1007 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 1018 | if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then |
1008 | if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then |
| 1019 | if [[ "${quiet}" == "0" ]]; then |
1009 | if [[ "${quiet}" == "0" ]]; then |
| 1020 | echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version) skipped${_NORMAL}" |
1010 | echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}" |
| 1021 | fi |
1011 | fi |
| 1022 | continue |
1012 | continue |
| 1023 | fi |
1013 | fi |
| 1024 | |
1014 | |
| 1025 | _python_prepare_flags |
1015 | _python_prepare_flags |
| 1026 | |
1016 | |
| 1027 | if [[ "${quiet}" == "0" ]]; then |
1017 | if [[ "${quiet}" == "0" ]]; then |
| 1028 | if [[ -n "${action_message_template}" ]]; then |
1018 | if [[ -n "${action_message_template}" ]]; then |
| 1029 | eval "action_message=\"${action_message_template}\"" |
1019 | eval "action_message=\"${action_message_template}\"" |
| 1030 | else |
1020 | else |
| 1031 | action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." |
1021 | action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)..." |
| 1032 | fi |
1022 | fi |
| 1033 | echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" |
1023 | echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" |
| 1034 | fi |
1024 | fi |
| 1035 | |
1025 | |
| 1036 | if [[ "${separate_build_dirs}" == "1" ]]; then |
1026 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| … | |
… | |
| 1060 | |
1050 | |
| 1061 | if [[ "${return_code}" -ne 0 ]]; then |
1051 | if [[ "${return_code}" -ne 0 ]]; then |
| 1062 | if [[ -n "${failure_message_template}" ]]; then |
1052 | if [[ -n "${failure_message_template}" ]]; then |
| 1063 | eval "failure_message=\"${failure_message_template}\"" |
1053 | eval "failure_message=\"${failure_message_template}\"" |
| 1064 | else |
1054 | else |
| 1065 | failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" |
1055 | failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function" |
| 1066 | fi |
1056 | fi |
| 1067 | |
1057 | |
| 1068 | if [[ "${nonfatal}" == "1" ]]; then |
1058 | if [[ "${nonfatal}" == "1" ]]; then |
| 1069 | if [[ "${quiet}" == "0" ]]; then |
1059 | if [[ "${quiet}" == "0" ]]; then |
| 1070 | ewarn "${failure_message}" |
1060 | ewarn "${failure_message}" |
| … | |
… | |
| 1243 | import subprocess |
1233 | import subprocess |
| 1244 | import sys |
1234 | import sys |
| 1245 | |
1235 | |
| 1246 | cpython_re = re.compile(r"^python(\d+\.\d+)$") |
1236 | cpython_re = re.compile(r"^python(\d+\.\d+)$") |
| 1247 | jython_re = re.compile(r"^jython(\d+\.\d+)$") |
1237 | jython_re = re.compile(r"^jython(\d+\.\d+)$") |
|
|
1238 | pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") |
| 1248 | python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
1239 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
|
|
1240 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
| 1249 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1241 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
|
|
1242 | |
|
|
1243 | pypy_versions_mapping = { |
|
|
1244 | "1.5": "2.7" |
|
|
1245 | } |
| 1250 | |
1246 | |
| 1251 | def get_PYTHON_ABI(EPYTHON): |
1247 | def get_PYTHON_ABI(EPYTHON): |
| 1252 | cpython_matched = cpython_re.match(EPYTHON) |
1248 | cpython_matched = cpython_re.match(EPYTHON) |
| 1253 | jython_matched = jython_re.match(EPYTHON) |
1249 | jython_matched = jython_re.match(EPYTHON) |
|
|
1250 | pypy_matched = pypy_re.match(EPYTHON) |
| 1254 | if cpython_matched is not None: |
1251 | if cpython_matched is not None: |
| 1255 | PYTHON_ABI = cpython_matched.group(1) |
1252 | PYTHON_ABI = cpython_matched.group(1) |
| 1256 | elif jython_matched is not None: |
1253 | elif jython_matched is not None: |
| 1257 | PYTHON_ABI = jython_matched.group(1) + "-jython" |
1254 | PYTHON_ABI = jython_matched.group(1) + "-jython" |
|
|
1255 | elif pypy_matched is not None: |
|
|
1256 | PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1) |
| 1258 | else: |
1257 | else: |
| 1259 | PYTHON_ABI = None |
1258 | PYTHON_ABI = None |
| 1260 | return PYTHON_ABI |
1259 | return PYTHON_ABI |
| 1261 | |
1260 | |
| 1262 | EOF |
1261 | EOF |
| … | |
… | |
| 1267 | cat << EOF >> "${file}" |
1266 | cat << EOF >> "${file}" |
| 1268 | EPYTHON = os.environ.get("EPYTHON") |
1267 | EPYTHON = os.environ.get("EPYTHON") |
| 1269 | if EPYTHON: |
1268 | if EPYTHON: |
| 1270 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
1269 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1271 | if PYTHON_ABI is None: |
1270 | if PYTHON_ABI is None: |
| 1272 | sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) |
1271 | sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) |
| 1273 | sys.exit(1) |
1272 | sys.exit(1) |
| 1274 | else: |
1273 | else: |
| 1275 | try: |
1274 | try: |
|
|
1275 | environment = os.environ.copy() |
|
|
1276 | environment["ROOT"] = "/" |
| 1276 | eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
1277 | eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE) |
| 1277 | if eselect_process.wait() != 0: |
1278 | if eselect_process.wait() != 0: |
| 1278 | raise ValueError |
1279 | raise ValueError |
| 1279 | except (OSError, ValueError): |
1280 | except (OSError, ValueError): |
| 1280 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
1281 | sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) |
| 1281 | sys.exit(1) |
1282 | sys.exit(1) |
| 1282 | |
1283 | |
| 1283 | EPYTHON = eselect_process.stdout.read() |
1284 | EPYTHON = eselect_process.stdout.read() |
| 1284 | if not isinstance(EPYTHON, str): |
1285 | if not isinstance(EPYTHON, str): |
| 1285 | # Python 3 |
1286 | # Python 3 |
| 1286 | EPYTHON = EPYTHON.decode() |
1287 | EPYTHON = EPYTHON.decode() |
| 1287 | EPYTHON = EPYTHON.rstrip("\n") |
1288 | EPYTHON = EPYTHON.rstrip("\n") |
| 1288 | |
1289 | |
| 1289 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
1290 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1290 | if PYTHON_ABI is None: |
1291 | if PYTHON_ABI is None: |
| 1291 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
1292 | sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) |
| 1292 | sys.exit(1) |
1293 | sys.exit(1) |
| 1293 | |
1294 | |
| 1294 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
1295 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 1295 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
1296 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
| 1296 | if not os.path.exists(target_executable_path): |
1297 | if not os.path.exists(target_executable_path): |
| 1297 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
1298 | sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path)) |
| 1298 | sys.exit(1) |
1299 | sys.exit(1) |
| 1299 | EOF |
1300 | EOF |
| 1300 | if [[ "$?" != "0" ]]; then |
1301 | if [[ "$?" != "0" ]]; then |
| 1301 | die "${FUNCNAME}(): Generation of '$1' failed" |
1302 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1302 | fi |
1303 | fi |
| 1303 | else |
1304 | else |
| 1304 | cat << EOF >> "${file}" |
1305 | cat << EOF >> "${file}" |
| 1305 | try: |
1306 | try: |
|
|
1307 | environment = os.environ.copy() |
|
|
1308 | environment["ROOT"] = "/" |
| 1306 | eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
1309 | eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE) |
| 1307 | if eselect_process.wait() != 0: |
1310 | if eselect_process.wait() != 0: |
| 1308 | raise ValueError |
1311 | raise ValueError |
| 1309 | except (OSError, ValueError): |
1312 | except (OSError, ValueError): |
| 1310 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
1313 | sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) |
| 1311 | sys.exit(1) |
1314 | sys.exit(1) |
| 1312 | |
1315 | |
| 1313 | EPYTHON = eselect_process.stdout.read() |
1316 | EPYTHON = eselect_process.stdout.read() |
| 1314 | if not isinstance(EPYTHON, str): |
1317 | if not isinstance(EPYTHON, str): |
| 1315 | # Python 3 |
1318 | # Python 3 |
| 1316 | EPYTHON = EPYTHON.decode() |
1319 | EPYTHON = EPYTHON.decode() |
| 1317 | EPYTHON = EPYTHON.rstrip("\n") |
1320 | EPYTHON = EPYTHON.rstrip("\n") |
| 1318 | |
1321 | |
| 1319 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
1322 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
| 1320 | if PYTHON_ABI is None: |
1323 | if PYTHON_ABI is None: |
| 1321 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
1324 | sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) |
| 1322 | sys.exit(1) |
1325 | sys.exit(1) |
| 1323 | |
1326 | |
| 1324 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
1327 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 1325 | for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: |
1328 | for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: |
| 1326 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
1329 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
| 1327 | if os.path.exists(target_executable_path): |
1330 | if os.path.exists(target_executable_path): |
| 1328 | break |
1331 | break |
| 1329 | else: |
1332 | else: |
| 1330 | sys.stderr.write("No target script exists for '%s'\n" % wrapper_script_path) |
1333 | sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path)) |
| 1331 | sys.exit(1) |
1334 | sys.exit(1) |
| 1332 | EOF |
1335 | EOF |
| 1333 | if [[ "$?" != "0" ]]; then |
1336 | if [[ "$?" != "0" ]]; then |
| 1334 | die "${FUNCNAME}(): Generation of '$1' failed" |
1337 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 1335 | fi |
1338 | fi |
| 1336 | fi |
1339 | fi |
| 1337 | cat << EOF >> "${file}" |
1340 | cat << EOF >> "${file}" |
| 1338 | |
1341 | |
| 1339 | target_executable = open(target_executable_path, "rb") |
1342 | target_executable = open(target_executable_path, "rb") |
| 1340 | target_executable_first_line = target_executable.readline() |
1343 | target_executable_first_line = target_executable.readline() |
|
|
1344 | target_executable.close() |
| 1341 | if not isinstance(target_executable_first_line, str): |
1345 | if not isinstance(target_executable_first_line, str): |
| 1342 | # Python 3 |
1346 | # Python 3 |
| 1343 | target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") |
1347 | target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") |
| 1344 | |
1348 | |
|
|
1349 | options = [] |
|
|
1350 | python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line) |
|
|
1351 | if python_shebang_options_matched is not None: |
|
|
1352 | options = [python_shebang_options_matched.group(1)] |
|
|
1353 | |
| 1345 | python_shebang_matched = python_shebang_re.match(target_executable_first_line) |
1354 | cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line) |
| 1346 | target_executable.close() |
|
|
| 1347 | |
1355 | |
| 1348 | if python_shebang_matched is not None: |
1356 | if cpython_shebang_matched is not None: |
| 1349 | try: |
1357 | try: |
| 1350 | python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
1358 | python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
| 1351 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
1359 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
| 1352 | python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) |
1360 | python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) |
| 1353 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
1361 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
| … | |
… | |
| 1366 | os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) |
1374 | os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) |
| 1367 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
1375 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
| 1368 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
1376 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
| 1369 | |
1377 | |
| 1370 | if hasattr(os, "execv"): |
1378 | if hasattr(os, "execv"): |
| 1371 | os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) |
1379 | os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv) |
| 1372 | else: |
1380 | else: |
| 1373 | sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) |
1381 | sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait()) |
| 1374 | except (KeyboardInterrupt, SystemExit): |
1382 | except (KeyboardInterrupt, SystemExit): |
| 1375 | raise |
1383 | raise |
| 1376 | except: |
1384 | except: |
| 1377 | pass |
1385 | pass |
| 1378 | for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"): |
1386 | for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"): |
| … | |
… | |
| 1420 | fi |
1428 | fi |
| 1421 | |
1429 | |
| 1422 | _python_check_python_pkg_setup_execution |
1430 | _python_check_python_pkg_setup_execution |
| 1423 | _python_initialize_prefix_variables |
1431 | _python_initialize_prefix_variables |
| 1424 | |
1432 | |
| 1425 | local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=() |
1433 | local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=() |
| 1426 | |
1434 | |
| 1427 | while (($#)); do |
1435 | while (($#)); do |
| 1428 | case "$1" in |
1436 | case "$1" in |
| 1429 | -q|--quiet) |
1437 | -q|--quiet) |
| 1430 | quiet="1" |
1438 | quiet="1" |
| … | |
… | |
| 1512 | break |
1520 | break |
| 1513 | fi |
1521 | fi |
| 1514 | done |
1522 | done |
| 1515 | fi |
1523 | fi |
| 1516 | |
1524 | |
| 1517 | [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue |
1525 | [[ "${version_executable}" == "0" ]] && continue |
| 1518 | |
1526 | |
|
|
1527 | if [[ -L "${file}" ]]; then |
|
|
1528 | absolute_file="$(readlink "${file}")" |
|
|
1529 | if [[ "${absolute_file}" == /* ]]; then |
|
|
1530 | absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}" |
|
|
1531 | else |
|
|
1532 | if [[ "${file}" == */* ]]; then |
|
|
1533 | absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}" |
|
|
1534 | else |
|
|
1535 | absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}" |
|
|
1536 | fi |
|
|
1537 | fi |
|
|
1538 | else |
|
|
1539 | absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}" |
|
|
1540 | fi |
|
|
1541 | |
|
|
1542 | [[ ! -x "${absolute_file}" ]] && continue |
|
|
1543 | |
| 1519 | shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed" |
1544 | shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed" |
| 1520 | |
1545 | |
| 1521 | if [[ "${version_executable}" == "2" ]]; then |
1546 | if [[ "${version_executable}" == "2" ]]; then |
| 1522 | wrapper_scripts+=("${ED}${file}") |
1547 | wrapper_scripts+=("${ED}${file}") |
| 1523 | elif [[ "${version_executable}" == "1" ]]; then |
1548 | elif [[ "${version_executable}" == "1" ]]; then |
| 1524 | if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then |
1549 | if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then |
| … | |
… | |
| 1535 | fi |
1560 | fi |
| 1536 | |
1561 | |
| 1537 | mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed" |
1562 | mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed" |
| 1538 | |
1563 | |
| 1539 | if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then |
1564 | if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then |
|
|
1565 | if [[ -L "${file}-${PYTHON_ABI}" ]]; then |
|
|
1566 | python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}" |
|
|
1567 | else |
| 1540 | python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}" |
1568 | python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}" |
|
|
1569 | fi |
| 1541 | fi |
1570 | fi |
| 1542 | done |
1571 | done |
| 1543 | |
1572 | |
| 1544 | popd > /dev/null || die "popd failed" |
1573 | popd > /dev/null || die "popd failed" |
| 1545 | |
1574 | |
| 1546 | if ROOT="/" has_version sys-apps/coreutils; then |
1575 | if ROOT="/" has_version sys-apps/coreutils; then |
| 1547 | cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
1576 | 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" |
| 1548 | else |
1577 | else |
| 1549 | cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
1578 | cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" |
| 1550 | fi |
1579 | fi |
| 1551 | done |
1580 | done |
| 1552 | |
1581 | |
| … | |
… | |
| 1645 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
1674 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
| 1646 | PYTHON_REQUESTED_ACTIVE_VERSION="$1" |
1675 | PYTHON_REQUESTED_ACTIVE_VERSION="$1" |
| 1647 | } |
1676 | } |
| 1648 | |
1677 | |
| 1649 | # @FUNCTION: python_need_rebuild |
1678 | # @FUNCTION: python_need_rebuild |
|
|
1679 | # @DESCRIPTION: |
| 1650 | # @DESCRIPTION: Mark current package for rebuilding by python-updater after |
1680 | # Mark current package for rebuilding by python-updater after |
| 1651 | # switching of active version of Python. |
1681 | # switching of active version of Python. |
| 1652 | python_need_rebuild() { |
1682 | python_need_rebuild() { |
| 1653 | if _python_package_supporting_installation_for_multiple_python_abis; then |
1683 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1654 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
1684 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 1655 | fi |
1685 | fi |
| … | |
… | |
| 1665 | |
1695 | |
| 1666 | # ================================================================================================ |
1696 | # ================================================================================================ |
| 1667 | # ======================================= GETTER FUNCTIONS ======================================= |
1697 | # ======================================= GETTER FUNCTIONS ======================================= |
| 1668 | # ================================================================================================ |
1698 | # ================================================================================================ |
| 1669 | |
1699 | |
| 1670 | _PYTHON_ABI_EXTRACTION_COMMAND='import platform |
1700 | _PYTHON_ABI_EXTRACTION_COMMAND=\ |
|
|
1701 | 'import platform |
| 1671 | import sys |
1702 | import sys |
| 1672 | sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) |
1703 | sys.stdout.write(".".join(str(x) for x in sys.version_info[:2])) |
| 1673 | if platform.system()[:4] == "Java": |
1704 | if platform.system()[:4] == "Java": |
| 1674 | sys.stdout.write("-jython")' |
1705 | sys.stdout.write("-jython") |
|
|
1706 | elif hasattr(platform, "python_implementation") and platform.python_implementation() == "PyPy": |
|
|
1707 | sys.stdout.write("-pypy-" + ".".join(str(x) for x in sys.pypy_version_info[:2]))' |
| 1675 | |
1708 | |
| 1676 | _python_get_implementation() { |
1709 | _python_get_implementation() { |
| 1677 | local ignore_invalid="0" |
1710 | local ignore_invalid="0" |
| 1678 | |
1711 | |
| 1679 | while (($#)); do |
1712 | while (($#)); do |
| … | |
… | |
| 1701 | |
1734 | |
| 1702 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
1735 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
| 1703 | echo "CPython" |
1736 | echo "CPython" |
| 1704 | elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
1737 | elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then |
| 1705 | echo "Jython" |
1738 | echo "Jython" |
|
|
1739 | elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then |
|
|
1740 | echo "PyPy" |
| 1706 | else |
1741 | else |
| 1707 | if [[ "${ignore_invalid}" == "0" ]]; then |
1742 | if [[ "${ignore_invalid}" == "0" ]]; then |
| 1708 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
1743 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
| 1709 | fi |
1744 | fi |
| 1710 | fi |
1745 | fi |
| … | |
… | |
| 1773 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
1808 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 1774 | fi |
1809 | fi |
| 1775 | _python_calculate_PYTHON_ABIS |
1810 | _python_calculate_PYTHON_ABIS |
| 1776 | PYTHON_ABI="${PYTHON_ABIS##* }" |
1811 | PYTHON_ABI="${PYTHON_ABIS##* }" |
| 1777 | elif [[ "${python2}" == "1" ]]; then |
1812 | elif [[ "${python2}" == "1" ]]; then |
| 1778 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
1813 | PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)" |
| 1779 | if [[ -z "${PYTHON_ABI}" ]]; then |
1814 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1780 | die "${FUNCNAME}(): Active version of CPython 2 not set" |
1815 | die "${FUNCNAME}(): Active version of CPython 2 not set" |
| 1781 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
1816 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
| 1782 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
1817 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
| 1783 | fi |
1818 | fi |
| 1784 | elif [[ "${python3}" == "1" ]]; then |
1819 | elif [[ "${python3}" == "1" ]]; then |
| 1785 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
1820 | PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)" |
| 1786 | if [[ -z "${PYTHON_ABI}" ]]; then |
1821 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1787 | die "${FUNCNAME}(): Active version of CPython 3 not set" |
1822 | die "${FUNCNAME}(): Active version of CPython 3 not set" |
| 1788 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
1823 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
| 1789 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
1824 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
| 1790 | fi |
1825 | fi |
| … | |
… | |
| 1819 | else |
1854 | else |
| 1820 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1855 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1821 | python_interpreter="python${PYTHON_ABI}" |
1856 | python_interpreter="python${PYTHON_ABI}" |
| 1822 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1857 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1823 | python_interpreter="jython${PYTHON_ABI%-jython}" |
1858 | python_interpreter="jython${PYTHON_ABI%-jython}" |
|
|
1859 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
1860 | python_interpreter="pypy-c${PYTHON_ABI#*-pypy-}" |
| 1824 | fi |
1861 | fi |
| 1825 | |
1862 | |
| 1826 | if [[ "${absolute_path_output}" == "1" ]]; then |
1863 | if [[ "${absolute_path_output}" == "1" ]]; then |
| 1827 | echo -n "${EPREFIX}/usr/bin/${python_interpreter}" |
1864 | echo -n "${EPREFIX}/usr/bin/${python_interpreter}" |
| 1828 | else |
1865 | else |
| … | |
… | |
| 1921 | if [[ "${EAPI:-0}" == "0" ]]; then |
1958 | if [[ "${EAPI:-0}" == "0" ]]; then |
| 1922 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1959 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1923 | echo "=dev-lang/python-${PYTHON_ABI}*" |
1960 | echo "=dev-lang/python-${PYTHON_ABI}*" |
| 1924 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1961 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1925 | echo "=dev-java/jython-${PYTHON_ABI%-jython}*" |
1962 | echo "=dev-java/jython-${PYTHON_ABI%-jython}*" |
|
|
1963 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
1964 | echo "=dev-python/pypy-${PYTHON_ABI#*-pypy-}*" |
| 1926 | fi |
1965 | fi |
| 1927 | else |
1966 | else |
| 1928 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1967 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1929 | echo "dev-lang/python:${PYTHON_ABI}" |
1968 | echo "dev-lang/python:${PYTHON_ABI}" |
| 1930 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1969 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1931 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
1970 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
|
|
1971 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
1972 | echo "dev-python/pypy:${PYTHON_ABI#*-pypy-}" |
| 1932 | fi |
1973 | fi |
| 1933 | fi |
1974 | fi |
| 1934 | } |
1975 | } |
| 1935 | |
1976 | |
| 1936 | # @FUNCTION: python_get_includedir |
1977 | # @FUNCTION: python_get_includedir |
| … | |
… | |
| 1983 | |
2024 | |
| 1984 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
2025 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1985 | echo "${prefix}usr/include/python${PYTHON_ABI}" |
2026 | echo "${prefix}usr/include/python${PYTHON_ABI}" |
| 1986 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
2027 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1987 | echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include" |
2028 | echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include" |
|
|
2029 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
2030 | echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/include" |
| 1988 | fi |
2031 | fi |
| 1989 | } |
2032 | } |
| 1990 | |
2033 | |
| 1991 | # @FUNCTION: python_get_libdir |
2034 | # @FUNCTION: python_get_libdir |
| 1992 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
2035 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
| 1993 | # @DESCRIPTION: |
2036 | # @DESCRIPTION: |
| 1994 | # Print path to Python library directory. |
2037 | # Print path to Python standard library directory. |
| 1995 | # If --base-path option is specified, then path not prefixed with "/" is printed. |
2038 | # If --base-path option is specified, then path not prefixed with "/" is printed. |
| 1996 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
2039 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 1997 | python_get_libdir() { |
2040 | python_get_libdir() { |
| 1998 | _python_check_python_pkg_setup_execution |
2041 | _python_check_python_pkg_setup_execution |
| 1999 | |
2042 | |
| … | |
… | |
| 2038 | |
2081 | |
| 2039 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
2082 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 2040 | echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}" |
2083 | echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}" |
| 2041 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
2084 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 2042 | echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib" |
2085 | echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib" |
|
|
2086 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
2087 | die "${FUNCNAME}(): PyPy has multiple standard library directories" |
| 2043 | fi |
2088 | fi |
| 2044 | } |
2089 | } |
| 2045 | |
2090 | |
| 2046 | # @FUNCTION: python_get_sitedir |
2091 | # @FUNCTION: python_get_sitedir |
| 2047 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
2092 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
| … | |
… | |
| 2050 | # If --base-path option is specified, then path not prefixed with "/" is printed. |
2095 | # If --base-path option is specified, then path not prefixed with "/" is printed. |
| 2051 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
2096 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 2052 | python_get_sitedir() { |
2097 | python_get_sitedir() { |
| 2053 | _python_check_python_pkg_setup_execution |
2098 | _python_check_python_pkg_setup_execution |
| 2054 | |
2099 | |
| 2055 | local final_ABI="0" options=() |
2100 | local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}" |
| 2056 | |
2101 | |
| 2057 | while (($#)); do |
2102 | while (($#)); do |
| 2058 | case "$1" in |
2103 | case "$1" in |
| 2059 | -b|--base-path) |
2104 | -b|--base-path) |
| 2060 | options+=("$1") |
2105 | base_path="1" |
| 2061 | ;; |
2106 | ;; |
| 2062 | -f|--final-ABI) |
2107 | -f|--final-ABI) |
| 2063 | final_ABI="1" |
2108 | final_ABI="1" |
| 2064 | options+=("$1") |
|
|
| 2065 | ;; |
2109 | ;; |
| 2066 | -*) |
2110 | -*) |
| 2067 | die "${FUNCNAME}(): Unrecognized option '$1'" |
2111 | die "${FUNCNAME}(): Unrecognized option '$1'" |
| 2068 | ;; |
2112 | ;; |
| 2069 | *) |
2113 | *) |
| 2070 | die "${FUNCNAME}(): Invalid usage" |
2114 | die "${FUNCNAME}(): Invalid usage" |
| 2071 | ;; |
2115 | ;; |
| 2072 | esac |
2116 | esac |
| 2073 | shift |
2117 | shift |
| 2074 | done |
2118 | done |
|
|
2119 | |
|
|
2120 | if [[ "${base_path}" == "0" ]]; then |
|
|
2121 | prefix="/" |
|
|
2122 | fi |
| 2075 | |
2123 | |
| 2076 | if [[ "${final_ABI}" == "1" ]]; then |
2124 | if [[ "${final_ABI}" == "1" ]]; then |
| 2077 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
2125 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2078 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2126 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2079 | fi |
2127 | fi |
|
|
2128 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 2080 | else |
2129 | else |
| 2081 | if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then |
2130 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2131 | if ! _python_abi-specific_local_scope; then |
| 2082 | die "${FUNCNAME}() should be used in ABI-specific local scope" |
2132 | die "${FUNCNAME}() should be used in ABI-specific local scope" |
| 2083 | fi |
2133 | fi |
|
|
2134 | else |
|
|
2135 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
| 2084 | fi |
2136 | fi |
|
|
2137 | fi |
| 2085 | |
2138 | |
| 2086 | echo "$(python_get_libdir "${options[@]}")/site-packages" |
2139 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
|
|
2140 | echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}/site-packages" |
|
|
2141 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
|
|
2142 | echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib/site-packages" |
|
|
2143 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
2144 | echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/site-packages" |
|
|
2145 | fi |
| 2087 | } |
2146 | } |
| 2088 | |
2147 | |
| 2089 | # @FUNCTION: python_get_library |
2148 | # @FUNCTION: python_get_library |
| 2090 | # @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option] |
2149 | # @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option] |
| 2091 | # @DESCRIPTION: |
2150 | # @DESCRIPTION: |
| … | |
… | |
| 2148 | else |
2207 | else |
| 2149 | echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" |
2208 | echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" |
| 2150 | fi |
2209 | fi |
| 2151 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
2210 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 2152 | die "${FUNCNAME}(): Jython does not have shared library" |
2211 | die "${FUNCNAME}(): Jython does not have shared library" |
|
|
2212 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
2213 | die "${FUNCNAME}(): PyPy does not have shared library" |
| 2153 | fi |
2214 | fi |
| 2154 | } |
2215 | } |
| 2155 | |
2216 | |
| 2156 | # @FUNCTION: python_get_version |
2217 | # @FUNCTION: python_get_version |
| 2157 | # @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] |
2218 | # @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro] |
| 2158 | # @DESCRIPTION: |
2219 | # @DESCRIPTION: |
| 2159 | # Print Python version. |
2220 | # Print version of Python implementation. |
| 2160 | # --full, --major, --minor and --micro options cannot be specified simultaneously. |
2221 | # --full, --major, --minor and --micro options cannot be specified simultaneously. |
| 2161 | # If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. |
2222 | # If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. |
|
|
2223 | # If --language option is specified, then version of Python language is printed. |
|
|
2224 | # --language and --full options cannot be specified simultaneously. |
|
|
2225 | # --language and --micro options cannot be specified simultaneously. |
| 2162 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
2226 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 2163 | python_get_version() { |
2227 | python_get_version() { |
| 2164 | _python_check_python_pkg_setup_execution |
2228 | _python_check_python_pkg_setup_execution |
| 2165 | |
2229 | |
| 2166 | local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command |
2230 | local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command |
| 2167 | |
2231 | |
| 2168 | while (($#)); do |
2232 | while (($#)); do |
| 2169 | case "$1" in |
2233 | case "$1" in |
| 2170 | -f|--final-ABI) |
2234 | -f|--final-ABI) |
| 2171 | final_ABI="1" |
2235 | final_ABI="1" |
| 2172 | ;; |
2236 | ;; |
|
|
2237 | -l|--language) |
|
|
2238 | language="1" |
|
|
2239 | ;; |
| 2173 | --full) |
2240 | --full) |
| 2174 | full="1" |
2241 | full="1" |
| 2175 | ;; |
2242 | ;; |
| 2176 | --major) |
2243 | --major) |
| 2177 | major="1" |
2244 | major="1" |
| … | |
… | |
| 2189 | die "${FUNCNAME}(): Invalid usage" |
2256 | die "${FUNCNAME}(): Invalid usage" |
| 2190 | ;; |
2257 | ;; |
| 2191 | esac |
2258 | esac |
| 2192 | shift |
2259 | shift |
| 2193 | done |
2260 | done |
| 2194 | |
|
|
| 2195 | if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then |
|
|
| 2196 | die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously" |
|
|
| 2197 | fi |
|
|
| 2198 | |
|
|
| 2199 | if [[ "${full}" == "1" ]]; then |
|
|
| 2200 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))" |
|
|
| 2201 | elif [[ "${major}" == "1" ]]; then |
|
|
| 2202 | python_command="from sys import version_info; print(version_info[0])" |
|
|
| 2203 | elif [[ "${minor}" == "1" ]]; then |
|
|
| 2204 | python_command="from sys import version_info; print(version_info[1])" |
|
|
| 2205 | elif [[ "${micro}" == "1" ]]; then |
|
|
| 2206 | python_command="from sys import version_info; print(version_info[2])" |
|
|
| 2207 | else |
|
|
| 2208 | if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then |
|
|
| 2209 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
|
|
| 2210 | echo "${PYTHON_ABI}" |
|
|
| 2211 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
|
|
| 2212 | echo "${PYTHON_ABI%-jython}" |
|
|
| 2213 | fi |
|
|
| 2214 | return |
|
|
| 2215 | fi |
|
|
| 2216 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" |
|
|
| 2217 | fi |
|
|
| 2218 | |
2261 | |
| 2219 | if [[ "${final_ABI}" == "1" ]]; then |
2262 | if [[ "${final_ABI}" == "1" ]]; then |
| 2220 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
2263 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2221 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2264 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2222 | fi |
2265 | fi |
| 2223 | "$(PYTHON -f)" -c "${python_command}" |
|
|
| 2224 | else |
2266 | else |
| 2225 | if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then |
2267 | if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then |
| 2226 | die "${FUNCNAME}() should be used in ABI-specific local scope" |
2268 | die "${FUNCNAME}() should be used in ABI-specific local scope" |
| 2227 | fi |
2269 | fi |
|
|
2270 | fi |
|
|
2271 | |
|
|
2272 | if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then |
|
|
2273 | die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously" |
|
|
2274 | fi |
|
|
2275 | |
|
|
2276 | if [[ "${language}" == "1" ]]; then |
|
|
2277 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
2278 | PYTHON_ABI="$(PYTHON -f --ABI)" |
|
|
2279 | elif [[ -z "${PYTHON_ABI}" ]]; then |
|
|
2280 | PYTHON_ABI="$(PYTHON --ABI)" |
|
|
2281 | fi |
|
|
2282 | language_version="${PYTHON_ABI%%-*}" |
|
|
2283 | if [[ "${full}" == "1" ]]; then |
|
|
2284 | die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously" |
|
|
2285 | elif [[ "${major}" == "1" ]]; then |
|
|
2286 | echo "${language_version%.*}" |
|
|
2287 | elif [[ "${minor}" == "1" ]]; then |
|
|
2288 | echo "${language_version#*.}" |
|
|
2289 | elif [[ "${micro}" == "1" ]]; then |
|
|
2290 | die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously" |
|
|
2291 | else |
|
|
2292 | echo "${language_version}" |
|
|
2293 | fi |
|
|
2294 | else |
|
|
2295 | if [[ "${full}" == "1" ]]; then |
|
|
2296 | python_command="import sys; print('.'.join(str(x) for x in getattr(sys, 'pypy_version_info', sys.version_info)[:3]))" |
|
|
2297 | elif [[ "${major}" == "1" ]]; then |
|
|
2298 | python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[0])" |
|
|
2299 | elif [[ "${minor}" == "1" ]]; then |
|
|
2300 | python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[1])" |
|
|
2301 | elif [[ "${micro}" == "1" ]]; then |
|
|
2302 | python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[2])" |
|
|
2303 | else |
|
|
2304 | if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then |
|
|
2305 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
|
|
2306 | echo "${PYTHON_ABI}" |
|
|
2307 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
|
|
2308 | echo "${PYTHON_ABI%-jython}" |
|
|
2309 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then |
|
|
2310 | echo "${PYTHON_ABI#*-pypy-}" |
|
|
2311 | fi |
|
|
2312 | return |
|
|
2313 | fi |
|
|
2314 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" |
|
|
2315 | fi |
|
|
2316 | |
|
|
2317 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
2318 | "$(PYTHON -f)" -c "${python_command}" |
|
|
2319 | else |
| 2228 | "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
2320 | "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
|
|
2321 | fi |
|
|
2322 | fi |
|
|
2323 | } |
|
|
2324 | |
|
|
2325 | # @FUNCTION: python_get_implementation_and_version |
|
|
2326 | # @USAGE: [-f|--final-ABI] |
|
|
2327 | # @DESCRIPTION: |
|
|
2328 | # Print name and version of Python implementation. |
|
|
2329 | # If version of Python implementation is not bound to version of Python language, then |
|
|
2330 | # version of Python language is additionally printed. |
|
|
2331 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
|
|
2332 | python_get_implementation_and_version() { |
|
|
2333 | _python_check_python_pkg_setup_execution |
|
|
2334 | |
|
|
2335 | local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" |
|
|
2336 | |
|
|
2337 | while (($#)); do |
|
|
2338 | case "$1" in |
|
|
2339 | -f|--final-ABI) |
|
|
2340 | final_ABI="1" |
|
|
2341 | ;; |
|
|
2342 | -*) |
|
|
2343 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
2344 | ;; |
|
|
2345 | *) |
|
|
2346 | die "${FUNCNAME}(): Invalid usage" |
|
|
2347 | ;; |
|
|
2348 | esac |
|
|
2349 | shift |
|
|
2350 | done |
|
|
2351 | |
|
|
2352 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
2353 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2354 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
2355 | fi |
|
|
2356 | PYTHON_ABI="$(PYTHON -f --ABI)" |
|
|
2357 | else |
|
|
2358 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2359 | if ! _python_abi-specific_local_scope; then |
|
|
2360 | die "${FUNCNAME}() should be used in ABI-specific local scope" |
|
|
2361 | fi |
|
|
2362 | else |
|
|
2363 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
|
|
2364 | fi |
|
|
2365 | fi |
|
|
2366 | |
|
|
2367 | if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then |
|
|
2368 | echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})" |
|
|
2369 | else |
|
|
2370 | echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}" |
| 2229 | fi |
2371 | fi |
| 2230 | } |
2372 | } |
| 2231 | |
2373 | |
| 2232 | # ================================================================================================ |
2374 | # ================================================================================================ |
| 2233 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
2375 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
| … | |
… | |
| 2579 | _python_check_python_pkg_setup_execution |
2721 | _python_check_python_pkg_setup_execution |
| 2580 | _python_initialize_prefix_variables |
2722 | _python_initialize_prefix_variables |
| 2581 | |
2723 | |
| 2582 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then |
2724 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then |
| 2583 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
2725 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
| 2584 | local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() |
2726 | 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 |
| 2585 | |
2727 | |
| 2586 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2728 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2587 | if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then |
2729 | if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then |
| 2588 | die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" |
2730 | die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" |
| 2589 | fi |
2731 | fi |
| … | |
… | |
| 2684 | options+=("-q") |
2826 | options+=("-q") |
| 2685 | |
2827 | |
| 2686 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
2828 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 2687 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then |
2829 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then |
| 2688 | return_code="0" |
2830 | return_code="0" |
|
|
2831 | stderr="" |
| 2689 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
2832 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)" |
| 2690 | if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then |
2833 | if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then |
| 2691 | for dir in "${site_packages_dirs[@]}"; do |
2834 | for dir in "${site_packages_dirs[@]}"; do |
| 2692 | dirs+=("${root}$(python_get_sitedir)/${dir}") |
2835 | dirs+=("${root}$(python_get_sitedir)/${dir}") |
| 2693 | done |
2836 | done |
| 2694 | for dir in "${evaluated_dirs[@]}"; do |
2837 | for dir in "${evaluated_dirs[@]}"; do |
| 2695 | eval "dirs+=(\"\${root}${dir}\")" |
2838 | eval "dirs+=(\"\${root}${dir}\")" |
| 2696 | done |
2839 | done |
| 2697 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1" |
2840 | stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1" |
| 2698 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2841 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2699 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" |
2842 | "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" |
| 2700 | fi |
2843 | fi |
| 2701 | _python_clean_compiled_modules "${dirs[@]}" |
2844 | _python_clean_compiled_modules "${dirs[@]}" |
| 2702 | fi |
2845 | fi |
| 2703 | if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then |
2846 | if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then |
| 2704 | for file in "${site_packages_files[@]}"; do |
2847 | for file in "${site_packages_files[@]}"; do |
| 2705 | files+=("${root}$(python_get_sitedir)/${file}") |
2848 | files+=("${root}$(python_get_sitedir)/${file}") |
| 2706 | done |
2849 | done |
| 2707 | for file in "${evaluated_files[@]}"; do |
2850 | for file in "${evaluated_files[@]}"; do |
| 2708 | eval "files+=(\"\${root}${file}\")" |
2851 | eval "files+=(\"\${root}${file}\")" |
| 2709 | done |
2852 | done |
| 2710 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1" |
2853 | stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1" |
| 2711 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2854 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2712 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1" |
2855 | "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" |
| 2713 | fi |
2856 | fi |
| 2714 | _python_clean_compiled_modules "${files[@]}" |
2857 | _python_clean_compiled_modules "${files[@]}" |
| 2715 | fi |
2858 | fi |
| 2716 | eend "${return_code}" |
2859 | eend "${return_code}" |
|
|
2860 | if [[ -n "${stderr}" ]]; then |
|
|
2861 | eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &> /dev/null |
|
|
2862 | while read stderr_line; do |
|
|
2863 | eerror " ${stderr_line}" |
|
|
2864 | done <<< "${stderr}" |
|
|
2865 | fi |
| 2717 | fi |
2866 | fi |
| 2718 | unset dirs files |
2867 | unset dirs files |
| 2719 | done |
2868 | done |
| 2720 | |
2869 | |
| 2721 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2870 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| … | |
… | |
| 2727 | fi |
2876 | fi |
| 2728 | fi |
2877 | fi |
| 2729 | |
2878 | |
| 2730 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
2879 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 2731 | return_code="0" |
2880 | return_code="0" |
|
|
2881 | stderr="" |
| 2732 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" |
2882 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)" |
| 2733 | if ((${#other_dirs[@]})); then |
2883 | if ((${#other_dirs[@]})); then |
| 2734 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
2884 | stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1" |
| 2735 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2885 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2736 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
2886 | "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 2737 | fi |
2887 | fi |
| 2738 | _python_clean_compiled_modules "${other_dirs[@]}" |
2888 | _python_clean_compiled_modules "${other_dirs[@]}" |
| 2739 | fi |
2889 | fi |
| 2740 | if ((${#other_files[@]})); then |
2890 | if ((${#other_files[@]})); then |
| 2741 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
2891 | stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1" |
| 2742 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2892 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2743 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
2893 | "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1" |
| 2744 | fi |
2894 | fi |
| 2745 | _python_clean_compiled_modules "${other_files[@]}" |
2895 | _python_clean_compiled_modules "${other_files[@]}" |
| 2746 | fi |
2896 | fi |
| 2747 | eend "${return_code}" |
2897 | eend "${return_code}" |
|
|
2898 | if [[ -n "${stderr}" ]]; then |
|
|
2899 | eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &> /dev/null |
|
|
2900 | while read stderr_line; do |
|
|
2901 | eerror " ${stderr_line}" |
|
|
2902 | done <<< "${stderr}" |
|
|
2903 | fi |
| 2748 | fi |
2904 | fi |
| 2749 | else |
2905 | else |
| 2750 | # Deprecated part of python_mod_optimize() |
2906 | # Deprecated part of python_mod_optimize() |
| 2751 | ewarn |
2907 | ewarn |
| 2752 | ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" |
2908 | ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" |