| 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.152 2012/03/07 04:13:27 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 |
| … | |
… | |
| 28 | fi |
28 | fi |
| 29 | |
29 | |
| 30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| 32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) |
| 34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 35 | |
35 | |
| 36 | # ================================================================================================ |
36 | # ================================================================================================ |
| 37 | # ===================================== HANDLING OF METADATA ===================================== |
37 | # ===================================== HANDLING OF METADATA ===================================== |
| 38 | # ================================================================================================ |
38 | # ================================================================================================ |
| … | |
… | |
| 482 | # @DESCRIPTION: |
482 | # @DESCRIPTION: |
| 483 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
483 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| 484 | python_convert_shebangs() { |
484 | python_convert_shebangs() { |
| 485 | _python_check_python_pkg_setup_execution |
485 | _python_check_python_pkg_setup_execution |
| 486 | |
486 | |
| 487 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" |
487 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0" |
| 488 | |
488 | |
| 489 | while (($#)); do |
489 | while (($#)); do |
| 490 | case "$1" in |
490 | case "$1" in |
| 491 | -r|--recursive) |
491 | -r|--recursive) |
| 492 | recursive="1" |
492 | recursive="1" |
| … | |
… | |
| 547 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
547 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 548 | |
548 | |
| 549 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
549 | 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 |
550 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
| 551 | |
551 | |
|
|
552 | shebangs_converted="1" |
|
|
553 | |
| 552 | if [[ "${quiet}" == "0" ]]; then |
554 | if [[ "${quiet}" == "0" ]]; then |
| 553 | einfo "Converting shebang in '${file}'" |
555 | einfo "Converting shebang in '${file}'" |
| 554 | fi |
556 | fi |
| 555 | |
557 | |
| 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" |
558 | 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 |
559 | fi |
| 558 | done |
560 | done |
|
|
561 | |
|
|
562 | if [[ "${shebangs_converted}" == "0" ]]; then |
|
|
563 | ewarn "${FUNCNAME}(): Python scripts not found" |
|
|
564 | fi |
| 559 | } |
565 | } |
| 560 | |
566 | |
| 561 | # @FUNCTION: python_clean_py-compile_files |
567 | # @FUNCTION: python_clean_py-compile_files |
| 562 | # @USAGE: [-q|--quiet] |
568 | # @USAGE: [-q|--quiet] |
| 563 | # @DESCRIPTION: |
569 | # @DESCRIPTION: |
| … | |
… | |
| 836 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
842 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
| 837 | fi |
843 | fi |
| 838 | else |
844 | else |
| 839 | python3_version="" |
845 | python3_version="" |
| 840 | fi |
846 | fi |
|
|
847 | fi |
|
|
848 | |
|
|
849 | if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then |
|
|
850 | eerror "${CATEGORY}/${PF} requires at least one of the following packages:" |
|
|
851 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
852 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
|
|
853 | eerror " dev-lang/python:${PYTHON_ABI}" |
|
|
854 | fi |
|
|
855 | done |
|
|
856 | die "No supported version of CPython installed" |
| 841 | fi |
857 | fi |
| 842 | |
858 | |
| 843 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
859 | 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" |
860 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
| 845 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
861 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
| … | |
… | |
| 1003 | python_default_function() { |
1019 | python_default_function() { |
| 1004 | emake "$@" |
1020 | emake "$@" |
| 1005 | } |
1021 | } |
| 1006 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1022 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| 1007 | python_default_function() { |
1023 | python_default_function() { |
|
|
1024 | # Stolen from portage's _eapi0_src_test() |
|
|
1025 | local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}" |
| 1008 | if emake -j1 -n check &> /dev/null; then |
1026 | if ${emake_cmd} -j1 -n check &> /dev/null; then |
| 1009 | emake -j1 check "$@" |
1027 | ${emake_cmd} -j1 check "$@" |
| 1010 | elif emake -j1 -n test &> /dev/null; then |
1028 | elif ${emake_cmd} -j1 -n test &> /dev/null; then |
| 1011 | emake -j1 test "$@" |
1029 | ${emake_cmd} -j1 test "$@" |
| 1012 | fi |
1030 | fi |
| 1013 | } |
1031 | } |
| 1014 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1032 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
| 1015 | python_default_function() { |
1033 | python_default_function() { |
| 1016 | emake DESTDIR="${D}" install "$@" |
1034 | emake DESTDIR="${D}" install "$@" |