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

Diff of /eclass/python.eclass

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

Revision 1.145 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.145 2012/01/21 19:48:20 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) 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
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
482# @DESCRIPTION: 481# @DESCRIPTION:
483# Convert shebangs in specified files. Directories can be specified only with --recursive option. 482# Convert shebangs in specified files. Directories can be specified only with --recursive option.
484python_convert_shebangs() { 483python_convert_shebangs() {
485 _python_check_python_pkg_setup_execution 484 _python_check_python_pkg_setup_execution
486 485
487 local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" 486 local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0"
488 487
489 while (($#)); do 488 while (($#)); do
490 case "$1" in 489 case "$1" in
491 -r|--recursive) 490 -r|--recursive)
492 recursive="1" 491 recursive="1"
547 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 546 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
548 547
549 if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then 548 if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
550 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue 549 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
551 550
551 shebangs_converted="1"
552
552 if [[ "${quiet}" == "0" ]]; then 553 if [[ "${quiet}" == "0" ]]; then
553 einfo "Converting shebang in '${file}'" 554 einfo "Converting shebang in '${file}'"
554 fi 555 fi
555 556
556 sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" 557 sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed"
557 fi 558 fi
558 done 559 done
560
561 if [[ "${shebangs_converted}" == "0" ]]; then
562 ewarn "${FUNCNAME}(): Python scripts not found"
563 fi
559} 564}
560 565
561# @FUNCTION: python_clean_py-compile_files 566# @FUNCTION: python_clean_py-compile_files
562# @USAGE: [-q|--quiet] 567# @USAGE: [-q|--quiet]
563# @DESCRIPTION: 568# @DESCRIPTION:
741 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
742 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
743 fi 748 fi
744fi 749fi
745 750
746if has "${EAPI:-0}" 0 1 2 3 4; then
747 unset PYTHON_ABIS 751unset PYTHON_ABIS
748fi
749 752
750_python_calculate_PYTHON_ABIS() { 753_python_calculate_PYTHON_ABIS() {
751 if ! _python_package_supporting_installation_for_multiple_python_abis; then 754 if ! _python_package_supporting_installation_for_multiple_python_abis; then
752 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"
753 fi 756 fi
754 757
755 _python_initial_sanity_checks 758 _python_initial_sanity_checks
756 759
757 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
758 local PYTHON_ABI 761 local PYTHON_ABI
759 762
760 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
761 local cpython_enabled="0" 764 local cpython_enabled="0"
762 765
836 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}"
837 fi 840 fi
838 else 841 else
839 python3_version="" 842 python3_version=""
840 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"
841 fi 854 fi
842 855
843 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
844 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"
845 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 858 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
1003 python_default_function() { 1016 python_default_function() {
1004 emake "$@" 1017 emake "$@"
1005 } 1018 }
1006 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 1019 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
1007 python_default_function() { 1020 python_default_function() {
1021 # Stolen from portage's _eapi0_src_test()
1022 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
1008 if emake -j1 -n check &> /dev/null; then 1023 if ${emake_cmd} -j1 -n check &> /dev/null; then
1009 emake -j1 check "$@" 1024 ${emake_cmd} -j1 check "$@"
1010 elif emake -j1 -n test &> /dev/null; then 1025 elif ${emake_cmd} -j1 -n test &> /dev/null; then
1011 emake -j1 test "$@" 1026 ${emake_cmd} -j1 test "$@"
1012 fi 1027 fi
1013 } 1028 }
1014 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 1029 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
1015 python_default_function() { 1030 python_default_function() {
1016 emake DESTDIR="${D}" install "$@" 1031 emake DESTDIR="${D}" install "$@"
1284cpython_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)")
1285python_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)")
1286python_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$")
1287 1302
1288pypy_versions_mapping = { 1303pypy_versions_mapping = {
1289 "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",
1290} 1309}
1291 1310
1292def get_PYTHON_ABI(python_interpreter): 1311def get_PYTHON_ABI(python_interpreter):
1293 cpython_matched = cpython_interpreter_re.match(python_interpreter) 1312 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1294 jython_matched = jython_interpreter_re.match(python_interpreter) 1313 jython_matched = jython_interpreter_re.match(python_interpreter)
2686 fi 2705 fi
2687 2706
2688 export PYTHONDONTWRITEBYTECODE="1" 2707 export PYTHONDONTWRITEBYTECODE="1"
2689} 2708}
2690 2709
2710_python_vecho() {
2711 [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
2712}
2713
2691_python_clean_compiled_modules() { 2714_python_clean_compiled_modules() {
2692 _python_initialize_prefix_variables 2715 _python_initialize_prefix_variables
2693 _python_set_color_variables 2716 _python_set_color_variables
2694 2717
2695 [[ "${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"
2708 2731
2709 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2732 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2710 # Delete empty child directories. 2733 # Delete empty child directories.
2711 find "${path}" -type d | sort -r | while read -r dir; do 2734 find "${path}" -type d | sort -r | while read -r dir; do
2712 if rmdir "${dir}" 2> /dev/null; then 2735 if rmdir "${dir}" 2> /dev/null; then
2713 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2736 _python_vecho "<<< ${dir}"
2714 fi 2737 fi
2715 done 2738 done
2716 fi 2739 fi
2717 elif [[ "${path}" == *.py ]]; then 2740 elif [[ "${path}" == *.py ]]; then
2718 base_module_name="${path##*/}" 2741 base_module_name="${path##*/}"
2741 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2764 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2742 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2765 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2743 else 2766 else
2744 [[ -f "${py_file}" ]] && continue 2767 [[ -f "${py_file}" ]] && continue
2745 fi 2768 fi
2746 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" 2769 _python_vecho "<<< ${compiled_file%[co]}[co]"
2747 rm -f "${compiled_file%[co]}"[co] 2770 rm -f "${compiled_file%[co]}"[co]
2748 elif [[ "${compiled_file}" == *\$py.class ]]; then 2771 elif [[ "${compiled_file}" == *\$py.class ]]; then
2749 if [[ "${dir}" == "__pycache__" ]]; then 2772 if [[ "${dir}" == "__pycache__" ]]; then
2750 base_module_name="${compiled_file##*/}" 2773 base_module_name="${compiled_file##*/}"
2751 base_module_name="${base_module_name%\$py.class}" 2774 base_module_name="${base_module_name%\$py.class}"
2756 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then 2779 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2757 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue 2780 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2758 else 2781 else
2759 [[ -f "${py_file}" ]] && continue 2782 [[ -f "${py_file}" ]] && continue
2760 fi 2783 fi
2761 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" 2784 _python_vecho "<<< ${compiled_file}"
2762 rm -f "${compiled_file}" 2785 rm -f "${compiled_file}"
2763 else 2786 else
2764 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" 2787 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2765 fi 2788 fi
2766 2789
2767 # Delete empty parent directories. 2790 # Delete empty parent directories.
2768 dir="${compiled_file%/*}" 2791 dir="${compiled_file%/*}"
2769 while [[ "${dir}" != "${root}" ]]; do 2792 while [[ "${dir}" != "${root}" ]]; do
2770 if rmdir "${dir}" 2> /dev/null; then 2793 if rmdir "${dir}" 2> /dev/null; then
2771 echo "${_CYAN}<<< ${dir}${_NORMAL}" 2794 _python_vecho "<<< ${dir}"
2772 else 2795 else
2773 break 2796 break
2774 fi 2797 fi
2775 dir="${dir%/*}" 2798 dir="${dir%/*}"
2776 done 2799 done

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

  ViewVC Help
Powered by ViewVC 1.1.20