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

Diff of /eclass/python.eclass

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

Revision 1.56 Revision 1.60
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.56 2009/08/01 22:36:20 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.60 2009/08/05 18:31:30 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#
20else 20else
21 PYTHON_ATOM="dev-lang/python" 21 PYTHON_ATOM="dev-lang/python"
22fi 22fi
23 23
24if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 24if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
25 DEPEND="${DEPEND} >=app-admin/eselect-python-20090801" 25 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804"
26fi 26fi
27 27
28__python_eclass_test() { 28__python_eclass_test() {
29 __python_version_extract 2.3 29 __python_version_extract 2.3
30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
64 tmpstr="$(${python} -V 2>&1 )" 64 tmpstr="$(${python} -V 2>&1 )"
65 export PYVER_ALL="${tmpstr#Python }" 65 export PYVER_ALL="${tmpstr#Python }"
66 __python_version_extract $PYVER_ALL 66 __python_version_extract $PYVER_ALL
67} 67}
68 68
69# @FUNCTION: get_python 69# @FUNCTION: PYTHON
70# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 70# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}">
71# @DESCRIPTION: 71# @DESCRIPTION:
72# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 72# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
73# is ommitted, then PYTHON_ABI environment variable must be set and is used. 73# is ommitted, then PYTHON_ABI environment variable must be set and is used.
74get_python() { 74PYTHON() {
75 local absolute_path="0" slot= 75 local absolute_path="0" slot=
76 76
77 while (($#)); do 77 while (($#)); do
78 case "$1" in 78 case "$1" in
79 -a|--absolute-path) 79 -a|--absolute-path)
110 110
111# @FUNCTION: validate_PYTHON_ABIS 111# @FUNCTION: validate_PYTHON_ABIS
112# @DESCRIPTION: 112# @DESCRIPTION:
113# Make sure PYTHON_ABIS variable has valid value. 113# Make sure PYTHON_ABIS variable has valid value.
114validate_PYTHON_ABIS() { 114validate_PYTHON_ABIS() {
115 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
116 if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then
117 die "/usr/bin/python isn't valid program"
118 fi
119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
120 die "/usr/bin/python-config isn't valid script"
121 fi
122
115 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 123 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
116 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then 124 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then
117 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 125 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
118 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 126 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
119 for ABI in ${USE_PYTHON}; do 127 for ABI in ${USE_PYTHON}; do
177 rm -f "${dir}" || die "Deletion of '${dir}' failed" 185 rm -f "${dir}" || die "Deletion of '${dir}' failed"
178 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 186 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
179} 187}
180 188
181# @FUNCTION: python_execute_function 189# @FUNCTION: python_execute_function
182# @USAGE: [--action-message message] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 190# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments]
183# @DESCRIPTION: 191# @DESCRIPTION:
184# Execute specified function for each value of PYTHON_ABIS, optionally passing 192# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
185# additional arguments. The specified function can use PYTHON_ABI variable. 193# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
186python_execute_function() { 194python_execute_function() {
187 local action action_message action_message_template= failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" 195 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"
188 196
189 while (($#)); do 197 while (($#)); do
190 case "$1" in 198 case "$1" in
191 --action-message) 199 --action-message)
192 action_message_template="$2" 200 action_message_template="$2"
193 shift 201 shift
194 ;; 202 ;;
203 -d|--default-function)
204 default_function="1"
205 ;;
195 --failure-message) 206 --failure-message)
196 failure_message_template="$2" 207 failure_message_template="$2"
197 shift 208 shift
198 ;; 209 ;;
199 --nonfatal) 210 --nonfatal)
213 ;; 224 ;;
214 esac 225 esac
215 shift 226 shift
216 done 227 done
217 228
229 if [[ "${default_function}" == "0" ]]; then
218 if [[ "$#" -eq "0" ]]; then 230 if [[ "$#" -eq "0" ]]; then
219 die "${FUNCNAME}(): Missing function name" 231 die "${FUNCNAME}(): Missing function name"
220 fi 232 fi
221 function="$1" 233 function="$1"
222 shift 234 shift
235 else
236 if [[ "$#" -ne "0" ]]; then
237 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously"
238 fi
239 if has "${EAPI:-0}" 0 1; then
240 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI"
241 fi
242
243 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
244 python_default_function() {
245 econf
246 }
247 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
248 python_default_function() {
249 emake
250 }
251 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
252 python_default_function() {
253 if emake -j1 -n check &> /dev/null; then
254 emake -j1 check
255 elif emake -j1 -n test &> /dev/null; then
256 emake -j1 test
257 fi
258 }
259 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
260 python_default_function() {
261 emake DESTDIR="${D}" install
262 }
263 else
264 die "${FUNCNAME}(): --default-function option cannot be used in this ebuild phase"
265 fi
266 function="python_default_function"
267 fi
223 268
224 if [[ "${quiet}" == "0" ]]; then 269 if [[ "${quiet}" == "0" ]]; then
225 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 270 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
226 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 271 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
227 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 272 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
257 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 302 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
258 fi 303 fi
259 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 304 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
260 fi 305 fi
261 if [[ "${separate_build_dirs}" == "1" ]]; then 306 if [[ "${separate_build_dirs}" == "1" ]]; then
307 export BUILDDIR="${S}-${PYTHON_ABI}"
262 pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed" 308 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
309 else
310 export BUILDDIR="${S}"
263 fi 311 fi
264 if ! EPYTHON="$(get_python)" "${function}" "$@"; then 312 if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then
265 if [[ -n "${failure_message_template}" ]]; then 313 if [[ -n "${failure_message_template}" ]]; then
266 failure_message="$(eval echo -n "${failure_message_template}")" 314 failure_message="$(eval echo -n "${failure_message_template}")"
267 else 315 else
268 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 316 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
269 fi 317 fi
281 fi 329 fi
282 fi 330 fi
283 if [[ "${separate_build_dirs}" == "1" ]]; then 331 if [[ "${separate_build_dirs}" == "1" ]]; then
284 popd > /dev/null || die "popd failed" 332 popd > /dev/null || die "popd failed"
285 fi 333 fi
334 unset BUILDDIR
286 done 335 done
336
337 if [[ "${default_function}" == "1" ]]; then
338 unset -f python_default_function
339 fi
287} 340}
288 341
289 342
290# @ECLASS-VARIABLE: PYTHON_USE_WITH 343# @ECLASS-VARIABLE: PYTHON_USE_WITH
291# @DESCRIPTION: 344# @DESCRIPTION:
584 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 637 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
585 if ((${#site_packages_dirs[@]})); then 638 if ((${#site_packages_dirs[@]})); then
586 for dir in "${site_packages_dirs[@]}"; do 639 for dir in "${site_packages_dirs[@]}"; do
587 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 640 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}")
588 done 641 done
589 "$(get_python)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 642 "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
590 "$(get_python)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 643 "$(PYTHON)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
591 fi 644 fi
592 if ((${#site_packages_files[@]})); then 645 if ((${#site_packages_files[@]})); then
593 for file in "${site_packages_files[@]}"; do 646 for file in "${site_packages_files[@]}"; do
594 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 647 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}")
595 done 648 done
596 "$(get_python)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 649 "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
597 "$(get_python)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 650 "$(PYTHON)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
598 fi 651 fi
599 eend "${return_code}" 652 eend "${return_code}"
600 fi 653 fi
601 unset site_packages_absolute_dirs site_packages_absolute_files 654 unset site_packages_absolute_dirs site_packages_absolute_files
602 done 655 done

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.60

  ViewVC Help
Powered by ViewVC 1.1.20