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

Diff of /eclass/python.eclass

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

Revision 1.57 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.57 2009/08/02 16:56:41 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 scripts. 115 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
116 if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper script"* ]]; then 116 if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then
117 die "/usr/bin/python isn't valid script" 117 die "/usr/bin/python isn't valid program"
118 fi 118 fi
119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
120 die "/usr/bin/python-config isn't valid script" 120 die "/usr/bin/python-config isn't valid script"
121 fi 121 fi
122 122
185 rm -f "${dir}" || die "Deletion of '${dir}' failed" 185 rm -f "${dir}" || die "Deletion of '${dir}' failed"
186 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"
187} 187}
188 188
189# @FUNCTION: python_execute_function 189# @FUNCTION: python_execute_function
190# @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]
191# @DESCRIPTION: 191# @DESCRIPTION:
192# Execute specified function for each value of PYTHON_ABIS, optionally passing 192# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
193# additional arguments. The specified function can use PYTHON_ABI variable. 193# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
194python_execute_function() { 194python_execute_function() {
195 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"
196 196
197 while (($#)); do 197 while (($#)); do
198 case "$1" in 198 case "$1" in
199 --action-message) 199 --action-message)
200 action_message_template="$2" 200 action_message_template="$2"
201 shift 201 shift
202 ;; 202 ;;
203 -d|--default-function)
204 default_function="1"
205 ;;
203 --failure-message) 206 --failure-message)
204 failure_message_template="$2" 207 failure_message_template="$2"
205 shift 208 shift
206 ;; 209 ;;
207 --nonfatal) 210 --nonfatal)
221 ;; 224 ;;
222 esac 225 esac
223 shift 226 shift
224 done 227 done
225 228
229 if [[ "${default_function}" == "0" ]]; then
226 if [[ "$#" -eq "0" ]]; then 230 if [[ "$#" -eq "0" ]]; then
227 die "${FUNCNAME}(): Missing function name" 231 die "${FUNCNAME}(): Missing function name"
228 fi 232 fi
229 function="$1" 233 function="$1"
230 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
231 268
232 if [[ "${quiet}" == "0" ]]; then 269 if [[ "${quiet}" == "0" ]]; then
233 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 270 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
234 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 271 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
235 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 272 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
265 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 302 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
266 fi 303 fi
267 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 304 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
268 fi 305 fi
269 if [[ "${separate_build_dirs}" == "1" ]]; then 306 if [[ "${separate_build_dirs}" == "1" ]]; then
307 export BUILDDIR="${S}-${PYTHON_ABI}"
270 pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed" 308 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
309 else
310 export BUILDDIR="${S}"
271 fi 311 fi
272 if ! EPYTHON="$(get_python)" "${function}" "$@"; then 312 if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then
273 if [[ -n "${failure_message_template}" ]]; then 313 if [[ -n "${failure_message_template}" ]]; then
274 failure_message="$(eval echo -n "${failure_message_template}")" 314 failure_message="$(eval echo -n "${failure_message_template}")"
275 else 315 else
276 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 316 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
277 fi 317 fi
289 fi 329 fi
290 fi 330 fi
291 if [[ "${separate_build_dirs}" == "1" ]]; then 331 if [[ "${separate_build_dirs}" == "1" ]]; then
292 popd > /dev/null || die "popd failed" 332 popd > /dev/null || die "popd failed"
293 fi 333 fi
334 unset BUILDDIR
294 done 335 done
336
337 if [[ "${default_function}" == "1" ]]; then
338 unset -f python_default_function
339 fi
295} 340}
296 341
297 342
298# @ECLASS-VARIABLE: PYTHON_USE_WITH 343# @ECLASS-VARIABLE: PYTHON_USE_WITH
299# @DESCRIPTION: 344# @DESCRIPTION:
592 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 637 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
593 if ((${#site_packages_dirs[@]})); then 638 if ((${#site_packages_dirs[@]})); then
594 for dir in "${site_packages_dirs[@]}"; do 639 for dir in "${site_packages_dirs[@]}"; do
595 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 640 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}")
596 done 641 done
597 "$(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"
598 "$(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"
599 fi 644 fi
600 if ((${#site_packages_files[@]})); then 645 if ((${#site_packages_files[@]})); then
601 for file in "${site_packages_files[@]}"; do 646 for file in "${site_packages_files[@]}"; do
602 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 647 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}")
603 done 648 done
604 "$(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"
605 "$(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"
606 fi 651 fi
607 eend "${return_code}" 652 eend "${return_code}"
608 fi 653 fi
609 unset site_packages_absolute_dirs site_packages_absolute_files 654 unset site_packages_absolute_dirs site_packages_absolute_files
610 done 655 done

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

  ViewVC Help
Powered by ViewVC 1.1.20