/[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.162
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.162 2012/12/20 06:07:05 floppym Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
9# @DESCRIPTION: 9# @DESCRIPTION:
10# The python eclass contains miscellaneous, useful functions for Python packages. 10# The python eclass contains miscellaneous, useful functions for Python packages.
11 11
12if [[ ${_PYTHON_UTILS_R1} ]]; then
13 die 'python.eclass can not be used with python-r1 suite eclasses.'
14fi
15
12# Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. 16# Must call inherit before EXPORT_FUNCTIONS to avoid QA warning.
13if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then 17if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
14 inherit multilib 18 inherit multilib
15fi 19fi
16 20
21 25
22# Avoid processing this eclass more than once. 26# Avoid processing this eclass more than once.
23if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then 27if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
24_PYTHON_ECLASS_INHERITED="1" 28_PYTHON_ECLASS_INHERITED="1"
25 29
26if ! has "${EAPI:-0}" 0 1 2 3 4; then 30if ! 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"
28fi 32fi
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 2.7-pypy-2.0)
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
256if _python_implementation; then
248DEPEND=">=app-admin/eselect-python-20091230" 257 DEPEND=">=app-admin/eselect-python-20091230"
249RDEPEND="${DEPEND}" 258 RDEPEND="${DEPEND}"
259 PDEPEND="app-admin/python-updater"
260fi
250 261
251if [[ -n "${PYTHON_DEPEND}" ]]; then 262if [[ -n "${PYTHON_DEPEND}" ]]; then
252 _python_parse_PYTHON_DEPEND 263 _python_parse_PYTHON_DEPEND
253else 264else
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
301fi 312fi
302 313
303unset _PYTHON_ATOMS 314unset _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
750fi 749fi
751 750
752if has "${EAPI:-0}" 0 1 2 3 4; then
753 unset PYTHON_ABIS 751unset PYTHON_ABIS
754fi
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
842 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" 839 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
843 fi 840 fi
844 else 841 else
845 python3_version="" 842 python3_version=""
846 fi 843 fi
844 fi
845
846 if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then
847 eerror "${CATEGORY}/${PF} requires at least one of the following packages:"
848 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
849 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
850 eerror " dev-lang/python:${PYTHON_ABI}"
851 fi
852 done
853 die "No supported version of CPython installed"
847 fi 854 fi
848 855
849 if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then 856 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" 857 eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink"
851 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 858 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
1009 python_default_function() { 1016 python_default_function() {
1010 emake "$@" 1017 emake "$@"
1011 } 1018 }
1012 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 1019 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
1013 python_default_function() { 1020 python_default_function() {
1021 # Stolen from portage's _eapi0_src_test()
1022 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
1014 if emake -j1 -n check &> /dev/null; then 1023 if ${emake_cmd} -j1 -n check &> /dev/null; then
1015 emake -j1 check "$@" 1024 ${emake_cmd} -j1 check "$@"
1016 elif emake -j1 -n test &> /dev/null; then 1025 elif ${emake_cmd} -j1 -n test &> /dev/null; then
1017 emake -j1 test "$@" 1026 ${emake_cmd} -j1 test "$@"
1018 fi 1027 fi
1019 } 1028 }
1020 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 1029 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
1021 python_default_function() { 1030 python_default_function() {
1022 emake DESTDIR="${D}" install "$@" 1031 emake DESTDIR="${D}" install "$@"
1290cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") 1299cpython_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)") 1300python_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$") 1301python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1293 1302
1294pypy_versions_mapping = { 1303pypy_versions_mapping = {
1295 "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",
1296} 1309}
1297 1310
1298def get_PYTHON_ABI(python_interpreter): 1311def get_PYTHON_ABI(python_interpreter):
1299 cpython_matched = cpython_interpreter_re.match(python_interpreter) 1312 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1300 jython_matched = jython_interpreter_re.match(python_interpreter) 1313 jython_matched = jython_interpreter_re.match(python_interpreter)
2692 fi 2705 fi
2693 2706
2694 export PYTHONDONTWRITEBYTECODE="1" 2707 export PYTHONDONTWRITEBYTECODE="1"
2695} 2708}
2696 2709
2710_python_vecho() {
2711 [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
2712}
2713
2697_python_clean_compiled_modules() { 2714_python_clean_compiled_modules() {
2698 _python_initialize_prefix_variables 2715 _python_initialize_prefix_variables
2699 _python_set_color_variables 2716 _python_set_color_variables
2700 2717
2701 [[ "${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"
2714 2731
2715 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2732 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2716 # Delete empty child directories. 2733 # Delete empty child directories.
2717 find "${path}" -type d | sort -r | while read -r dir; do 2734 find "${path}" -type d | sort -r | while read -r dir; do
2718 if rmdir "${dir}" 2> /dev/null; then 2735 if rmdir "${dir}" 2> /dev/null; then
2719 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2736 _python_vecho "<<< ${dir}"
2720 fi 2737 fi
2721 done 2738 done
2722 fi 2739 fi
2723 elif [[ "${path}" == *.py ]]; then 2740 elif [[ "${path}" == *.py ]]; then
2724 base_module_name="${path##*/}" 2741 base_module_name="${path##*/}"
2747 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2764 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2748 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2765 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2749 else 2766 else
2750 [[ -f "${py_file}" ]] && continue 2767 [[ -f "${py_file}" ]] && continue
2751 fi 2768 fi
2752 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" 2769 _python_vecho "<<< ${compiled_file%[co]}[co]"
2753 rm -f "${compiled_file%[co]}"[co] 2770 rm -f "${compiled_file%[co]}"[co]
2754 elif [[ "${compiled_file}" == *\$py.class ]]; then 2771 elif [[ "${compiled_file}" == *\$py.class ]]; then
2755 if [[ "${dir}" == "__pycache__" ]]; then 2772 if [[ "${dir}" == "__pycache__" ]]; then
2756 base_module_name="${compiled_file##*/}" 2773 base_module_name="${compiled_file##*/}"
2757 base_module_name="${base_module_name%\$py.class}" 2774 base_module_name="${base_module_name%\$py.class}"
2762 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2779 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2763 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2780 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2764 else 2781 else
2765 [[ -f "${py_file}" ]] && continue 2782 [[ -f "${py_file}" ]] && continue
2766 fi 2783 fi
2767 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" 2784 _python_vecho "<<< ${compiled_file}"
2768 rm -f "${compiled_file}" 2785 rm -f "${compiled_file}"
2769 else 2786 else
2770 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" 2787 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2771 fi 2788 fi
2772 2789
2773 # Delete empty parent directories. 2790 # Delete empty parent directories.
2774 dir="${compiled_file%/*}" 2791 dir="${compiled_file%/*}"
2775 while [[ "${dir}" != "${root}" ]]; do 2792 while [[ "${dir}" != "${root}" ]]; do
2776 if rmdir "${dir}" 2> /dev/null; then 2793 if rmdir "${dir}" 2> /dev/null; then
2777 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2794 _python_vecho "<<< ${dir}"
2778 else 2795 else
2779 break 2796 break
2780 fi 2797 fi
2781 dir="${dir%/*}" 2798 dir="${dir%/*}"
2782 done 2799 done

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

  ViewVC Help
Powered by ViewVC 1.1.20