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

Diff of /eclass/python.eclass

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

Revision 1.73 Revision 1.74
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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.73 2009/09/18 17:50:08 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.74 2009/10/02 02:02:24 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# python@gentoo.org 7# python@gentoo.org
8# @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. 8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules.
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Some useful functions for dealing with Python. 10# Some useful functions for dealing with Python.
11 11
12inherit multilib 12inherit multilib
13 13
17 RDEPEND="${DEPEND}" 17 RDEPEND="${DEPEND}"
18else 18else
19 PYTHON_ATOM="dev-lang/python" 19 PYTHON_ATOM="dev-lang/python"
20fi 20fi
21 21
22DEPEND="${DEPEND} >=app-shells/bash-3.2"
23if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
24 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" 22DEPEND+=" >=app-admin/eselect-python-20090804
25fi 23 >=app-shells/bash-3.2"
26 24
27__python_eclass_test() { 25__python_eclass_test() {
28 __python_version_extract 2.3 26 __python_version_extract 2.3
29 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 27 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
30 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 28 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
127 die "'/usr/bin/python-config' isn't valid script" 125 die "'/usr/bin/python-config' isn't valid script"
128 fi 126 fi
129 127
130 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 128 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
131 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then 129 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
132 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 130 local ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
133 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 131 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
134 132
135 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 133 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
136 if [[ -z "${USE_PYTHON}" ]]; then 134 if [[ -z "${USE_PYTHON}" ]]; then
137 die "USE_PYTHON variable is empty" 135 die "USE_PYTHON variable is empty"
151 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 149 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
152 done 150 done
153 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 151 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
154 152
155 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 153 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
156 die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}" 154 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
157 fi 155 fi
158 else 156 else
159 local restricted_ABI 157 local ABI python2_version= python2_supported_versions python3_version= python3_supported_versions restricted_ABI support_python_major_version
160 python_version
161 158
159 if has_version "=dev-lang/python-2*"; then
160 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
161 die "'/usr/bin/python2' isn't valid symlink"
162 fi
163
164 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
165 python2_supported_versions="2.4 2.5 2.6 2.7"
166
167 for ABI in ${python2_supported_versions}; do
168 support_python_major_version="1"
162 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 169 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
163 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then 170 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
164 die "Active Python version isn't supported by ${CATEGORY}/${PF}" 171 support_python_major_version="0"
165 fi 172 fi
173 done
174 [[ "${support_python_major_version}" == "1" ]] && break
166 done 175 done
176 if [[ "${support_python_major_version}" == "1" ]]; then
177 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
178 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python2_version}', '${restricted_ABI}'))"; then
179 die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}"
180 fi
181 done
182 else
183 python2_version=""
184 fi
185 fi
186
187 if has_version "=dev-lang/python-3*"; then
188 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
189 die "'/usr/bin/python3' isn't valid symlink"
190 fi
191
192 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
193 python3_supported_versions="3.0 3.1 3.2"
194
195 for ABI in ${python3_supported_versions}; do
196 support_python_major_version="1"
197 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
198 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
199 support_python_major_version="0"
200 fi
201 done
202 [[ "${support_python_major_version}" == "1" ]] && break
203 done
204 if [[ "${support_python_major_version}" == "1" ]]; then
205 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
206 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python3_version}', '${restricted_ABI}'))"; then
207 die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}"
208 fi
209 done
210 else
211 python3_version=""
212 fi
213 fi
214
215 PYTHON_ABIS="${python2_version} ${python3_version}"
216 PYTHON_ABIS="${PYTHON_ABIS# }"
167 export PYTHON_ABIS="${PYVER}" 217 export PYTHON_ABIS="${PYTHON_ABIS% }"
168 fi 218 fi
169 fi 219 fi
170 220
171 local PYTHON_ABI 221 local PYTHON_ABI
172 for PYTHON_ABI in ${PYTHON_ABIS}; do 222 for PYTHON_ABI in ${PYTHON_ABIS}; do
473# @FUNCTION: python_pkg_setup 523# @FUNCTION: python_pkg_setup
474# @DESCRIPTION: 524# @DESCRIPTION:
475# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 525# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
476# are respected. Only exported if one of those variables is set. 526# are respected. Only exported if one of those variables is set.
477if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 527if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
528 python_pkg_setup() {
478 python_pkg_setup_fail() { 529 python_pkg_setup_fail() {
479 eerror "${1}" 530 eerror "${1}"
480 die "${1}" 531 die "${1}"
532 }
533
534 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
535
536 python_pkg_setup_check_USE_flags() {
537 local pyatom use
538 if [[ -n "${PYTHON_ABI}" ]]; then
539 pyatom="dev-lang/python:${PYTHON_ABI}"
540 else
541 python_version
542 pyatom="dev-lang/python:${PYVER}"
543 fi
544
545 for use in ${PYTHON_USE_WITH}; do
546 if ! has_version "${pyatom}[${use}]"; then
547 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
548 fi
549 done
550
551 for use in ${PYTHON_USE_WITH_OR}; do
552 if has_version "${pyatom}[${use}]"; then
553 return
554 fi
555 done
556
557 if [[ ${PYTHON_USE_WITH_OR} ]]; then
558 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
559 fi
560 }
561
562 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
563 python_execute_function -q python_pkg_setup_check_USE_flags
564 else
565 python_pkg_setup_check_USE_flags
566 fi
481 } 567 }
482 568
483 python_pkg_setup() {
484 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
485
486 python_version
487 local failed
488 local pyatom="dev-lang/python:${PYVER}"
489
490 for use in ${PYTHON_USE_WITH}; do
491 if ! has_version "${pyatom}[${use}]"; then
492 python_pkg_setup_fail \
493 "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}"
494 fi
495 done
496
497 for use in ${PYTHON_USE_WITH_OR}; do
498 if has_version "${pyatom}[${use}]"; then
499 return
500 fi
501 done
502
503 if [[ ${PYTHON_USE_WITH_OR} ]]; then
504 python_pkg_setup_fail \
505 "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}"
506 fi
507 }
508
509 EXPORT_FUNCTIONS pkg_setup 569 EXPORT_FUNCTIONS pkg_setup
510 570
511 if [[ ${PYTHON_USE_WITH} ]]; then 571 if [[ -n "${PYTHON_USE_WITH}" ]]; then
512 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 572 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
513 elif [[ ${PYTHON_USE_WITH_OR} ]]; then 573 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
514 PYTHON_USE_WITH_ATOM="|| ( " 574 PYTHON_USE_WITH_ATOM="|| ( "
515 for use in ${PYTHON_USE_WITH_OR}; do 575 for use in ${PYTHON_USE_WITH_OR}; do
516 PYTHON_USE_WITH_ATOM=" 576 PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
517 ${PYTHON_USE_WITH_ATOM}
518 ${PYTHON_ATOM}[${use}]"
519 done 577 done
520 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" 578 unset use
579 PYTHON_USE_WITH_ATOM+=" )"
521 fi 580 fi
522 if [[ ${PYTHON_USE_WITH_OPT} ]]; then 581 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
523 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" 582 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
524 fi 583 fi
525 DEPEND="${PYTHON_USE_WITH_ATOM}" 584 DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
526 RDEPEND="${PYTHON_USE_WITH_ATOM}" 585 RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
527fi 586fi
528 587
529# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS 588# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
530# @DESCRIPTION: 589# @DESCRIPTION:
531# Set this to define default functions for the following ebuild phases: 590# Set this to define default functions for the following ebuild phases:

Legend:
Removed from v.1.73  
changed lines
  Added in v.1.74

  ViewVC Help
Powered by ViewVC 1.1.20