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

Diff of /eclass/python.eclass

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

Revision 1.64 Revision 1.66
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.64 2009/08/15 21:50:31 betelgeuse Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.66 2009/08/28 16:08:51 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#
9# original author: Alastair Tse <liquidx@gentoo.org> 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. 10# @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules.
11# @DESCRIPTION: 11# @DESCRIPTION:
12# Some useful functions for dealing with python. 12# Some useful functions for dealing with Python.
13inherit alternatives multilib
14 13
14inherit multilib
15 15
16if [[ -n "${NEED_PYTHON}" ]] ; then 16if [[ -n "${NEED_PYTHON}" ]] ; then
17 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" 17 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}"
18 DEPEND="${PYTHON_ATOM}" 18 DEPEND="${PYTHON_ATOM}"
19 RDEPEND="${DEPEND}" 19 RDEPEND="${DEPEND}"
20else 20else
21 PYTHON_ATOM="dev-lang/python" 21 PYTHON_ATOM="dev-lang/python"
22fi 22fi
23 23
24DEPEND="${DEPEND} >=app-shells/bash-3.2"
24if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 25if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
25 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" 26 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804"
26fi 27fi
27 28
28__python_eclass_test() { 29__python_eclass_test() {
110 111
111# @FUNCTION: validate_PYTHON_ABIS 112# @FUNCTION: validate_PYTHON_ABIS
112# @DESCRIPTION: 113# @DESCRIPTION:
113# Make sure PYTHON_ABIS variable has valid value. 114# Make sure PYTHON_ABIS variable has valid value.
114validate_PYTHON_ABIS() { 115validate_PYTHON_ABIS() {
116 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable.
117 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
118 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
119 fi
120
115 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 121 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
116 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then 122 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
117 die "/usr/bin/python isn't valid symlink" 123 die "'/usr/bin/python' isn't valid symlink"
118 fi 124 fi
119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 125 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
120 die "/usr/bin/python-config isn't valid script" 126 die "'/usr/bin/python-config' isn't valid script"
121 fi 127 fi
122 128
123 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 129 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
124 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then 130 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then
125 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 131 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
128 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 134 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
129 ewarn "Ignoring unsupported Python ABI '${ABI}'" 135 ewarn "Ignoring unsupported Python ABI '${ABI}'"
130 continue 136 continue
131 fi 137 fi
132 support_ABI="1" 138 support_ABI="1"
139 if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then
133 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 140 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
134 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 141 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
135 support_ABI="0" 142 support_ABI="0"
136 break 143 break
137 fi 144 fi
138 done 145 done
146 fi
139 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 147 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
140 done 148 done
141 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 149 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
142 fi 150 fi
143 151
144 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 152 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
145 python_version 153 python_version
146 export PYTHON_ABIS="${PYVER}" 154 export PYTHON_ABIS="${PYVER}"
147 fi 155 fi
156
157 # Ensure that EPYTHON variable is respected.
158 local PYTHON_ABI
159 for PYTHON_ABI in ${PYTHON_ABIS}; do
160 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"
162 fi
163 done
148} 164}
149 165
150# @FUNCTION: python_copy_sources 166# @FUNCTION: python_copy_sources
151# @USAGE: [directory] 167# @USAGE: [directory]
152# @DESCRIPTION: 168# @DESCRIPTION:
176# @DESCRIPTION: 192# @DESCRIPTION:
177# Create build directory symlink. 193# Create build directory symlink.
178python_set_build_dir_symlink() { 194python_set_build_dir_symlink() {
179 local dir="$1" 195 local dir="$1"
180 196
181 [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" 197 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
182 [[ -z "${dir}" ]] && dir="build" 198 [[ -z "${dir}" ]] && dir="build"
183 199
184 # Don't delete preexistent directories. 200 # Don't delete preexistent directories.
185 rm -f "${dir}" || die "Deletion of '${dir}' failed" 201 rm -f "${dir}" || die "Deletion of '${dir}' failed"
186 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 202 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
307 else 323 else
308 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 324 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
309 fi 325 fi
310 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 326 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
311 fi 327 fi
328
312 if [[ "${separate_build_dirs}" == "1" ]]; then 329 if [[ "${separate_build_dirs}" == "1" ]]; then
313 export BUILDDIR="${S}-${PYTHON_ABI}" 330 export BUILDDIR="${S}-${PYTHON_ABI}"
314 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 331 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
315 else 332 else
316 export BUILDDIR="${S}" 333 export BUILDDIR="${S}"
317 fi 334 fi
335
336 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
337 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
338 else
318 if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then 339 EPYTHON="$(PYTHON)" "${function}" "$@"
340 fi
341
342 if [[ "$?" != "0" ]]; then
319 if [[ -n "${failure_message_template}" ]]; then 343 if [[ -n "${failure_message_template}" ]]; then
320 failure_message="$(eval echo -n "${failure_message_template}")" 344 failure_message="$(eval echo -n "${failure_message_template}")"
321 else 345 else
322 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 346 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
323 fi 347 fi
348
324 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 349 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
325 local ABI enabled_PYTHON_ABIS 350 local ABI enabled_PYTHON_ABIS
326 for ABI in ${PYTHON_ABIS}; do 351 for ABI in ${PYTHON_ABIS}; do
327 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" 352 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
328 done 353 done
332 fi 357 fi
333 else 358 else
334 die "${failure_message}" 359 die "${failure_message}"
335 fi 360 fi
336 fi 361 fi
362
337 if [[ "${separate_build_dirs}" == "1" ]]; then 363 if [[ "${separate_build_dirs}" == "1" ]]; then
338 popd > /dev/null || die "popd failed" 364 popd > /dev/null || die "popd failed"
339 fi 365 fi
340 unset BUILDDIR 366 unset BUILDDIR
341 done 367 done
418 RDEPEND="${PYTHON_USE_WITH_ATOM}" 444 RDEPEND="${PYTHON_USE_WITH_ATOM}"
419fi 445fi
420 446
421# @FUNCTION: python_disable_pyc 447# @FUNCTION: python_disable_pyc
422# @DESCRIPTION: 448# @DESCRIPTION:
423# Tells python not to automatically recompile modules to .pyc/.pyo 449# Tell Python not to automatically recompile modules to .pyc/.pyo
424# even if the timestamps/version stamps don't match. This is done 450# even if the timestamps/version stamps don't match. This is done
425# to protect sandbox. 451# to protect sandbox.
426#
427# note: supported by >=dev-lang/python-2.2.3-r3 only.
428#
429python_disable_pyc() { 452python_disable_pyc() {
430 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above 453 export PYTHONDONTWRITEBYTECODE="1"
431 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
432} 454}
433 455
434# @FUNCTION: python_enable_pyc 456# @FUNCTION: python_enable_pyc
435# @DESCRIPTION: 457# @DESCRIPTION:
436# Tells python to automatically recompile modules to .pyc/.pyo if the 458# Tell Python to automatically recompile modules to .pyc/.pyo if the
437# timestamps/version stamps change 459# timestamps/version stamps have changed.
438python_enable_pyc() { 460python_enable_pyc() {
439 unset PYTHONDONTWRITEBYTECODE 461 unset PYTHONDONTWRITEBYTECODE
440 unset PYTHON_DONTCOMPILE
441} 462}
442 463
443python_disable_pyc 464python_disable_pyc
444 465
445# @FUNCTION: python_need_rebuild 466# @FUNCTION: python_need_rebuild
477# @FUNCTION: python_get_sitedir 498# @FUNCTION: python_get_sitedir
478# @DESCRIPTION: 499# @DESCRIPTION:
479# Run without arguments, returns the Python site-packages directory. 500# Run without arguments, returns the Python site-packages directory.
480python_get_sitedir() { 501python_get_sitedir() {
481 echo "$(python_get_libdir)/site-packages" 502 echo "$(python_get_libdir)/site-packages"
482}
483
484# @FUNCTION: python_makesym
485# @DESCRIPTION:
486# Run without arguments, it will create the /usr/bin/python symlinks
487# to the latest installed version
488python_makesym() {
489 alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]"
490 alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]"
491} 503}
492 504
493# @FUNCTION: python_tkinter_exists 505# @FUNCTION: python_tkinter_exists
494# @DESCRIPTION: 506# @DESCRIPTION:
495# Run without arguments, checks if python was compiled with Tkinter 507# Run without arguments, checks if python was compiled with Tkinter

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

  ViewVC Help
Powered by ViewVC 1.1.20