/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.150 Revision 1.159
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.150 2012/02/13 23:50:12 zmedico Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.159 2012/09/27 22:42:48 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
21 21
22# Avoid processing this eclass more than once. 22# Avoid processing this eclass more than once.
23if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then 23if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
24_PYTHON_ECLASS_INHERITED="1" 24_PYTHON_ECLASS_INHERITED="1"
25 25
26if ! has "${EAPI:-0}" 0 1 2 3 4; then 26if ! has "${EAPI:-0}" 0 1 2 3 4 5; then
27 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 27 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
28fi 28fi
29 29
30_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)
31_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) 31_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2)
32_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) 32_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
33_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) 33_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[@]}) 34_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]})
35 35
36# ================================================================================================ 36# ================================================================================================
37# ===================================== HANDLING OF METADATA ===================================== 37# ===================================== HANDLING OF METADATA =====================================
38# ================================================================================================ 38# ================================================================================================
98 98
99 return 1 99 return 1
100 fi 100 fi
101} 101}
102 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
103_python_package_supporting_installation_for_multiple_python_abis() { 115_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 116 [[ -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} 117}
114 118
115# @ECLASS-VARIABLE: PYTHON_DEPEND 119# @ECLASS-VARIABLE: PYTHON_DEPEND
116# @DESCRIPTION: 120# @DESCRIPTION:
117# Specification of dependency on dev-lang/python. 121# Specification of dependency on dev-lang/python.
243 else 247 else
244 die "Invalid syntax of PYTHON_DEPEND" 248 die "Invalid syntax of PYTHON_DEPEND"
245 fi 249 fi
246} 250}
247 251
252if _python_implementation; then
248DEPEND=">=app-admin/eselect-python-20091230" 253 DEPEND=">=app-admin/eselect-python-20091230"
249RDEPEND="${DEPEND}" 254 RDEPEND="${DEPEND}"
255 PDEPEND="app-admin/python-updater"
256fi
250 257
251if [[ -n "${PYTHON_DEPEND}" ]]; then 258if [[ -n "${PYTHON_DEPEND}" ]]; then
252 _python_parse_PYTHON_DEPEND 259 _python_parse_PYTHON_DEPEND
253else 260else
254 _PYTHON_ATOMS=("dev-lang/python") 261 _PYTHON_ATOMS=("dev-lang/python")
293 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" 300 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
294 fi 301 fi
295 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then 302 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
296 _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} )"
297 fi 304 fi
298 DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" 305 DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
299 RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" 306 RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
300 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
301fi 308fi
302 309
303unset _PYTHON_ATOMS 310unset _PYTHON_ATOMS
304 311
305# ================================================================================================ 312# ================================================================================================
306# =================================== MISCELLANEOUS FUNCTIONS ==================================== 313# =================================== MISCELLANEOUS FUNCTIONS ====================================
307# ================================================================================================ 314# ================================================================================================
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 315
321_python_abi-specific_local_scope() { 316_python_abi-specific_local_scope() {
322 [[ " ${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)" " ]]
323} 318}
324 319
747 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 742 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
748 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
749 fi 744 fi
750fi 745fi
751 746
752if has "${EAPI:-0}" 0 1 2 3 4; then
753 unset PYTHON_ABIS 747unset PYTHON_ABIS
754fi
755 748
756_python_calculate_PYTHON_ABIS() { 749_python_calculate_PYTHON_ABIS() {
757 if ! _python_package_supporting_installation_for_multiple_python_abis; then 750 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" 751 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
759 fi 752 fi
760 753
761 _python_initial_sanity_checks 754 _python_initial_sanity_checks
762 755
763 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 756 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then
764 local PYTHON_ABI 757 local PYTHON_ABI
765 758
766 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 759 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
767 local cpython_enabled="0" 760 local cpython_enabled="0"
768 761
842 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}"
843 fi 836 fi
844 else 837 else
845 python3_version="" 838 python3_version=""
846 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"
847 fi 850 fi
848 851
849 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
850 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"
851 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 854 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
1009 python_default_function() { 1012 python_default_function() {
1010 emake "$@" 1013 emake "$@"
1011 } 1014 }
1012 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 1015 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
1013 python_default_function() { 1016 python_default_function() {
1017 # Stolen from portage's _eapi0_src_test()
1018 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
1014 if emake -j1 -n check &> /dev/null; then 1019 if ${emake_cmd} -j1 -n check &> /dev/null; then
1015 emake -j1 check "$@" 1020 ${emake_cmd} -j1 check "$@"
1016 elif emake -j1 -n test &> /dev/null; then 1021 elif ${emake_cmd} -j1 -n test &> /dev/null; then
1017 emake -j1 test "$@" 1022 ${emake_cmd} -j1 test "$@"
1018 fi 1023 fi
1019 } 1024 }
1020 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 1025 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
1021 python_default_function() { 1026 python_default_function() {
1022 emake DESTDIR="${D}" install "$@" 1027 emake DESTDIR="${D}" install "$@"
1290cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") 1295cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
1291python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") 1296python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
1292python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") 1297python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1293 1298
1294pypy_versions_mapping = { 1299pypy_versions_mapping = {
1295 "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",
1296} 1305}
1297 1306
1298def get_PYTHON_ABI(python_interpreter): 1307def get_PYTHON_ABI(python_interpreter):
1299 cpython_matched = cpython_interpreter_re.match(python_interpreter) 1308 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1300 jython_matched = jython_interpreter_re.match(python_interpreter) 1309 jython_matched = jython_interpreter_re.match(python_interpreter)
2692 fi 2701 fi
2693 2702
2694 export PYTHONDONTWRITEBYTECODE="1" 2703 export PYTHONDONTWRITEBYTECODE="1"
2695} 2704}
2696 2705
2706_python_vecho() {
2707 [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
2708}
2709
2697_python_clean_compiled_modules() { 2710_python_clean_compiled_modules() {
2698 _python_initialize_prefix_variables 2711 _python_initialize_prefix_variables
2699 _python_set_color_variables 2712 _python_set_color_variables
2700 2713
2701 [[ "${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"
2714 2727
2715 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2728 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2716 # Delete empty child directories. 2729 # Delete empty child directories.
2717 find "${path}" -type d | sort -r | while read -r dir; do 2730 find "${path}" -type d | sort -r | while read -r dir; do
2718 if rmdir "${dir}" 2> /dev/null; then 2731 if rmdir "${dir}" 2> /dev/null; then
2719 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2732 _python_vecho "<<< ${dir}"
2720 fi 2733 fi
2721 done 2734 done
2722 fi 2735 fi
2723 elif [[ "${path}" == *.py ]]; then 2736 elif [[ "${path}" == *.py ]]; then
2724 base_module_name="${path##*/}" 2737 base_module_name="${path##*/}"
2747 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2760 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2748 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2761 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2749 else 2762 else
2750 [[ -f "${py_file}" ]] && continue 2763 [[ -f "${py_file}" ]] && continue
2751 fi 2764 fi
2752 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" 2765 _python_vecho "<<< ${compiled_file%[co]}[co]"
2753 rm -f "${compiled_file%[co]}"[co] 2766 rm -f "${compiled_file%[co]}"[co]
2754 elif [[ "${compiled_file}" == *\$py.class ]]; then 2767 elif [[ "${compiled_file}" == *\$py.class ]]; then
2755 if [[ "${dir}" == "__pycache__" ]]; then 2768 if [[ "${dir}" == "__pycache__" ]]; then
2756 base_module_name="${compiled_file##*/}" 2769 base_module_name="${compiled_file##*/}"
2757 base_module_name="${base_module_name%\$py.class}" 2770 base_module_name="${base_module_name%\$py.class}"
2762 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2775 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2763 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2776 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2764 else 2777 else
2765 [[ -f "${py_file}" ]] && continue 2778 [[ -f "${py_file}" ]] && continue
2766 fi 2779 fi
2767 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" 2780 _python_vecho "<<< ${compiled_file}"
2768 rm -f "${compiled_file}" 2781 rm -f "${compiled_file}"
2769 else 2782 else
2770 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" 2783 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2771 fi 2784 fi
2772 2785
2773 # Delete empty parent directories. 2786 # Delete empty parent directories.
2774 dir="${compiled_file%/*}" 2787 dir="${compiled_file%/*}"
2775 while [[ "${dir}" != "${root}" ]]; do 2788 while [[ "${dir}" != "${root}" ]]; do
2776 if rmdir "${dir}" 2> /dev/null; then 2789 if rmdir "${dir}" 2> /dev/null; then
2777 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2790 _python_vecho "<<< ${dir}"
2778 else 2791 else
2779 break 2792 break
2780 fi 2793 fi
2781 dir="${dir%/*}" 2794 dir="${dir%/*}"
2782 done 2795 done

Legend:
Removed from v.1.150  
changed lines
  Added in v.1.159

  ViewVC Help
Powered by ViewVC 1.1.20