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

Diff of /eclass/python.eclass

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

Revision 1.151 Revision 1.164
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.151 2012/02/27 03:57:35 floppym Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.164 2012/12/20 06:34:57 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
1019 python_default_function() { 1016 python_default_function() {
1020 emake "$@" 1017 emake "$@"
1021 } 1018 }
1022 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 1019 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
1023 python_default_function() { 1020 python_default_function() {
1021 # Stolen from portage's _eapi0_src_test()
1022 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
1024 if emake -j1 -n check &> /dev/null; then 1023 if ${emake_cmd} -j1 -n check &> /dev/null; then
1025 emake -j1 check "$@" 1024 ${emake_cmd} -j1 check "$@"
1026 elif emake -j1 -n test &> /dev/null; then 1025 elif ${emake_cmd} -j1 -n test &> /dev/null; then
1027 emake -j1 test "$@" 1026 ${emake_cmd} -j1 test "$@"
1028 fi 1027 fi
1029 } 1028 }
1030 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 1029 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
1031 python_default_function() { 1030 python_default_function() {
1032 emake DESTDIR="${D}" install "$@" 1031 emake DESTDIR="${D}" install "$@"
1299pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$") 1298pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
1300cpython_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)")
1301python_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)")
1302python_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$")
1303 1302
1304pypy_versions_mapping = { 1303#pypy_versions_mapping = {
1305 "1.5": "2.7" 1304# "1.5": "2.7",
1306} 1305# "1.6": "2.7",
1306# "1.7": "2.7",
1307# "1.8": "2.7",
1308# "1.9": "2.7",
1309# "2.0": "2.7",
1310#}
1307 1311
1308def get_PYTHON_ABI(python_interpreter): 1312def get_PYTHON_ABI(python_interpreter):
1309 cpython_matched = cpython_interpreter_re.match(python_interpreter) 1313 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1310 jython_matched = jython_interpreter_re.match(python_interpreter) 1314 jython_matched = jython_interpreter_re.match(python_interpreter)
1311 pypy_matched = pypy_interpreter_re.match(python_interpreter) 1315 pypy_matched = pypy_interpreter_re.match(python_interpreter)
1312 if cpython_matched is not None: 1316 if cpython_matched is not None:
1313 PYTHON_ABI = cpython_matched.group(1) 1317 PYTHON_ABI = cpython_matched.group(1)
1314 elif jython_matched is not None: 1318 elif jython_matched is not None:
1315 PYTHON_ABI = jython_matched.group(1) + "-jython" 1319 PYTHON_ABI = jython_matched.group(1) + "-jython"
1316 elif pypy_matched is not None: 1320 elif pypy_matched is not None:
1317 PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1) 1321 #PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
1322 PYTHON_ABI = "2.7-pypy-" + pypy_matched.group(1)
1318 else: 1323 else:
1319 PYTHON_ABI = None 1324 PYTHON_ABI = None
1320 return PYTHON_ABI 1325 return PYTHON_ABI
1321 1326
1322def get_python_interpreter(PYTHON_ABI): 1327def get_python_interpreter(PYTHON_ABI):
2702 fi 2707 fi
2703 2708
2704 export PYTHONDONTWRITEBYTECODE="1" 2709 export PYTHONDONTWRITEBYTECODE="1"
2705} 2710}
2706 2711
2712_python_vecho() {
2713 [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
2714}
2715
2707_python_clean_compiled_modules() { 2716_python_clean_compiled_modules() {
2708 _python_initialize_prefix_variables 2717 _python_initialize_prefix_variables
2709 _python_set_color_variables 2718 _python_set_color_variables
2710 2719
2711 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2720 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2724 2733
2725 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2734 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2726 # Delete empty child directories. 2735 # Delete empty child directories.
2727 find "${path}" -type d | sort -r | while read -r dir; do 2736 find "${path}" -type d | sort -r | while read -r dir; do
2728 if rmdir "${dir}" 2> /dev/null; then 2737 if rmdir "${dir}" 2> /dev/null; then
2729 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2738 _python_vecho "<<< ${dir}"
2730 fi 2739 fi
2731 done 2740 done
2732 fi 2741 fi
2733 elif [[ "${path}" == *.py ]]; then 2742 elif [[ "${path}" == *.py ]]; then
2734 base_module_name="${path##*/}" 2743 base_module_name="${path##*/}"
2757 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2766 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2758 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2767 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2759 else 2768 else
2760 [[ -f "${py_file}" ]] && continue 2769 [[ -f "${py_file}" ]] && continue
2761 fi 2770 fi
2762 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" 2771 _python_vecho "<<< ${compiled_file%[co]}[co]"
2763 rm -f "${compiled_file%[co]}"[co] 2772 rm -f "${compiled_file%[co]}"[co]
2764 elif [[ "${compiled_file}" == *\$py.class ]]; then 2773 elif [[ "${compiled_file}" == *\$py.class ]]; then
2765 if [[ "${dir}" == "__pycache__" ]]; then 2774 if [[ "${dir}" == "__pycache__" ]]; then
2766 base_module_name="${compiled_file##*/}" 2775 base_module_name="${compiled_file##*/}"
2767 base_module_name="${base_module_name%\$py.class}" 2776 base_module_name="${base_module_name%\$py.class}"
2772 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2781 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2773 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2782 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2774 else 2783 else
2775 [[ -f "${py_file}" ]] && continue 2784 [[ -f "${py_file}" ]] && continue
2776 fi 2785 fi
2777 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" 2786 _python_vecho "<<< ${compiled_file}"
2778 rm -f "${compiled_file}" 2787 rm -f "${compiled_file}"
2779 else 2788 else
2780 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" 2789 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2781 fi 2790 fi
2782 2791
2783 # Delete empty parent directories. 2792 # Delete empty parent directories.
2784 dir="${compiled_file%/*}" 2793 dir="${compiled_file%/*}"
2785 while [[ "${dir}" != "${root}" ]]; do 2794 while [[ "${dir}" != "${root}" ]]; do
2786 if rmdir "${dir}" 2> /dev/null; then 2795 if rmdir "${dir}" 2> /dev/null; then
2787 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2796 _python_vecho "<<< ${dir}"
2788 else 2797 else
2789 break 2798 break
2790 fi 2799 fi
2791 dir="${dir%/*}" 2800 dir="${dir%/*}"
2792 done 2801 done

Legend:
Removed from v.1.151  
changed lines
  Added in v.1.164

  ViewVC Help
Powered by ViewVC 1.1.20