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

Diff of /eclass/python.eclass

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

Revision 1.66 Revision 1.71
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.66 2009/08/28 16:08:51 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.71 2009/09/09 04:16:58 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# 8#
66 export PYVER_ALL="${tmpstr#Python }" 66 export PYVER_ALL="${tmpstr#Python }"
67 __python_version_extract $PYVER_ALL 67 __python_version_extract $PYVER_ALL
68} 68}
69 69
70# @FUNCTION: PYTHON 70# @FUNCTION: PYTHON
71# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 71# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}">
72# @DESCRIPTION: 72# @DESCRIPTION:
73# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 73# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
74# is ommitted, then PYTHON_ABI environment variable must be set and is used. 74# is ommitted, then PYTHON_ABI environment variable must be set and is used.
75PYTHON() { 75PYTHON() {
76 local absolute_path="0" slot= 76 local absolute_path="0" slot=
77 77
78 while (($#)); do 78 while (($#)); do
79 case "$1" in 79 case "$1" in
80 -a|--absolute-path) 80 -a|--absolute-path)
81 absolute_path="1" 81 absolute_path="1"
82 ;;
83 --)
84 break
82 ;; 85 ;;
83 -*) 86 -*)
84 die "${FUNCNAME}(): Unrecognized option $1" 87 die "${FUNCNAME}(): Unrecognized option $1"
85 ;; 88 ;;
86 *) 89 *)
125 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 128 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
126 die "'/usr/bin/python-config' isn't valid script" 129 die "'/usr/bin/python-config' isn't valid script"
127 fi 130 fi
128 131
129 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 132 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
130 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then 133 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
131 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 134 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
132 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 135 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
136
137 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
138 if [[ -z "${USE_PYTHON}" ]]; then
139 die "USE_PYTHON variable is empty"
140 fi
141
133 for ABI in ${USE_PYTHON}; do 142 for ABI in ${USE_PYTHON}; do
134 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 143 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
135 ewarn "Ignoring unsupported Python ABI '${ABI}'" 144 die "USE_PYTHON variable contains invalid value '${ABI}'"
136 continue
137 fi 145 fi
138 support_ABI="1" 146 support_ABI="1"
139 if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then
140 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 147 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
141 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 148 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
142 support_ABI="0" 149 support_ABI="0"
143 break 150 break
144 fi 151 fi
145 done 152 done
146 fi
147 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 153 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
148 done 154 done
149 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 155 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
150 fi
151 156
152 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 157 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
158 die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}"
159 fi
160 else
161 local restricted_ABI
153 python_version 162 python_version
163
164 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
165 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then
166 die "Active Python version isn't supported by ${CATEGORY}/${PF}"
167 fi
168 done
154 export PYTHON_ABIS="${PYVER}" 169 export PYTHON_ABIS="${PYVER}"
155 fi 170 fi
171 fi
156 172
157 # Ensure that EPYTHON variable is respected.
158 local PYTHON_ABI 173 local PYTHON_ABI
159 for PYTHON_ABI in ${PYTHON_ABIS}; do 174 for PYTHON_ABI in ${PYTHON_ABIS}; do
175 # Ensure that appropriate Python version is installed.
176 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
177 die "dev-lang/python:${PYTHON_ABI} isn't installed"
178 fi
179
180 # Ensure that EPYTHON variable is respected.
160 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then 181 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
161 die "'python' doesn't respect EPYTHON variable" 182 die "'python' doesn't respect EPYTHON variable"
162 fi 183 fi
163 done 184 done
164} 185}
165 186
166# @FUNCTION: python_copy_sources 187# @FUNCTION: python_copy_sources
167# @USAGE: [directory] 188# @USAGE: [--no-link] [--] [directory]
168# @DESCRIPTION: 189# @DESCRIPTION:
169# Copy unpacked sources of given package for each Python ABI. 190# Copy unpacked sources of given package for each Python ABI.
170python_copy_sources() { 191python_copy_sources() {
171 local dir dirs=() PYTHON_ABI 192 local dir dirs=() no_link="0" PYTHON_ABI
193
194 while (($#)); do
195 case "$1" in
196 --no-link)
197 no_link="1"
198 ;;
199 --)
200 break
201 ;;
202 -*)
203 die "${FUNCNAME}(): Unrecognized option '$1'"
204 ;;
205 *)
206 break
207 ;;
208 esac
209 shift
210 done
172 211
173 if [[ "$#" -eq "0" ]]; then 212 if [[ "$#" -eq "0" ]]; then
174 if [[ "${WORKDIR}" == "${S}" ]]; then 213 if [[ "${WORKDIR}" == "${S}" ]]; then
175 die "${FUNCNAME}() cannot be used" 214 die "${FUNCNAME}() cannot be used"
176 fi 215 fi
180 fi 219 fi
181 220
182 validate_PYTHON_ABIS 221 validate_PYTHON_ABIS
183 for PYTHON_ABI in ${PYTHON_ABIS}; do 222 for PYTHON_ABI in ${PYTHON_ABIS}; do
184 for dir in "${dirs[@]}"; do 223 for dir in "${dirs[@]}"; do
224 if [[ "${no_link}" == "1" ]]; then
225 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
226 else
185 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 227 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
228 fi
186 done 229 done
187 done 230 done
188} 231}
189 232
190# @FUNCTION: python_set_build_dir_symlink 233# @FUNCTION: python_set_build_dir_symlink
201 rm -f "${dir}" || die "Deletion of '${dir}' failed" 244 rm -f "${dir}" || die "Deletion of '${dir}' failed"
202 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 245 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
203} 246}
204 247
205# @FUNCTION: python_execute_function 248# @FUNCTION: python_execute_function
206# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 249# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments]
207# @DESCRIPTION: 250# @DESCRIPTION:
208# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 251# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
209# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 252# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
210python_execute_function() { 253python_execute_function() {
211 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" 254 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0"
230 quiet="1" 273 quiet="1"
231 ;; 274 ;;
232 -s|--separate-build-dirs) 275 -s|--separate-build-dirs)
233 separate_build_dirs="1" 276 separate_build_dirs="1"
234 ;; 277 ;;
278 --)
279 break
280 ;;
235 -*) 281 -*)
236 die "${FUNCNAME}(): Unrecognized option $1" 282 die "${FUNCNAME}(): Unrecognized option '$1'"
237 ;; 283 ;;
238 *) 284 *)
239 break 285 break
240 ;; 286 ;;
241 esac 287 esac
246 if [[ "$#" -eq "0" ]]; then 292 if [[ "$#" -eq "0" ]]; then
247 die "${FUNCNAME}(): Missing function name" 293 die "${FUNCNAME}(): Missing function name"
248 fi 294 fi
249 function="$1" 295 function="$1"
250 shift 296 shift
297
298 if [[ -z "$(type -t "${function}")" ]]; then
299 die "${FUNCNAME}(): '${function}' function isn't defined"
300 fi
251 else 301 else
252 if [[ "$#" -ne "0" ]]; then 302 if [[ "$#" -ne "0" ]]; then
253 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" 303 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
254 fi 304 fi
255 if has "${EAPI:-0}" 0 1; then 305 if has "${EAPI:-0}" 0 1; then
256 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" 306 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
257 fi 307 fi
258 308
259 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 309 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
260 if has "${EAPI}" 2; then 310 if has "${EAPI}" 2; then
261 python_default_function() { 311 python_default_function() {
344 failure_message="$(eval echo -n "${failure_message_template}")" 394 failure_message="$(eval echo -n "${failure_message_template}")"
345 else 395 else
346 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 396 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
347 fi 397 fi
348 398
349 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 399 if [[ "${nonfatal}" == "1" ]]; then
350 local ABI enabled_PYTHON_ABIS
351 for ABI in ${PYTHON_ABIS}; do
352 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
353 done
354 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
355 if [[ "${quiet}" == "0" ]]; then 400 if [[ "${quiet}" == "0" ]]; then
356 ewarn "${RED}${failure_message}${NORMAL}" 401 ewarn "${RED}${failure_message}${NORMAL}"
402 fi
403 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
404 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
405 local ABI enabled_PYTHON_ABIS=
406 for ABI in ${PYTHON_ABIS}; do
407 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
408 done
409 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
410 fi
411 if [[ "${quiet}" == "0" ]]; then
412 ewarn "${RED}${failure_message}${NORMAL}"
413 fi
414 if [[ -z "${PYTHON_ABIS}" ]]; then
415 die "${function}() function failed with all enabled versions of Python"
357 fi 416 fi
358 else 417 else
359 die "${failure_message}" 418 die "${failure_message}"
360 fi 419 fi
361 fi 420 fi
390 449
391# @FUNCTION: python_pkg_setup 450# @FUNCTION: python_pkg_setup
392# @DESCRIPTION: 451# @DESCRIPTION:
393# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 452# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
394# are respected. Only exported if one of those variables is set. 453# are respected. Only exported if one of those variables is set.
395if ! has ${EAPI:-0} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 454if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
396 python_pkg_setup_fail() { 455 python_pkg_setup_fail() {
397 eerror "${1}" 456 eerror "${1}"
398 die "${1}" 457 die "${1}"
399 } 458 }
400 459
440 if [[ ${PYTHON_USE_WITH_OPT} ]]; then 499 if [[ ${PYTHON_USE_WITH_OPT} ]]; then
441 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" 500 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
442 fi 501 fi
443 DEPEND="${PYTHON_USE_WITH_ATOM}" 502 DEPEND="${PYTHON_USE_WITH_ATOM}"
444 RDEPEND="${PYTHON_USE_WITH_ATOM}" 503 RDEPEND="${PYTHON_USE_WITH_ATOM}"
504fi
505
506# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
507# @DESCRIPTION:
508# Set this to define default functions for the following ebuild phases:
509# src_prepare, src_configure, src_compile, src_test, src_install.
510if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
511 python_src_prepare() {
512 python_copy_sources
513 }
514
515 for python_default_function in src_configure src_compile src_test src_install; do
516 eval "python_${python_default_function}() { python_execute_function -d -s; }"
517 done
518 unset python_default_function
519
520 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
445fi 521fi
446 522
447# @FUNCTION: python_disable_pyc 523# @FUNCTION: python_disable_pyc
448# @DESCRIPTION: 524# @DESCRIPTION:
449# Tell Python not to automatically recompile modules to .pyc/.pyo 525# Tell Python not to automatically recompile modules to .pyc/.pyo

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.71

  ViewVC Help
Powered by ViewVC 1.1.20