| 1 | # Copyright 1999-2012 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.152 2012/03/07 04:13:27 floppym Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.161 2012/11/24 21:07:14 mgorny 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 | if [[ ${_PYTHON_UTILS_R1} ]]; then |
|
|
13 | die 'python.eclass can not be used with python-r1 suite eclasses.' |
|
|
14 | fi |
|
|
15 | |
| 12 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
16 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
| 13 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
17 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 14 | inherit multilib |
18 | inherit multilib |
| 15 | fi |
19 | fi |
| 16 | |
20 | |
| … | |
… | |
| 21 | |
25 | |
| 22 | # Avoid processing this eclass more than once. |
26 | # Avoid processing this eclass more than once. |
| 23 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
27 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 24 | _PYTHON_ECLASS_INHERITED="1" |
28 | _PYTHON_ECLASS_INHERITED="1" |
| 25 | |
29 | |
| 26 | if ! has "${EAPI:-0}" 0 1 2 3 4; then |
30 | if ! has "${EAPI:-0}" 0 1 2 3 4 5; then |
| 27 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
31 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
| 28 | fi |
32 | fi |
| 29 | |
33 | |
| 30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
34 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
35 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3) |
| 32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
36 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) |
37 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9) |
| 34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
38 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 35 | |
39 | |
| 36 | # ================================================================================================ |
40 | # ================================================================================================ |
| 37 | # ===================================== HANDLING OF METADATA ===================================== |
41 | # ===================================== HANDLING OF METADATA ===================================== |
| 38 | # ================================================================================================ |
42 | # ================================================================================================ |
| … | |
… | |
| 98 | |
102 | |
| 99 | return 1 |
103 | return 1 |
| 100 | fi |
104 | fi |
| 101 | } |
105 | } |
| 102 | |
106 | |
|
|
107 | _python_implementation() { |
|
|
108 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
109 | return 0 |
|
|
110 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
111 | return 0 |
|
|
112 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
113 | return 0 |
|
|
114 | else |
|
|
115 | return 1 |
|
|
116 | fi |
|
|
117 | } |
|
|
118 | |
| 103 | _python_package_supporting_installation_for_multiple_python_abis() { |
119 | _python_package_supporting_installation_for_multiple_python_abis() { |
| 104 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 105 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
120 | [[ -n "${SUPPORT_PYTHON_ABIS}" ]] |
| 106 | return 0 |
|
|
| 107 | else |
|
|
| 108 | return 1 |
|
|
| 109 | fi |
|
|
| 110 | else |
|
|
| 111 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
| 112 | fi |
|
|
| 113 | } |
121 | } |
| 114 | |
122 | |
| 115 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
123 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
| 116 | # @DESCRIPTION: |
124 | # @DESCRIPTION: |
| 117 | # Specification of dependency on dev-lang/python. |
125 | # Specification of dependency on dev-lang/python. |
| … | |
… | |
| 243 | else |
251 | else |
| 244 | die "Invalid syntax of PYTHON_DEPEND" |
252 | die "Invalid syntax of PYTHON_DEPEND" |
| 245 | fi |
253 | fi |
| 246 | } |
254 | } |
| 247 | |
255 | |
|
|
256 | if _python_implementation; then |
| 248 | DEPEND=">=app-admin/eselect-python-20091230" |
257 | DEPEND=">=app-admin/eselect-python-20091230" |
| 249 | RDEPEND="${DEPEND}" |
258 | RDEPEND="${DEPEND}" |
|
|
259 | PDEPEND="app-admin/python-updater" |
|
|
260 | fi |
| 250 | |
261 | |
| 251 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
262 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
| 252 | _python_parse_PYTHON_DEPEND |
263 | _python_parse_PYTHON_DEPEND |
| 253 | else |
264 | else |
| 254 | _PYTHON_ATOMS=("dev-lang/python") |
265 | _PYTHON_ATOMS=("dev-lang/python") |
| … | |
… | |
| 293 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
304 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
| 294 | fi |
305 | fi |
| 295 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
306 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
| 296 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
307 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
| 297 | fi |
308 | fi |
| 298 | DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
309 | DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 299 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
310 | RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 300 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
311 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
| 301 | fi |
312 | fi |
| 302 | |
313 | |
| 303 | unset _PYTHON_ATOMS |
314 | unset _PYTHON_ATOMS |
| 304 | |
315 | |
| 305 | # ================================================================================================ |
316 | # ================================================================================================ |
| 306 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
317 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
| 307 | # ================================================================================================ |
318 | # ================================================================================================ |
| 308 | |
|
|
| 309 | _python_implementation() { |
|
|
| 310 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
| 311 | return 0 |
|
|
| 312 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
| 313 | return 0 |
|
|
| 314 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
| 315 | return 0 |
|
|
| 316 | else |
|
|
| 317 | return 1 |
|
|
| 318 | fi |
|
|
| 319 | } |
|
|
| 320 | |
319 | |
| 321 | _python_abi-specific_local_scope() { |
320 | _python_abi-specific_local_scope() { |
| 322 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
321 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
| 323 | } |
322 | } |
| 324 | |
323 | |
| … | |
… | |
| 747 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
746 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 748 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
747 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
| 749 | fi |
748 | fi |
| 750 | fi |
749 | fi |
| 751 | |
750 | |
| 752 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 753 | unset PYTHON_ABIS |
751 | unset PYTHON_ABIS |
| 754 | fi |
|
|
| 755 | |
752 | |
| 756 | _python_calculate_PYTHON_ABIS() { |
753 | _python_calculate_PYTHON_ABIS() { |
| 757 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
754 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 758 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
755 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 759 | fi |
756 | fi |
| 760 | |
757 | |
| 761 | _python_initial_sanity_checks |
758 | _python_initial_sanity_checks |
| 762 | |
759 | |
| 763 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
760 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then |
| 764 | local PYTHON_ABI |
761 | local PYTHON_ABI |
| 765 | |
762 | |
| 766 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
763 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
| 767 | local cpython_enabled="0" |
764 | local cpython_enabled="0" |
| 768 | |
765 | |
| … | |
… | |
| 1302 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
1299 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
| 1303 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
1300 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
| 1304 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1301 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 1305 | |
1302 | |
| 1306 | pypy_versions_mapping = { |
1303 | pypy_versions_mapping = { |
| 1307 | "1.5": "2.7" |
1304 | "1.5": "2.7", |
|
|
1305 | "1.6": "2.7", |
|
|
1306 | "1.7": "2.7", |
|
|
1307 | "1.8": "2.7", |
|
|
1308 | "1.9": "2.7", |
| 1308 | } |
1309 | } |
| 1309 | |
1310 | |
| 1310 | def get_PYTHON_ABI(python_interpreter): |
1311 | def get_PYTHON_ABI(python_interpreter): |
| 1311 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
1312 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
| 1312 | jython_matched = jython_interpreter_re.match(python_interpreter) |
1313 | jython_matched = jython_interpreter_re.match(python_interpreter) |
| … | |
… | |
| 2704 | fi |
2705 | fi |
| 2705 | |
2706 | |
| 2706 | export PYTHONDONTWRITEBYTECODE="1" |
2707 | export PYTHONDONTWRITEBYTECODE="1" |
| 2707 | } |
2708 | } |
| 2708 | |
2709 | |
|
|
2710 | _python_vecho() { |
|
|
2711 | [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@" |
|
|
2712 | } |
|
|
2713 | |
| 2709 | _python_clean_compiled_modules() { |
2714 | _python_clean_compiled_modules() { |
| 2710 | _python_initialize_prefix_variables |
2715 | _python_initialize_prefix_variables |
| 2711 | _python_set_color_variables |
2716 | _python_set_color_variables |
| 2712 | |
2717 | |
| 2713 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
2718 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
| … | |
… | |
| 2726 | |
2731 | |
| 2727 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
2732 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
| 2728 | # Delete empty child directories. |
2733 | # Delete empty child directories. |
| 2729 | find "${path}" -type d | sort -r | while read -r dir; do |
2734 | find "${path}" -type d | sort -r | while read -r dir; do |
| 2730 | if rmdir "${dir}" 2> /dev/null; then |
2735 | if rmdir "${dir}" 2> /dev/null; then |
| 2731 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2736 | _python_vecho "<<< ${dir}" |
| 2732 | fi |
2737 | fi |
| 2733 | done |
2738 | done |
| 2734 | fi |
2739 | fi |
| 2735 | elif [[ "${path}" == *.py ]]; then |
2740 | elif [[ "${path}" == *.py ]]; then |
| 2736 | base_module_name="${path##*/}" |
2741 | base_module_name="${path##*/}" |
| … | |
… | |
| 2759 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2764 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2760 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2765 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2761 | else |
2766 | else |
| 2762 | [[ -f "${py_file}" ]] && continue |
2767 | [[ -f "${py_file}" ]] && continue |
| 2763 | fi |
2768 | fi |
| 2764 | echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" |
2769 | _python_vecho "<<< ${compiled_file%[co]}[co]" |
| 2765 | rm -f "${compiled_file%[co]}"[co] |
2770 | rm -f "${compiled_file%[co]}"[co] |
| 2766 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
2771 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
| 2767 | if [[ "${dir}" == "__pycache__" ]]; then |
2772 | if [[ "${dir}" == "__pycache__" ]]; then |
| 2768 | base_module_name="${compiled_file##*/}" |
2773 | base_module_name="${compiled_file##*/}" |
| 2769 | base_module_name="${base_module_name%\$py.class}" |
2774 | base_module_name="${base_module_name%\$py.class}" |
| … | |
… | |
| 2774 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2779 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2775 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2780 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2776 | else |
2781 | else |
| 2777 | [[ -f "${py_file}" ]] && continue |
2782 | [[ -f "${py_file}" ]] && continue |
| 2778 | fi |
2783 | fi |
| 2779 | echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" |
2784 | _python_vecho "<<< ${compiled_file}" |
| 2780 | rm -f "${compiled_file}" |
2785 | rm -f "${compiled_file}" |
| 2781 | else |
2786 | else |
| 2782 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
2787 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
| 2783 | fi |
2788 | fi |
| 2784 | |
2789 | |
| 2785 | # Delete empty parent directories. |
2790 | # Delete empty parent directories. |
| 2786 | dir="${compiled_file%/*}" |
2791 | dir="${compiled_file%/*}" |
| 2787 | while [[ "${dir}" != "${root}" ]]; do |
2792 | while [[ "${dir}" != "${root}" ]]; do |
| 2788 | if rmdir "${dir}" 2> /dev/null; then |
2793 | if rmdir "${dir}" 2> /dev/null; then |
| 2789 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2794 | _python_vecho "<<< ${dir}" |
| 2790 | else |
2795 | else |
| 2791 | break |
2796 | break |
| 2792 | fi |
2797 | fi |
| 2793 | dir="${dir%/*}" |
2798 | dir="${dir%/*}" |
| 2794 | done |
2799 | done |