diff options
author | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2009-08-28 16:08:51 +0000 |
---|---|---|
committer | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2009-08-28 16:08:51 +0000 |
commit | 95f3e4d2b381c3490ff44e2ed3e10d570c190df5 (patch) | |
tree | 4ed39cf175b7525a866963d2839f34382155a82a /eclass/python.eclass | |
parent | Keyworded on alpha, bug #279851 (diff) | |
download | historical-95f3e4d2b381c3490ff44e2ed3e10d570c190df5.tar.gz historical-95f3e4d2b381c3490ff44e2ed3e10d570c190df5.tar.bz2 historical-95f3e4d2b381c3490ff44e2ed3e10d570c190df5.zip |
Update dependencies. Add more sanity checks. Improve python_execute_function().
Diffstat (limited to 'eclass/python.eclass')
-rw-r--r-- | eclass/python.eclass | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/eclass/python.eclass b/eclass/python.eclass index fb044a836458..940b7cb04e76 100644 --- a/eclass/python.eclass +++ b/eclass/python.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.65 2009/08/15 23:32:58 arfrever Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.66 2009/08/28 16:08:51 arfrever Exp $ # @ECLASS: python.eclass # @MAINTAINER: @@ -9,7 +9,7 @@ # original author: Alastair Tse <liquidx@gentoo.org> # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. # @DESCRIPTION: -# Some useful functions for dealing with python. +# Some useful functions for dealing with Python. inherit multilib @@ -21,6 +21,7 @@ else PYTHON_ATOM="dev-lang/python" fi +DEPEND="${DEPEND} >=app-shells/bash-3.2" if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" fi @@ -112,12 +113,17 @@ PYTHON() { # @DESCRIPTION: # Make sure PYTHON_ABIS variable has valid value. validate_PYTHON_ABIS() { + # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. + if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then + die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" + fi + # Ensure that /usr/bin/python and /usr/bin/python-config are valid. if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then - die "/usr/bin/python isn't valid symlink" + die "'/usr/bin/python' isn't valid symlink" fi if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then - die "/usr/bin/python-config isn't valid script" + die "'/usr/bin/python-config' isn't valid script" fi # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. @@ -130,12 +136,14 @@ validate_PYTHON_ABIS() { continue fi support_ABI="1" - for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do - if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then - support_ABI="0" - break - fi - done + if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then + for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do + if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then + support_ABI="0" + break + fi + done + fi [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" done export PYTHON_ABIS="${supported_PYTHON_ABIS# }" @@ -145,6 +153,14 @@ validate_PYTHON_ABIS() { python_version export PYTHON_ABIS="${PYVER}" fi + + # Ensure that EPYTHON variable is respected. + local PYTHON_ABI + for PYTHON_ABI in ${PYTHON_ABIS}; do + if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then + die "'python' doesn't respect EPYTHON variable" + fi + done } # @FUNCTION: python_copy_sources @@ -178,7 +194,7 @@ python_copy_sources() { python_set_build_dir_symlink() { local dir="$1" - [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" + [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" [[ -z "${dir}" ]] && dir="build" # Don't delete preexistent directories. @@ -309,18 +325,27 @@ python_execute_function() { fi echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" fi + if [[ "${separate_build_dirs}" == "1" ]]; then export BUILDDIR="${S}-${PYTHON_ABI}" pushd "${BUILDDIR}" > /dev/null || die "pushd failed" else export BUILDDIR="${S}" fi - if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then + + if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then + EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" + else + EPYTHON="$(PYTHON)" "${function}" "$@" + fi + + if [[ "$?" != "0" ]]; then if [[ -n "${failure_message_template}" ]]; then failure_message="$(eval echo -n "${failure_message_template}")" else failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" fi + if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then local ABI enabled_PYTHON_ABIS for ABI in ${PYTHON_ABIS}; do @@ -334,6 +359,7 @@ python_execute_function() { die "${failure_message}" fi fi + if [[ "${separate_build_dirs}" == "1" ]]; then popd > /dev/null || die "popd failed" fi @@ -420,24 +446,19 @@ fi # @FUNCTION: python_disable_pyc # @DESCRIPTION: -# Tells python not to automatically recompile modules to .pyc/.pyo +# Tell Python not to automatically recompile modules to .pyc/.pyo # even if the timestamps/version stamps don't match. This is done # to protect sandbox. -# -# note: supported by >=dev-lang/python-2.2.3-r3 only. -# python_disable_pyc() { - export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above - export PYTHON_DONTCOMPILE=1 # For 2.5 and below + export PYTHONDONTWRITEBYTECODE="1" } # @FUNCTION: python_enable_pyc # @DESCRIPTION: -# Tells python to automatically recompile modules to .pyc/.pyo if the -# timestamps/version stamps change +# Tell Python to automatically recompile modules to .pyc/.pyo if the +# timestamps/version stamps have changed. python_enable_pyc() { unset PYTHONDONTWRITEBYTECODE - unset PYTHON_DONTCOMPILE } python_disable_pyc |