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

Diff of /eclass/python.eclass

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

Revision 1.72 Revision 1.76
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.72 2009/09/11 19:55:05 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.76 2009/10/02 23:09:08 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#
9# original author: Alastair Tse <liquidx@gentoo.org>
10# @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.
11# @DESCRIPTION: 9# @DESCRIPTION:
12# Some useful functions for dealing with Python. 10# Some useful functions for dealing with Python.
13 11
14inherit multilib 12inherit multilib
15 13
19 RDEPEND="${DEPEND}" 17 RDEPEND="${DEPEND}"
20else 18else
21 PYTHON_ATOM="dev-lang/python" 19 PYTHON_ATOM="dev-lang/python"
22fi 20fi
23 21
24DEPEND="${DEPEND} >=app-shells/bash-3.2"
25if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
26 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" 22DEPEND+=" >=app-admin/eselect-python-20090804
27fi 23 >=app-shells/bash-3.2"
28 24
29__python_eclass_test() { 25__python_eclass_test() {
30 __python_version_extract 2.3 26 __python_version_extract 2.3
31 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 27 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
32 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 28 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
112 fi 108 fi
113} 109}
114 110
115# @FUNCTION: validate_PYTHON_ABIS 111# @FUNCTION: validate_PYTHON_ABIS
116# @DESCRIPTION: 112# @DESCRIPTION:
117# Make sure PYTHON_ABIS variable has valid value. 113# Ensure that PYTHON_ABIS variable has valid value.
118validate_PYTHON_ABIS() { 114validate_PYTHON_ABIS() {
119 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. 115 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable.
120 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 116 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
121 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" 117 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
122 fi 118 fi
129 die "'/usr/bin/python-config' isn't valid script" 125 die "'/usr/bin/python-config' isn't valid script"
130 fi 126 fi
131 127
132 # 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.
133 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
134 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 130 local ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
135 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"
132 python2_supported_versions="2.4 2.5 2.6 2.7"
133 python3_supported_versions="3.0 3.1 3.2"
136 134
137 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 135 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
136 local python2_enabled="0" python3_enabled="0"
137
138 if [[ -z "${USE_PYTHON}" ]]; then 138 if [[ -z "${USE_PYTHON}" ]]; then
139 die "USE_PYTHON variable is empty" 139 die "USE_PYTHON variable is empty"
140 fi 140 fi
141 141
142 for ABI in ${USE_PYTHON}; do 142 for ABI in ${USE_PYTHON}; do
143 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 143 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
144 die "USE_PYTHON variable contains invalid value '${ABI}'" 144 die "USE_PYTHON variable contains invalid value '${ABI}'"
145 fi 145 fi
146
147 if has "${ABI}" ${python2_supported_versions}; then
148 python2_enabled="1"
149 fi
150 if has "${ABI}" ${python3_supported_versions}; then
151 python3_enabled="1"
152 fi
153
146 support_ABI="1" 154 support_ABI="1"
147 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 155 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
148 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 156 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
149 support_ABI="0" 157 support_ABI="0"
150 break 158 break
153 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 161 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
154 done 162 done
155 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 163 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
156 164
157 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 165 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
158 die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}" 166 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
167 fi
168
169 if [[ "${python2_enabled}" == "0" ]]; then
170 ewarn "USE_PYTHON variable doesn't enable any version of Python 2. This configuration is unsupported."
171 fi
172 if [[ "${python3_enabled}" == "0" ]]; then
173 ewarn "USE_PYTHON variable doesn't enable any version of Python 3. This configuration is unsupported."
159 fi 174 fi
160 else 175 else
161 local restricted_ABI 176 local python_version python2_version= python3_version= support_python_major_version
162 python_version
163 177
178 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
179
180 if has_version "=dev-lang/python-2*"; then
181 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
182 die "'/usr/bin/python2' isn't valid symlink"
183 fi
184
185 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
186
187 for ABI in ${python2_supported_versions}; do
188 support_python_major_version="1"
164 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 189 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
165 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then 190 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
166 die "Active Python version isn't supported by ${CATEGORY}/${PF}" 191 support_python_major_version="0"
167 fi 192 fi
193 done
194 [[ "${support_python_major_version}" == "1" ]] && break
168 done 195 done
196 if [[ "${support_python_major_version}" == "1" ]]; then
197 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
198 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python2_version}', '${restricted_ABI}'))"; then
199 die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}"
200 fi
201 done
202 else
203 python2_version=""
204 fi
205 fi
206
207 if has_version "=dev-lang/python-3*"; then
208 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
209 die "'/usr/bin/python3' isn't valid symlink"
210 fi
211
212 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
213
214 for ABI in ${python3_supported_versions}; do
215 support_python_major_version="1"
216 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
217 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
218 support_python_major_version="0"
219 fi
220 done
221 [[ "${support_python_major_version}" == "1" ]] && break
222 done
223 if [[ "${support_python_major_version}" == "1" ]]; then
224 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
225 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${python3_version}', '${restricted_ABI}'))"; then
226 die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}"
227 fi
228 done
229 else
230 python3_version=""
231 fi
232 fi
233
234 if ! has "${python_version}" "${python2_version}" "${python3_version}"; then
235 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 or /usr/bin/python3 symlink"
236 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
237 die "Incorrect configuration of Python"
238 fi
239
240 PYTHON_ABIS="${python2_version} ${python3_version}"
241 PYTHON_ABIS="${PYTHON_ABIS# }"
169 export PYTHON_ABIS="${PYVER}" 242 export PYTHON_ABIS="${PYTHON_ABIS% }"
170 fi 243 fi
171 fi 244 fi
172 245
173 local PYTHON_ABI 246 local PYTHON_ABI
174 for PYTHON_ABI in ${PYTHON_ABIS}; do 247 for PYTHON_ABI in ${PYTHON_ABIS}; do
249# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments] 322# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments]
250# @DESCRIPTION: 323# @DESCRIPTION:
251# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 324# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
252# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 325# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
253python_execute_function() { 326python_execute_function() {
254 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" 327 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0"
255 328
256 while (($#)); do 329 while (($#)); do
257 case "$1" in 330 case "$1" in
258 --action-message) 331 --action-message)
259 action_message_template="$2" 332 action_message_template="$2"
381 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 454 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
382 else 455 else
383 export BUILDDIR="${S}" 456 export BUILDDIR="${S}"
384 fi 457 fi
385 458
386 previous_directory_stack_length="${#DIRSTACK[@]}" 459 previous_directory="$(pwd)"
460 previous_directory_stack="$(dirs -p)"
461 previous_directory_stack_length="$(dirs -p | wc -l)"
387 462
388 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 463 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
389 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 464 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
390 else 465 else
391 EPYTHON="$(PYTHON)" "${function}" "$@" 466 EPYTHON="$(PYTHON)" "${function}" "$@"
419 else 494 else
420 die "${failure_message}" 495 die "${failure_message}"
421 fi 496 fi
422 fi 497 fi
423 498
499 # Ensure that directory stack hasn't been decreased.
424 if [[ "${#DIRSTACK[@]}" -lt "${previous_directory_stack_length}" ]]; then 500 if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
425 die "Directory stack decreased illegally" 501 die "Directory stack decreased illegally"
426 fi 502 fi
427 503
504 # Avoid side effects of earlier returning from the specified function.
428 while [[ "${#DIRSTACK[@]}" -gt "${previous_directory_stack_length}" ]]; do 505 while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
429 popd > /dev/null || die "popd failed" 506 popd > /dev/null || die "popd failed"
430 done 507 done
508
509 # Ensure that the bottom part of directory stack hasn't been changed. Restore
510 # previous directory (from before running of the specified function) before
511 # comparison of directory stacks to avoid mismatch of directory stacks after
512 # potential using of 'cd' to change current directory. Restoration of previous
513 # directory allows to safely use 'cd' to change current directory in the
514 # specified function without changing it back to original directory.
515 cd "${previous_directory}"
516 if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
517 die "Directory stack changed illegally"
518 fi
431 519
432 if [[ "${separate_build_dirs}" == "1" ]]; then 520 if [[ "${separate_build_dirs}" == "1" ]]; then
433 popd > /dev/null || die "popd failed" 521 popd > /dev/null || die "popd failed"
434 fi 522 fi
435 unset BUILDDIR 523 unset BUILDDIR
460# @FUNCTION: python_pkg_setup 548# @FUNCTION: python_pkg_setup
461# @DESCRIPTION: 549# @DESCRIPTION:
462# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 550# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
463# are respected. Only exported if one of those variables is set. 551# are respected. Only exported if one of those variables is set.
464if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 552if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
553 python_pkg_setup() {
465 python_pkg_setup_fail() { 554 python_pkg_setup_fail() {
466 eerror "${1}" 555 eerror "${1}"
467 die "${1}" 556 die "${1}"
557 }
558
559 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
560
561 python_pkg_setup_check_USE_flags() {
562 local pyatom use
563 if [[ -n "${PYTHON_ABI}" ]]; then
564 pyatom="dev-lang/python:${PYTHON_ABI}"
565 else
566 python_version
567 pyatom="dev-lang/python:${PYVER}"
568 fi
569
570 # Workaround for older versions of Portage.
571 # has_version() calls portageq which is implemented in Python.
572 if has_version "=dev-lang/python-2*"; then
573 local EPYTHON
574 export EPYTHON="$(readlink /usr/bin/python2)"
575 fi
576
577 for use in ${PYTHON_USE_WITH}; do
578 if ! has_version "${pyatom}[${use}]"; then
579 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
580 fi
581 done
582
583 for use in ${PYTHON_USE_WITH_OR}; do
584 if has_version "${pyatom}[${use}]"; then
585 return
586 fi
587 done
588
589 if [[ ${PYTHON_USE_WITH_OR} ]]; then
590 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
591 fi
592 }
593
594 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
595 python_execute_function -q python_pkg_setup_check_USE_flags
596 else
597 python_pkg_setup_check_USE_flags
598 fi
468 } 599 }
469 600
470 python_pkg_setup() {
471 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
472
473 python_version
474 local failed
475 local pyatom="dev-lang/python:${PYVER}"
476
477 for use in ${PYTHON_USE_WITH}; do
478 if ! has_version "${pyatom}[${use}]"; then
479 python_pkg_setup_fail \
480 "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}"
481 fi
482 done
483
484 for use in ${PYTHON_USE_WITH_OR}; do
485 if has_version "${pyatom}[${use}]"; then
486 return
487 fi
488 done
489
490 if [[ ${PYTHON_USE_WITH_OR} ]]; then
491 python_pkg_setup_fail \
492 "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}"
493 fi
494 }
495
496 EXPORT_FUNCTIONS pkg_setup 601 EXPORT_FUNCTIONS pkg_setup
497 602
498 if [[ ${PYTHON_USE_WITH} ]]; then 603 if [[ -n "${PYTHON_USE_WITH}" ]]; then
499 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 604 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
500 elif [[ ${PYTHON_USE_WITH_OR} ]]; then 605 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
501 PYTHON_USE_WITH_ATOM="|| ( " 606 PYTHON_USE_WITH_ATOM="|| ( "
502 for use in ${PYTHON_USE_WITH_OR}; do 607 for use in ${PYTHON_USE_WITH_OR}; do
503 PYTHON_USE_WITH_ATOM=" 608 PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
504 ${PYTHON_USE_WITH_ATOM}
505 ${PYTHON_ATOM}[${use}]"
506 done 609 done
507 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" 610 unset use
611 PYTHON_USE_WITH_ATOM+=" )"
508 fi 612 fi
509 if [[ ${PYTHON_USE_WITH_OPT} ]]; then 613 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
510 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" 614 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
511 fi 615 fi
512 DEPEND="${PYTHON_USE_WITH_ATOM}" 616 DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
513 RDEPEND="${PYTHON_USE_WITH_ATOM}" 617 RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
514fi 618fi
515 619
516# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS 620# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
517# @DESCRIPTION: 621# @DESCRIPTION:
518# Set this to define default functions for the following ebuild phases: 622# Set this to define default functions for the following ebuild phases:

Legend:
Removed from v.1.72  
changed lines
  Added in v.1.76

  ViewVC Help
Powered by ViewVC 1.1.20