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

Diff of /eclass/python.eclass

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

Revision 1.135 Revision 1.139
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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.135 2011/10/07 10:52:31 djc Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.139 2011/10/15 20:58:08 phajdan.jr 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
12inherit multilib 12inherit multilib
13 13
14if ! has "${EAPI:-0}" 0 1 2 3; then 14if ! has "${EAPI:-0}" 0 1 2 3 4; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) 19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2)
1621 stdout = sys.stdout.buffer 1621 stdout = sys.stdout.buffer
1622else: 1622else:
1623 # Python 2 1623 # Python 2
1624 stdout = sys.stdout 1624 stdout = sys.stdout
1625 1625
1626python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
1626files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00')) 1627files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
1628python_wrapper_scripts_file.close()
1627 1629
1628for file in sorted(files): 1630for file in sorted(files):
1629 stdout.write(file) 1631 stdout.write(file)
1630 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts") 1632 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1631 1633
2406_python_test_hook() { 2408_python_test_hook() {
2407 if [[ "$#" -ne 1 ]]; then 2409 if [[ "$#" -ne 1 ]]; then
2408 die "${FUNCNAME}() requires 1 argument" 2410 die "${FUNCNAME}() requires 1 argument"
2409 fi 2411 fi
2410 2412
2411 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then 2413 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
2412 "${FUNCNAME[3]}_$1_hook" 2414 "${_PYTHON_TEST_FUNCTION}_$1_hook"
2413 fi 2415 fi
2414} 2416}
2415 2417
2416# @FUNCTION: python_execute_nosetests 2418# @FUNCTION: python_execute_nosetests
2417# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 2419# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
2451 python_test_function() { 2453 python_test_function() {
2452 local evaluated_PYTHONPATH 2454 local evaluated_PYTHONPATH
2453 2455
2454 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2456 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2455 2457
2456 _python_test_hook pre 2458 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre
2457 2459
2458 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2460 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2459 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2461 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2460 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2462 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2461 else 2463 else
2462 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2464 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2463 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2465 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2464 fi 2466 fi
2465 2467
2466 _python_test_hook post 2468 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
2467 } 2469 }
2468 if _python_package_supporting_installation_for_multiple_python_abis; then 2470 if _python_package_supporting_installation_for_multiple_python_abis; then
2469 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2471 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2470 else 2472 else
2471 if [[ -n "${separate_build_dirs}" ]]; then 2473 if [[ -n "${separate_build_dirs}" ]]; then
2515 python_test_function() { 2517 python_test_function() {
2516 local evaluated_PYTHONPATH 2518 local evaluated_PYTHONPATH
2517 2519
2518 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2520 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2519 2521
2520 _python_test_hook pre 2522 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre
2521 2523
2522 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2524 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2523 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 2525 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
2524 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?" 2526 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
2525 else 2527 else
2526 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} 2528 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
2527 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" 2529 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
2528 fi 2530 fi
2529 2531
2530 _python_test_hook post 2532 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
2531 } 2533 }
2532 if _python_package_supporting_installation_for_multiple_python_abis; then 2534 if _python_package_supporting_installation_for_multiple_python_abis; then
2533 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2535 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2534 else 2536 else
2535 if [[ -n "${separate_build_dirs}" ]]; then 2537 if [[ -n "${separate_build_dirs}" ]]; then
2579 python_test_function() { 2581 python_test_function() {
2580 local evaluated_PYTHONPATH 2582 local evaluated_PYTHONPATH
2581 2583
2582 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2584 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2583 2585
2584 _python_test_hook pre 2586 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre
2585 2587
2586 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2588 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2587 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2589 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2588 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 2590 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2589 else 2591 else
2590 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2592 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2591 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 2593 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2592 fi 2594 fi
2593 2595
2594 _python_test_hook post 2596 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
2595 } 2597 }
2596 if _python_package_supporting_installation_for_multiple_python_abis; then 2598 if _python_package_supporting_installation_for_multiple_python_abis; then
2597 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2599 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2598 else 2600 else
2599 if [[ -n "${separate_build_dirs}" ]]; then 2601 if [[ -n "${separate_build_dirs}" ]]; then
2858 done 2860 done
2859 for dir in "${evaluated_dirs[@]}"; do 2861 for dir in "${evaluated_dirs[@]}"; do
2860 eval "dirs+=(\"\${root}${dir}\")" 2862 eval "dirs+=(\"\${root}${dir}\")"
2861 done 2863 done
2862 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1" 2864 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1"
2863 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2865 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2864 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" 2866 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2865 fi 2867 fi
2866 _python_clean_compiled_modules "${dirs[@]}" 2868 _python_clean_compiled_modules "${dirs[@]}"
2867 fi 2869 fi
2868 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then 2870 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2871 done 2873 done
2872 for file in "${evaluated_files[@]}"; do 2874 for file in "${evaluated_files[@]}"; do
2873 eval "files+=(\"\${root}${file}\")" 2875 eval "files+=(\"\${root}${file}\")"
2874 done 2876 done
2875 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1" 2877 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1"
2876 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2878 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2877 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" 2879 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1"
2878 fi 2880 fi
2879 _python_clean_compiled_modules "${files[@]}" 2881 _python_clean_compiled_modules "${files[@]}"
2880 fi 2882 fi
2881 eend "${return_code}" 2883 eend "${return_code}"
2902 return_code="0" 2904 return_code="0"
2903 stderr="" 2905 stderr=""
2904 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)" 2906 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)"
2905 if ((${#other_dirs[@]})); then 2907 if ((${#other_dirs[@]})); then
2906 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1" 2908 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1"
2907 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2909 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2908 "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2910 "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2909 fi 2911 fi
2910 _python_clean_compiled_modules "${other_dirs[@]}" 2912 _python_clean_compiled_modules "${other_dirs[@]}"
2911 fi 2913 fi
2912 if ((${#other_files[@]})); then 2914 if ((${#other_files[@]})); then
2913 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1" 2915 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1"
2914 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2916 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2915 "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1" 2917 "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1"
2916 fi 2918 fi
2917 _python_clean_compiled_modules "${other_files[@]}" 2919 _python_clean_compiled_modules "${other_files[@]}"
2918 fi 2920 fi
2919 eend "${return_code}" 2921 eend "${return_code}"

Legend:
Removed from v.1.135  
changed lines
  Added in v.1.139

  ViewVC Help
Powered by ViewVC 1.1.20