summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-10-02 02:02:24 +0000
committerArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-10-02 02:02:24 +0000
commit1e3f2f6b9c5c7eaae4431d8236ad234985cb36dd (patch)
tree8f254642d2cc48df685fc2e7b120b1ce4400bc13 /eclass/python.eclass
parentVersion bump. Set SUPPORT_PYTHON_ABIS. (diff)
downloadgentoo-2-1e3f2f6b9c5c7eaae4431d8236ad234985cb36dd.tar.gz
gentoo-2-1e3f2f6b9c5c7eaae4431d8236ad234985cb36dd.tar.bz2
gentoo-2-1e3f2f6b9c5c7eaae4431d8236ad234985cb36dd.zip
Automatically enable Python 2 and Python 3 if no version has been explicitly enabled. Improve python_pkg_setup().
Diffstat (limited to 'eclass/python.eclass')
-rw-r--r--eclass/python.eclass149
1 files changed, 104 insertions, 45 deletions
diff --git a/eclass/python.eclass b/eclass/python.eclass
index 8709331e790a..0c3b891ba80c 100644
--- a/eclass/python.eclass
+++ b/eclass/python.eclass
@@ -1,11 +1,11 @@
# 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.73 2009/09/18 17:50:08 arfrever Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.74 2009/10/02 02:02:24 arfrever Exp $
# @ECLASS: python.eclass
# @MAINTAINER:
# python@gentoo.org
-# @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules.
+# @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.
@@ -19,10 +19,8 @@ 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
+DEPEND+=" >=app-admin/eselect-python-20090804
+ >=app-shells/bash-3.2"
__python_eclass_test() {
__python_version_extract 2.3
@@ -129,7 +127,7 @@ validate_PYTHON_ABIS() {
# USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
- local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
+ local ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
@@ -153,18 +151,70 @@ validate_PYTHON_ABIS() {
export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
- die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}"
+ die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
fi
else
- local restricted_ABI
- python_version
+ local ABI python2_version= python2_supported_versions python3_version= python3_supported_versions restricted_ABI support_python_major_version
- for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
- if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then
- die "Active Python version isn't supported by ${CATEGORY}/${PF}"
+ if has_version "=dev-lang/python-2*"; then
+ if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
+ die "'/usr/bin/python2' isn't valid symlink"
fi
- done
- export PYTHON_ABIS="${PYVER}"
+
+ python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
+ python2_supported_versions="2.4 2.5 2.6 2.7"
+
+ for ABI in ${python2_supported_versions}; do
+ support_python_major_version="1"
+ for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
+ if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
+ support_python_major_version="0"
+ fi
+ done
+ [[ "${support_python_major_version}" == "1" ]] && break
+ done
+ if [[ "${support_python_major_version}" == "1" ]]; then
+ for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
+ if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python2_version}', '${restricted_ABI}'))"; then
+ die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}"
+ fi
+ done
+ else
+ python2_version=""
+ fi
+ fi
+
+ if has_version "=dev-lang/python-3*"; then
+ if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
+ die "'/usr/bin/python3' isn't valid symlink"
+ fi
+
+ python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
+ python3_supported_versions="3.0 3.1 3.2"
+
+ for ABI in ${python3_supported_versions}; do
+ support_python_major_version="1"
+ for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
+ if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
+ support_python_major_version="0"
+ fi
+ done
+ [[ "${support_python_major_version}" == "1" ]] && break
+ done
+ if [[ "${support_python_major_version}" == "1" ]]; then
+ for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
+ if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python3_version}', '${restricted_ABI}'))"; then
+ die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}"
+ fi
+ done
+ else
+ python3_version=""
+ fi
+ fi
+
+ PYTHON_ABIS="${python2_version} ${python3_version}"
+ PYTHON_ABIS="${PYTHON_ABIS# }"
+ export PYTHON_ABIS="${PYTHON_ABIS% }"
fi
fi
@@ -475,55 +525,64 @@ python_execute_function() {
# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
# are respected. Only exported if one of those variables is set.
if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
- python_pkg_setup_fail() {
- eerror "${1}"
- die "${1}"
- }
-
python_pkg_setup() {
- [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
+ python_pkg_setup_fail() {
+ eerror "${1}"
+ die "${1}"
+ }
- python_version
- local failed
- local pyatom="dev-lang/python:${PYVER}"
+ [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
- for use in ${PYTHON_USE_WITH}; do
- if ! has_version "${pyatom}[${use}]"; then
- python_pkg_setup_fail \
- "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}"
+ python_pkg_setup_check_USE_flags() {
+ local pyatom use
+ if [[ -n "${PYTHON_ABI}" ]]; then
+ pyatom="dev-lang/python:${PYTHON_ABI}"
+ else
+ python_version
+ pyatom="dev-lang/python:${PYVER}"
fi
- done
- for use in ${PYTHON_USE_WITH_OR}; do
- if has_version "${pyatom}[${use}]"; then
- return
+ for use in ${PYTHON_USE_WITH}; do
+ if ! has_version "${pyatom}[${use}]"; then
+ python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
+ fi
+ done
+
+ for use in ${PYTHON_USE_WITH_OR}; do
+ if has_version "${pyatom}[${use}]"; then
+ return
+ fi
+ done
+
+ if [[ ${PYTHON_USE_WITH_OR} ]]; then
+ python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
fi
- done
+ }
- if [[ ${PYTHON_USE_WITH_OR} ]]; then
- python_pkg_setup_fail \
- "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}"
+ if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+ python_execute_function -q python_pkg_setup_check_USE_flags
+ else
+ python_pkg_setup_check_USE_flags
fi
}
EXPORT_FUNCTIONS pkg_setup
- if [[ ${PYTHON_USE_WITH} ]]; then
+ if [[ -n "${PYTHON_USE_WITH}" ]]; then
PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
- elif [[ ${PYTHON_USE_WITH_OR} ]]; then
+ elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
PYTHON_USE_WITH_ATOM="|| ( "
for use in ${PYTHON_USE_WITH_OR}; do
- PYTHON_USE_WITH_ATOM="
- ${PYTHON_USE_WITH_ATOM}
- ${PYTHON_ATOM}[${use}]"
+ PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
done
- PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )"
+ unset use
+ PYTHON_USE_WITH_ATOM+=" )"
fi
- if [[ ${PYTHON_USE_WITH_OPT} ]]; then
+ if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
fi
- DEPEND="${PYTHON_USE_WITH_ATOM}"
- RDEPEND="${PYTHON_USE_WITH_ATOM}"
+ DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
+ RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
fi
# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS