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

Diff of /eclass/python.eclass

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

Revision 1.153 Revision 1.161
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.153 2012/03/20 20:37:21 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
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)
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# ================================================================================================
111 return 1 115 return 1
112 fi 116 fi
113} 117}
114 118
115_python_package_supporting_installation_for_multiple_python_abis() { 119_python_package_supporting_installation_for_multiple_python_abis() {
116 if has "${EAPI:-0}" 0 1 2 3 4; then
117 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 120 [[ -n "${SUPPORT_PYTHON_ABIS}" ]]
118 return 0
119 else
120 return 1
121 fi
122 else
123 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
124 fi
125} 121}
126 122
127# @ECLASS-VARIABLE: PYTHON_DEPEND 123# @ECLASS-VARIABLE: PYTHON_DEPEND
128# @DESCRIPTION: 124# @DESCRIPTION:
129# Specification of dependency on dev-lang/python. 125# Specification of dependency on dev-lang/python.
750 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
751 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
752 fi 748 fi
753fi 749fi
754 750
755if has "${EAPI:-0}" 0 1 2 3 4; then
756 unset PYTHON_ABIS 751unset PYTHON_ABIS
757fi
758 752
759_python_calculate_PYTHON_ABIS() { 753_python_calculate_PYTHON_ABIS() {
760 if ! _python_package_supporting_installation_for_multiple_python_abis; then 754 if ! _python_package_supporting_installation_for_multiple_python_abis; then
761 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"
762 fi 756 fi
763 757
764 _python_initial_sanity_checks 758 _python_initial_sanity_checks
765 759
766 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
767 local PYTHON_ABI 761 local PYTHON_ABI
768 762
769 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
770 local cpython_enabled="0" 764 local cpython_enabled="0"
771 765
1305cpython_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)")
1306python_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)")
1307python_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$")
1308 1302
1309pypy_versions_mapping = { 1303pypy_versions_mapping = {
1310 "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",
1311} 1309}
1312 1310
1313def get_PYTHON_ABI(python_interpreter): 1311def get_PYTHON_ABI(python_interpreter):
1314 cpython_matched = cpython_interpreter_re.match(python_interpreter) 1312 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1315 jython_matched = jython_interpreter_re.match(python_interpreter) 1313 jython_matched = jython_interpreter_re.match(python_interpreter)
2707 fi 2705 fi
2708 2706
2709 export PYTHONDONTWRITEBYTECODE="1" 2707 export PYTHONDONTWRITEBYTECODE="1"
2710} 2708}
2711 2709
2710_python_vecho() {
2711 [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
2712}
2713
2712_python_clean_compiled_modules() { 2714_python_clean_compiled_modules() {
2713 _python_initialize_prefix_variables 2715 _python_initialize_prefix_variables
2714 _python_set_color_variables 2716 _python_set_color_variables
2715 2717
2716 [[ "${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"
2729 2731
2730 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2732 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2731 # Delete empty child directories. 2733 # Delete empty child directories.
2732 find "${path}" -type d | sort -r | while read -r dir; do 2734 find "${path}" -type d | sort -r | while read -r dir; do
2733 if rmdir "${dir}" 2> /dev/null; then 2735 if rmdir "${dir}" 2> /dev/null; then
2734 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2736 _python_vecho "<<< ${dir}"
2735 fi 2737 fi
2736 done 2738 done
2737 fi 2739 fi
2738 elif [[ "${path}" == *.py ]]; then 2740 elif [[ "${path}" == *.py ]]; then
2739 base_module_name="${path##*/}" 2741 base_module_name="${path##*/}"
2762 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2764 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2763 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2765 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2764 else 2766 else
2765 [[ -f "${py_file}" ]] && continue 2767 [[ -f "${py_file}" ]] && continue
2766 fi 2768 fi
2767 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" 2769 _python_vecho "<<< ${compiled_file%[co]}[co]"
2768 rm -f "${compiled_file%[co]}"[co] 2770 rm -f "${compiled_file%[co]}"[co]
2769 elif [[ "${compiled_file}" == *\$py.class ]]; then 2771 elif [[ "${compiled_file}" == *\$py.class ]]; then
2770 if [[ "${dir}" == "__pycache__" ]]; then 2772 if [[ "${dir}" == "__pycache__" ]]; then
2771 base_module_name="${compiled_file##*/}" 2773 base_module_name="${compiled_file##*/}"
2772 base_module_name="${base_module_name%\$py.class}" 2774 base_module_name="${base_module_name%\$py.class}"
2777 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2779 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2778 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2780 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2779 else 2781 else
2780 [[ -f "${py_file}" ]] && continue 2782 [[ -f "${py_file}" ]] && continue
2781 fi 2783 fi
2782 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" 2784 _python_vecho "<<< ${compiled_file}"
2783 rm -f "${compiled_file}" 2785 rm -f "${compiled_file}"
2784 else 2786 else
2785 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" 2787 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2786 fi 2788 fi
2787 2789
2788 # Delete empty parent directories. 2790 # Delete empty parent directories.
2789 dir="${compiled_file%/*}" 2791 dir="${compiled_file%/*}"
2790 while [[ "${dir}" != "${root}" ]]; do 2792 while [[ "${dir}" != "${root}" ]]; do
2791 if rmdir "${dir}" 2> /dev/null; then 2793 if rmdir "${dir}" 2> /dev/null; then
2792 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2794 _python_vecho "<<< ${dir}"
2793 else 2795 else
2794 break 2796 break
2795 fi 2797 fi
2796 dir="${dir%/*}" 2798 dir="${dir%/*}"
2797 done 2799 done

Legend:
Removed from v.1.153  
changed lines
  Added in v.1.161

  ViewVC Help
Powered by ViewVC 1.1.20