| 1 | # Copyright 1999-2011 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.143 2011/12/19 01:29:57 robbat2 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 |
| 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 | |
|
|
12 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
|
|
13 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 12 | inherit multilib |
14 | inherit multilib |
|
|
15 | fi |
|
|
16 | |
|
|
17 | # Export pkg_setup every time to avoid issues with eclass inheritance order. |
|
|
18 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
|
|
19 | EXPORT_FUNCTIONS pkg_setup |
|
|
20 | fi |
|
|
21 | |
|
|
22 | # Avoid processing this eclass more than once. |
|
|
23 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
|
|
24 | _PYTHON_ECLASS_INHERITED="1" |
| 13 | |
25 | |
| 14 | if ! has "${EAPI:-0}" 0 1 2 3 4; then |
26 | if ! has "${EAPI:-0}" 0 1 2 3 4; then |
| 15 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
27 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
| 16 | fi |
28 | fi |
| 17 | |
29 | |
| 18 | _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) |
| 19 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| 20 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 21 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) |
| 22 | _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[@]}) |
| 23 | |
35 | |
| 24 | # ================================================================================================ |
36 | # ================================================================================================ |
| 25 | # ===================================== HANDLING OF METADATA ===================================== |
37 | # ===================================== HANDLING OF METADATA ===================================== |
| 26 | # ================================================================================================ |
38 | # ================================================================================================ |
| … | |
… | |
| 461 | fi |
473 | fi |
| 462 | |
474 | |
| 463 | PYTHON_PKG_SETUP_EXECUTED="1" |
475 | PYTHON_PKG_SETUP_EXECUTED="1" |
| 464 | } |
476 | } |
| 465 | |
477 | |
| 466 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
|
|
| 467 | EXPORT_FUNCTIONS pkg_setup |
|
|
| 468 | fi |
|
|
| 469 | |
|
|
| 470 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)' |
478 | _PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)' |
| 471 | |
479 | |
| 472 | # @FUNCTION: python_convert_shebangs |
480 | # @FUNCTION: python_convert_shebangs |
| 473 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
481 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories] |
| 474 | # @DESCRIPTION: |
482 | # @DESCRIPTION: |
| 475 | # 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. |
| 476 | python_convert_shebangs() { |
484 | python_convert_shebangs() { |
| 477 | _python_check_python_pkg_setup_execution |
485 | _python_check_python_pkg_setup_execution |
| 478 | |
486 | |
| 479 | 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" |
| 480 | |
488 | |
| 481 | while (($#)); do |
489 | while (($#)); do |
| 482 | case "$1" in |
490 | case "$1" in |
| 483 | -r|--recursive) |
491 | -r|--recursive) |
| 484 | recursive="1" |
492 | recursive="1" |
| … | |
… | |
| 539 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
547 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 540 | |
548 | |
| 541 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
549 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
| 542 | [[ "$(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 |
| 543 | |
551 | |
|
|
552 | shebangs_converted="1" |
|
|
553 | |
| 544 | if [[ "${quiet}" == "0" ]]; then |
554 | if [[ "${quiet}" == "0" ]]; then |
| 545 | einfo "Converting shebang in '${file}'" |
555 | einfo "Converting shebang in '${file}'" |
| 546 | fi |
556 | fi |
| 547 | |
557 | |
| 548 | 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" |
| 549 | fi |
559 | fi |
|
|
560 | done |
|
|
561 | |
|
|
562 | if [[ "${shebangs_converted}" == "0" ]]; then |
|
|
563 | ewarn "${FUNCNAME}(): Python scripts not found" |
|
|
564 | fi |
|
|
565 | } |
|
|
566 | |
|
|
567 | # @FUNCTION: python_clean_py-compile_files |
|
|
568 | # @USAGE: [-q|--quiet] |
|
|
569 | # @DESCRIPTION: |
|
|
570 | # Clean py-compile files to disable byte-compilation. |
|
|
571 | python_clean_py-compile_files() { |
|
|
572 | _python_check_python_pkg_setup_execution |
|
|
573 | |
|
|
574 | local file files=() quiet="0" |
|
|
575 | |
|
|
576 | while (($#)); do |
|
|
577 | case "$1" in |
|
|
578 | -q|--quiet) |
|
|
579 | quiet="1" |
|
|
580 | ;; |
|
|
581 | -*) |
|
|
582 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
583 | ;; |
|
|
584 | *) |
|
|
585 | die "${FUNCNAME}(): Invalid usage" |
|
|
586 | ;; |
|
|
587 | esac |
|
|
588 | shift |
|
|
589 | done |
|
|
590 | |
|
|
591 | while read -d $'\0' -r file; do |
|
|
592 | files+=("${file#./}") |
|
|
593 | done < <(find -name py-compile -type f -print0) |
|
|
594 | |
|
|
595 | for file in "${files[@]}"; do |
|
|
596 | if [[ "${quiet}" == "0" ]]; then |
|
|
597 | einfo "Cleaning '${file}' file" |
|
|
598 | fi |
|
|
599 | echo "#!/bin/sh" > "${file}" |
| 550 | done |
600 | done |
| 551 | } |
601 | } |
| 552 | |
602 | |
| 553 | # @FUNCTION: python_clean_installation_image |
603 | # @FUNCTION: python_clean_installation_image |
| 554 | # @USAGE: [-q|--quiet] |
604 | # @USAGE: [-q|--quiet] |
| … | |
… | |
| 792 | 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}" |
| 793 | fi |
843 | fi |
| 794 | else |
844 | else |
| 795 | python3_version="" |
845 | python3_version="" |
| 796 | 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" |
| 797 | fi |
857 | fi |
| 798 | |
858 | |
| 799 | 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 |
| 800 | 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" |
| 801 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
861 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
| … | |
… | |
| 959 | python_default_function() { |
1019 | python_default_function() { |
| 960 | emake "$@" |
1020 | emake "$@" |
| 961 | } |
1021 | } |
| 962 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1022 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| 963 | python_default_function() { |
1023 | python_default_function() { |
|
|
1024 | # Stolen from portage's _eapi0_src_test() |
|
|
1025 | local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}" |
| 964 | if emake -j1 -n check &> /dev/null; then |
1026 | if ${emake_cmd} -j1 -n check &> /dev/null; then |
| 965 | emake -j1 check "$@" |
1027 | ${emake_cmd} -j1 check "$@" |
| 966 | elif emake -j1 -n test &> /dev/null; then |
1028 | elif ${emake_cmd} -j1 -n test &> /dev/null; then |
| 967 | emake -j1 test "$@" |
1029 | ${emake_cmd} -j1 test "$@" |
| 968 | fi |
1030 | fi |
| 969 | } |
1031 | } |
| 970 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1032 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
| 971 | python_default_function() { |
1033 | python_default_function() { |
| 972 | emake DESTDIR="${D}" install "$@" |
1034 | emake DESTDIR="${D}" install "$@" |
| … | |
… | |
| 3112 | } |
3174 | } |
| 3113 | |
3175 | |
| 3114 | # ================================================================================================ |
3176 | # ================================================================================================ |
| 3115 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
3177 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
| 3116 | # ================================================================================================ |
3178 | # ================================================================================================ |
|
|
3179 | |
|
|
3180 | fi # _PYTHON_ECLASS_INHERITED |