/[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.72
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.72 2009/09/11 19:55:05 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-20090801" 26 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804"
26fi 27fi
27 28
28__python_eclass_test() { 29__python_eclass_test() {
29 __python_version_extract 2.3 30 __python_version_extract 2.3
30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 31 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
64 tmpstr="$(${python} -V 2>&1 )" 65 tmpstr="$(${python} -V 2>&1 )"
65 export PYVER_ALL="${tmpstr#Python }" 66 export PYVER_ALL="${tmpstr#Python }"
66 __python_version_extract $PYVER_ALL 67 __python_version_extract $PYVER_ALL
67} 68}
68 69
69# @FUNCTION: get_python 70# @FUNCTION: PYTHON
70# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 71# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}">
71# @DESCRIPTION: 72# @DESCRIPTION:
72# 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
73# 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.
74get_python() { 75PYTHON() {
75 local absolute_path="0" slot= 76 local absolute_path="0" slot=
76 77
77 while (($#)); do 78 while (($#)); do
78 case "$1" in 79 case "$1" in
79 -a|--absolute-path) 80 -a|--absolute-path)
80 absolute_path="1" 81 absolute_path="1"
82 ;;
83 --)
84 break
81 ;; 85 ;;
82 -*) 86 -*)
83 die "${FUNCNAME}(): Unrecognized option $1" 87 die "${FUNCNAME}(): Unrecognized option $1"
84 ;; 88 ;;
85 *) 89 *)
110 114
111# @FUNCTION: validate_PYTHON_ABIS 115# @FUNCTION: validate_PYTHON_ABIS
112# @DESCRIPTION: 116# @DESCRIPTION:
113# Make sure PYTHON_ABIS variable has valid value. 117# Make sure PYTHON_ABIS variable has valid value.
114validate_PYTHON_ABIS() { 118validate_PYTHON_ABIS() {
119 # 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
121 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
122 fi
123
115 # Ensure that /usr/bin/python and /usr/bin/python-config are scripts. 124 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
116 if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper script"* ]]; then 125 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
117 die "/usr/bin/python isn't valid script" 126 die "'/usr/bin/python' isn't valid symlink"
118 fi 127 fi
119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 128 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
120 die "/usr/bin/python-config isn't valid script" 129 die "'/usr/bin/python-config' isn't valid script"
121 fi 130 fi
122 131
123 # 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.
124 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
125 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 134 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
126 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
127 for ABI in ${USE_PYTHON}; do 142 for ABI in ${USE_PYTHON}; do
128 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 143 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
129 ewarn "Ignoring unsupported Python ABI '${ABI}'" 144 die "USE_PYTHON variable contains invalid value '${ABI}'"
130 continue
131 fi 145 fi
132 support_ABI="1" 146 support_ABI="1"
147 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
148 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
149 support_ABI="0"
150 break
151 fi
152 done
153 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
154 done
155 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
156
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
162 python_version
163
133 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 164 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
134 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 165 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then
135 support_ABI="0" 166 die "Active Python version isn't supported by ${CATEGORY}/${PF}"
136 break
137 fi 167 fi
138 done 168 done
139 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
140 done
141 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
142 fi
143
144 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
145 python_version
146 export PYTHON_ABIS="${PYVER}" 169 export PYTHON_ABIS="${PYVER}"
147 fi 170 fi
171 fi
172
173 local PYTHON_ABI
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.
181 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
182 die "'python' doesn't respect EPYTHON variable"
183 fi
184 done
148} 185}
149 186
150# @FUNCTION: python_copy_sources 187# @FUNCTION: python_copy_sources
151# @USAGE: [directory] 188# @USAGE: [--no-link] [--] [directory]
152# @DESCRIPTION: 189# @DESCRIPTION:
153# Copy unpacked sources of given package for each Python ABI. 190# Copy unpacked sources of given package for each Python ABI.
154python_copy_sources() { 191python_copy_sources() {
155 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
156 211
157 if [[ "$#" -eq "0" ]]; then 212 if [[ "$#" -eq "0" ]]; then
158 if [[ "${WORKDIR}" == "${S}" ]]; then 213 if [[ "${WORKDIR}" == "${S}" ]]; then
159 die "${FUNCNAME}() cannot be used" 214 die "${FUNCNAME}() cannot be used"
160 fi 215 fi
164 fi 219 fi
165 220
166 validate_PYTHON_ABIS 221 validate_PYTHON_ABIS
167 for PYTHON_ABI in ${PYTHON_ABIS}; do 222 for PYTHON_ABI in ${PYTHON_ABIS}; do
168 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
169 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
170 done 229 done
171 done 230 done
172} 231}
173 232
174# @FUNCTION: python_set_build_dir_symlink 233# @FUNCTION: python_set_build_dir_symlink
176# @DESCRIPTION: 235# @DESCRIPTION:
177# Create build directory symlink. 236# Create build directory symlink.
178python_set_build_dir_symlink() { 237python_set_build_dir_symlink() {
179 local dir="$1" 238 local dir="$1"
180 239
181 [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" 240 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
182 [[ -z "${dir}" ]] && dir="build" 241 [[ -z "${dir}" ]] && dir="build"
183 242
184 # Don't delete preexistent directories. 243 # Don't delete preexistent directories.
185 rm -f "${dir}" || die "Deletion of '${dir}' failed" 244 rm -f "${dir}" || die "Deletion of '${dir}' failed"
186 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"
187} 246}
188 247
189# @FUNCTION: python_execute_function 248# @FUNCTION: python_execute_function
190# @USAGE: [--action-message message] [--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]
191# @DESCRIPTION: 250# @DESCRIPTION:
192# Execute specified function for each value of PYTHON_ABIS, optionally passing 251# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
193# additional arguments. The specified function can use PYTHON_ABI variable. 252# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
194python_execute_function() { 253python_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" 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"
196 255
197 while (($#)); do 256 while (($#)); do
198 case "$1" in 257 case "$1" in
199 --action-message) 258 --action-message)
200 action_message_template="$2" 259 action_message_template="$2"
201 shift 260 shift
202 ;; 261 ;;
262 -d|--default-function)
263 default_function="1"
264 ;;
203 --failure-message) 265 --failure-message)
204 failure_message_template="$2" 266 failure_message_template="$2"
205 shift 267 shift
206 ;; 268 ;;
207 --nonfatal) 269 --nonfatal)
211 quiet="1" 273 quiet="1"
212 ;; 274 ;;
213 -s|--separate-build-dirs) 275 -s|--separate-build-dirs)
214 separate_build_dirs="1" 276 separate_build_dirs="1"
215 ;; 277 ;;
278 --)
279 break
280 ;;
216 -*) 281 -*)
217 die "${FUNCNAME}(): Unrecognized option $1" 282 die "${FUNCNAME}(): Unrecognized option '$1'"
218 ;; 283 ;;
219 *) 284 *)
220 break 285 break
221 ;; 286 ;;
222 esac 287 esac
223 shift 288 shift
224 done 289 done
225 290
291 if [[ "${default_function}" == "0" ]]; then
226 if [[ "$#" -eq "0" ]]; then 292 if [[ "$#" -eq "0" ]]; then
227 die "${FUNCNAME}(): Missing function name" 293 die "${FUNCNAME}(): Missing function name"
228 fi 294 fi
229 function="$1" 295 function="$1"
230 shift 296 shift
297
298 if [[ -z "$(type -t "${function}")" ]]; then
299 die "${FUNCNAME}(): '${function}' function isn't defined"
300 fi
301 else
302 if [[ "$#" -ne "0" ]]; then
303 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
304 fi
305 if has "${EAPI:-0}" 0 1; then
306 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
307 fi
308
309 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
310 if has "${EAPI}" 2; then
311 python_default_function() {
312 econf
313 }
314 else
315 python_default_function() {
316 nonfatal econf
317 }
318 fi
319 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
320 python_default_function() {
321 emake
322 }
323 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
324 python_default_function() {
325 if emake -j1 -n check &> /dev/null; then
326 emake -j1 check
327 elif emake -j1 -n test &> /dev/null; then
328 emake -j1 test
329 fi
330 }
331 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
332 python_default_function() {
333 emake DESTDIR="${D}" install
334 }
335 else
336 die "${FUNCNAME}(): --default-function option cannot be used in this ebuild phase"
337 fi
338 function="python_default_function"
339 fi
231 340
232 if [[ "${quiet}" == "0" ]]; then 341 if [[ "${quiet}" == "0" ]]; then
233 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 342 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
234 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 343 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
235 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 344 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
264 else 373 else
265 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 374 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
266 fi 375 fi
267 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 376 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
268 fi 377 fi
378
269 if [[ "${separate_build_dirs}" == "1" ]]; then 379 if [[ "${separate_build_dirs}" == "1" ]]; then
380 export BUILDDIR="${S}-${PYTHON_ABI}"
270 pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed" 381 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
382 else
383 export BUILDDIR="${S}"
271 fi 384 fi
272 if ! EPYTHON="$(get_python)" "${function}" "$@"; then 385
386 previous_directory_stack_length="${#DIRSTACK[@]}"
387
388 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
389 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
390 else
391 EPYTHON="$(PYTHON)" "${function}" "$@"
392 fi
393
394 if [[ "$?" != "0" ]]; then
273 if [[ -n "${failure_message_template}" ]]; then 395 if [[ -n "${failure_message_template}" ]]; then
274 failure_message="$(eval echo -n "${failure_message_template}")" 396 failure_message="$(eval echo -n "${failure_message_template}")"
275 else 397 else
276 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 398 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
277 fi 399 fi
278 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 400
279 local ABI enabled_PYTHON_ABIS 401 if [[ "${nonfatal}" == "1" ]]; then
280 for ABI in ${PYTHON_ABIS}; do
281 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
282 done
283 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
284 if [[ "${quiet}" == "0" ]]; then 402 if [[ "${quiet}" == "0" ]]; then
285 ewarn "${RED}${failure_message}${NORMAL}" 403 ewarn "${RED}${failure_message}${NORMAL}"
286 fi 404 fi
405 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
406 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
407 local ABI enabled_PYTHON_ABIS=
408 for ABI in ${PYTHON_ABIS}; do
409 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
410 done
411 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
412 fi
413 if [[ "${quiet}" == "0" ]]; then
414 ewarn "${RED}${failure_message}${NORMAL}"
415 fi
416 if [[ -z "${PYTHON_ABIS}" ]]; then
417 die "${function}() function failed with all enabled versions of Python"
418 fi
287 else 419 else
288 die "${failure_message}" 420 die "${failure_message}"
289 fi 421 fi
290 fi 422 fi
423
424 if [[ "${#DIRSTACK[@]}" -lt "${previous_directory_stack_length}" ]]; then
425 die "Directory stack decreased illegally"
426 fi
427
428 while [[ "${#DIRSTACK[@]}" -gt "${previous_directory_stack_length}" ]]; do
429 popd > /dev/null || die "popd failed"
430 done
431
291 if [[ "${separate_build_dirs}" == "1" ]]; then 432 if [[ "${separate_build_dirs}" == "1" ]]; then
292 popd > /dev/null || die "popd failed" 433 popd > /dev/null || die "popd failed"
293 fi 434 fi
435 unset BUILDDIR
294 done 436 done
437
438 if [[ "${default_function}" == "1" ]]; then
439 unset -f python_default_function
440 fi
295} 441}
296 442
297 443
298# @ECLASS-VARIABLE: PYTHON_USE_WITH 444# @ECLASS-VARIABLE: PYTHON_USE_WITH
299# @DESCRIPTION: 445# @DESCRIPTION:
313 459
314# @FUNCTION: python_pkg_setup 460# @FUNCTION: python_pkg_setup
315# @DESCRIPTION: 461# @DESCRIPTION:
316# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 462# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
317# are respected. Only exported if one of those variables is set. 463# are respected. Only exported if one of those variables is set.
318if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 464if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
319 python_pkg_setup_fail() { 465 python_pkg_setup_fail() {
320 eerror "${1}" 466 eerror "${1}"
321 die "${1}" 467 die "${1}"
322 } 468 }
323 469
365 fi 511 fi
366 DEPEND="${PYTHON_USE_WITH_ATOM}" 512 DEPEND="${PYTHON_USE_WITH_ATOM}"
367 RDEPEND="${PYTHON_USE_WITH_ATOM}" 513 RDEPEND="${PYTHON_USE_WITH_ATOM}"
368fi 514fi
369 515
516# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
517# @DESCRIPTION:
518# Set this to define default functions for the following ebuild phases:
519# src_prepare, src_configure, src_compile, src_test, src_install.
520if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
521 python_src_prepare() {
522 python_copy_sources
523 }
524
525 for python_default_function in src_configure src_compile src_test src_install; do
526 eval "python_${python_default_function}() { python_execute_function -d -s; }"
527 done
528 unset python_default_function
529
530 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
531fi
532
370# @FUNCTION: python_disable_pyc 533# @FUNCTION: python_disable_pyc
371# @DESCRIPTION: 534# @DESCRIPTION:
372# Tells python not to automatically recompile modules to .pyc/.pyo 535# Tell Python not to automatically recompile modules to .pyc/.pyo
373# even if the timestamps/version stamps don't match. This is done 536# even if the timestamps/version stamps don't match. This is done
374# to protect sandbox. 537# to protect sandbox.
375#
376# note: supported by >=dev-lang/python-2.2.3-r3 only.
377#
378python_disable_pyc() { 538python_disable_pyc() {
379 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above 539 export PYTHONDONTWRITEBYTECODE="1"
380 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
381} 540}
382 541
383# @FUNCTION: python_enable_pyc 542# @FUNCTION: python_enable_pyc
384# @DESCRIPTION: 543# @DESCRIPTION:
385# Tells python to automatically recompile modules to .pyc/.pyo if the 544# Tell Python to automatically recompile modules to .pyc/.pyo if the
386# timestamps/version stamps change 545# timestamps/version stamps have changed.
387python_enable_pyc() { 546python_enable_pyc() {
388 unset PYTHONDONTWRITEBYTECODE 547 unset PYTHONDONTWRITEBYTECODE
389 unset PYTHON_DONTCOMPILE
390} 548}
391 549
392python_disable_pyc 550python_disable_pyc
393 551
394# @FUNCTION: python_need_rebuild 552# @FUNCTION: python_need_rebuild
426# @FUNCTION: python_get_sitedir 584# @FUNCTION: python_get_sitedir
427# @DESCRIPTION: 585# @DESCRIPTION:
428# Run without arguments, returns the Python site-packages directory. 586# Run without arguments, returns the Python site-packages directory.
429python_get_sitedir() { 587python_get_sitedir() {
430 echo "$(python_get_libdir)/site-packages" 588 echo "$(python_get_libdir)/site-packages"
431}
432
433# @FUNCTION: python_makesym
434# @DESCRIPTION:
435# Run without arguments, it will create the /usr/bin/python symlinks
436# to the latest installed version
437python_makesym() {
438 alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]"
439 alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]"
440} 589}
441 590
442# @FUNCTION: python_tkinter_exists 591# @FUNCTION: python_tkinter_exists
443# @DESCRIPTION: 592# @DESCRIPTION:
444# Run without arguments, checks if python was compiled with Tkinter 593# Run without arguments, checks if python was compiled with Tkinter
505 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 654 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
506 done 655 done
507 656
508 if ((${#myfiles[@]})); then 657 if ((${#myfiles[@]})); then
509 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 658 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}"
510 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 659 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null
511 else 660 else
512 ewarn "No files to compile!" 661 ewarn "No files to compile!"
513 fi 662 fi
514} 663}
515 664
563 else 712 else
564 ewarn "'${root}/$1' doesn't exist!" 713 ewarn "'${root}/$1' doesn't exist!"
565 fi 714 fi
566 else 715 else
567 for PYTHON_ABI in ${PYTHON_ABIS}; do 716 for PYTHON_ABI in ${PYTHON_ABIS}; do
568 if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then 717 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
569 site_packages_dirs+=("$1") 718 site_packages_dirs+=("$1")
570 break 719 break
571 elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then 720 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
572 site_packages_files+=("$1") 721 site_packages_files+=("$1")
573 break 722 break
574 elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then 723 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
575 ewarn "'$1' is not a file or a directory!" 724 ewarn "'$1' is not a file or a directory!"
576 else 725 else
577 ewarn "'$1' doesn't exist!" 726 ewarn "'$1' doesn't exist!"
578 fi 727 fi
579 done 728 done
590 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 739 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
591 return_code="0" 740 return_code="0"
592 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 741 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
593 if ((${#site_packages_dirs[@]})); then 742 if ((${#site_packages_dirs[@]})); then
594 for dir in "${site_packages_dirs[@]}"; do 743 for dir in "${site_packages_dirs[@]}"; do
595 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 744 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
596 done 745 done
597 "$(get_python)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 746 "$(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" 747 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
599 fi 748 fi
600 if ((${#site_packages_files[@]})); then 749 if ((${#site_packages_files[@]})); then
601 for file in "${site_packages_files[@]}"; do 750 for file in "${site_packages_files[@]}"; do
602 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 751 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
603 done 752 done
604 "$(get_python)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 753 "$(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" 754 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
606 fi 755 fi
607 eend "${return_code}" 756 eend "${return_code}"
608 fi 757 fi
609 unset site_packages_absolute_dirs site_packages_absolute_files 758 unset site_packages_absolute_dirs site_packages_absolute_files
610 done 759 done
614 763
615 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 764 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
616 return_code="0" 765 return_code="0"
617 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." 766 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
618 if ((${#other_dirs[@]})); then 767 if ((${#other_dirs[@]})); then
619 python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 768 python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
620 python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 769 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
621 fi 770 fi
622 if ((${#other_files[@]})); then 771 if ((${#other_files[@]})); then
623 python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 772 python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
624 python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 773 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
625 fi 774 fi
626 eend "${return_code}" 775 eend "${return_code}"
627 fi 776 fi
628 else 777 else
629 local myroot mydirs=() myfiles=() myopts=() 778 local myroot mydirs=() myfiles=() myopts=() return_code="0"
630 779
631 # strip trailing slash 780 # strip trailing slash
632 myroot="${ROOT%/}" 781 myroot="${ROOT%/}"
633 782
634 # respect ROOT and options passed to compileall.py 783 # respect ROOT and options passed to compileall.py
672 821
673 ebegin "Byte compiling python modules for python-${PYVER} .." 822 ebegin "Byte compiling python modules for python-${PYVER} .."
674 if ((${#mydirs[@]})); then 823 if ((${#mydirs[@]})); then
675 python${PYVER} \ 824 python${PYVER} \
676 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 825 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
677 "${myopts[@]}" "${mydirs[@]}" 826 "${myopts[@]}" "${mydirs[@]}" || return_code="1"
678 python${PYVER} -O \ 827 python${PYVER} -O \
679 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 828 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
680 "${myopts[@]}" "${mydirs[@]}" 829 "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
681 fi 830 fi
682 831
683 if ((${#myfiles[@]})); then 832 if ((${#myfiles[@]})); then
684 python_mod_compile "${myfiles[@]}" 833 python_mod_compile "${myfiles[@]}"
685 fi 834 fi
686 835
687 eend $? 836 eend "${return_code}"
688 fi 837 fi
689} 838}
690 839
691# @FUNCTION: python_mod_cleanup 840# @FUNCTION: python_mod_cleanup
692# @USAGE: [directory] 841# @USAGE: [directory]
715 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 864 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
716 elif [[ "$1" =~ ^/ ]]; then 865 elif [[ "$1" =~ ^/ ]]; then
717 SEARCH_PATH+=("${root}/${1#/}") 866 SEARCH_PATH+=("${root}/${1#/}")
718 else 867 else
719 for PYTHON_ABI in ${PYTHON_ABIS}; do 868 for PYTHON_ABI in ${PYTHON_ABIS}; do
720 SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") 869 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
721 done 870 done
722 fi 871 fi
723 shift 872 shift
724 done 873 done
725 else 874 else
729 else 878 else
730 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) 879 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
731 fi 880 fi
732 881
733 for path in "${SEARCH_PATH[@]}"; do 882 for path in "${SEARCH_PATH[@]}"; do
883 [[ ! -d "${path}" ]] && continue
734 einfo "Cleaning orphaned Python bytecode from ${path} .." 884 einfo "Cleaning orphaned Python bytecode from ${path} .."
735 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do 885 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
736 src_py="${REPLY%[co]}" 886 src_py="${REPLY%[co]}"
737 [[ -f "${src_py}" ]] && continue 887 [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue
738 einfo "Purging ${src_py}[co]" 888 einfo "Purging ${src_py}[co]"
739 rm -f "${src_py}"[co] 889 rm -f "${src_py}"[co]
740 done 890 done
741 891
742 # Attempt to remove directories that may be empty. 892 # Attempt to remove directories that may be empty.
743 find "${path}" -type d | sort -r | while read -r dir; do 893 find "${path}" -type d | sort -r | while read -r dir; do
744 rmdir "${dir}" 2>/dev/null 894 rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}"
745 done 895 done
746 done 896 done
747} 897}

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

  ViewVC Help
Powered by ViewVC 1.1.20