/[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.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.56 2009/08/01 22:36:20 arfrever 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-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)
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
121 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
122 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
123 die "'/usr/bin/python' isn't valid symlink"
124 fi
125 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
126 die "'/usr/bin/python-config' isn't valid script"
127 fi
128
115 # 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.
116 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
117 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 131 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" 132 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 133 for ABI in ${USE_PYTHON}; do
120 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 134 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
121 ewarn "Ignoring unsupported Python ABI '${ABI}'" 135 ewarn "Ignoring unsupported Python ABI '${ABI}'"
122 continue 136 continue
123 fi 137 fi
124 support_ABI="1" 138 support_ABI="1"
139 if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then
125 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 140 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
126 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
127 support_ABI="0" 142 support_ABI="0"
128 break 143 break
129 fi 144 fi
130 done 145 done
146 fi
131 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 147 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
132 done 148 done
133 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 149 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
134 fi 150 fi
135 151
136 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 152 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
137 python_version 153 python_version
138 export PYTHON_ABIS="${PYVER}" 154 export PYTHON_ABIS="${PYVER}"
139 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
140} 164}
141 165
142# @FUNCTION: python_copy_sources 166# @FUNCTION: python_copy_sources
143# @USAGE: [directory] 167# @USAGE: [directory]
144# @DESCRIPTION: 168# @DESCRIPTION:
168# @DESCRIPTION: 192# @DESCRIPTION:
169# Create build directory symlink. 193# Create build directory symlink.
170python_set_build_dir_symlink() { 194python_set_build_dir_symlink() {
171 local dir="$1" 195 local dir="$1"
172 196
173 [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" 197 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
174 [[ -z "${dir}" ]] && dir="build" 198 [[ -z "${dir}" ]] && dir="build"
175 199
176 # Don't delete preexistent directories. 200 # Don't delete preexistent directories.
177 rm -f "${dir}" || die "Deletion of '${dir}' failed" 201 rm -f "${dir}" || die "Deletion of '${dir}' failed"
178 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"
179} 203}
180 204
181# @FUNCTION: python_execute_function 205# @FUNCTION: python_execute_function
182# @USAGE: [--action-message message] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 206# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments]
183# @DESCRIPTION: 207# @DESCRIPTION:
184# Execute specified function for each value of PYTHON_ABIS, optionally passing 208# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
185# additional arguments. The specified function can use PYTHON_ABI variable. 209# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
186python_execute_function() { 210python_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" 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"
188 212
189 while (($#)); do 213 while (($#)); do
190 case "$1" in 214 case "$1" in
191 --action-message) 215 --action-message)
192 action_message_template="$2" 216 action_message_template="$2"
193 shift 217 shift
194 ;; 218 ;;
219 -d|--default-function)
220 default_function="1"
221 ;;
195 --failure-message) 222 --failure-message)
196 failure_message_template="$2" 223 failure_message_template="$2"
197 shift 224 shift
198 ;; 225 ;;
199 --nonfatal) 226 --nonfatal)
213 ;; 240 ;;
214 esac 241 esac
215 shift 242 shift
216 done 243 done
217 244
245 if [[ "${default_function}" == "0" ]]; then
218 if [[ "$#" -eq "0" ]]; then 246 if [[ "$#" -eq "0" ]]; then
219 die "${FUNCNAME}(): Missing function name" 247 die "${FUNCNAME}(): Missing function name"
220 fi 248 fi
221 function="$1" 249 function="$1"
222 shift 250 shift
251 else
252 if [[ "$#" -ne "0" ]]; then
253 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously"
254 fi
255 if has "${EAPI:-0}" 0 1; then
256 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI"
257 fi
258
259 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
260 if has "${EAPI}" 2; then
261 python_default_function() {
262 econf
263 }
264 else
265 python_default_function() {
266 nonfatal econf
267 }
268 fi
269 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
270 python_default_function() {
271 emake
272 }
273 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
274 python_default_function() {
275 if emake -j1 -n check &> /dev/null; then
276 emake -j1 check
277 elif emake -j1 -n test &> /dev/null; then
278 emake -j1 test
279 fi
280 }
281 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
282 python_default_function() {
283 emake DESTDIR="${D}" install
284 }
285 else
286 die "${FUNCNAME}(): --default-function option cannot be used in this ebuild phase"
287 fi
288 function="python_default_function"
289 fi
223 290
224 if [[ "${quiet}" == "0" ]]; then 291 if [[ "${quiet}" == "0" ]]; then
225 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 292 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
226 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 293 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
227 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 294 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
256 else 323 else
257 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 324 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
258 fi 325 fi
259 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 326 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
260 fi 327 fi
328
261 if [[ "${separate_build_dirs}" == "1" ]]; then 329 if [[ "${separate_build_dirs}" == "1" ]]; then
330 export BUILDDIR="${S}-${PYTHON_ABI}"
262 pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed" 331 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
332 else
333 export BUILDDIR="${S}"
263 fi 334 fi
264 if ! EPYTHON="$(get_python)" "${function}" "$@"; then 335
336 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
337 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
338 else
339 EPYTHON="$(PYTHON)" "${function}" "$@"
340 fi
341
342 if [[ "$?" != "0" ]]; then
265 if [[ -n "${failure_message_template}" ]]; then 343 if [[ -n "${failure_message_template}" ]]; then
266 failure_message="$(eval echo -n "${failure_message_template}")" 344 failure_message="$(eval echo -n "${failure_message_template}")"
267 else 345 else
268 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 346 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
269 fi 347 fi
348
270 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 349 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
271 local ABI enabled_PYTHON_ABIS 350 local ABI enabled_PYTHON_ABIS
272 for ABI in ${PYTHON_ABIS}; do 351 for ABI in ${PYTHON_ABIS}; do
273 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" 352 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
274 done 353 done
278 fi 357 fi
279 else 358 else
280 die "${failure_message}" 359 die "${failure_message}"
281 fi 360 fi
282 fi 361 fi
362
283 if [[ "${separate_build_dirs}" == "1" ]]; then 363 if [[ "${separate_build_dirs}" == "1" ]]; then
284 popd > /dev/null || die "popd failed" 364 popd > /dev/null || die "popd failed"
285 fi 365 fi
366 unset BUILDDIR
286 done 367 done
368
369 if [[ "${default_function}" == "1" ]]; then
370 unset -f python_default_function
371 fi
287} 372}
288 373
289 374
290# @ECLASS-VARIABLE: PYTHON_USE_WITH 375# @ECLASS-VARIABLE: PYTHON_USE_WITH
291# @DESCRIPTION: 376# @DESCRIPTION:
305 390
306# @FUNCTION: python_pkg_setup 391# @FUNCTION: python_pkg_setup
307# @DESCRIPTION: 392# @DESCRIPTION:
308# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 393# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
309# are respected. Only exported if one of those variables is set. 394# are respected. Only exported if one of those variables is set.
310if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 395if ! has ${EAPI:-0} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
311 python_pkg_setup_fail() { 396 python_pkg_setup_fail() {
312 eerror "${1}" 397 eerror "${1}"
313 die "${1}" 398 die "${1}"
314 } 399 }
315 400
359 RDEPEND="${PYTHON_USE_WITH_ATOM}" 444 RDEPEND="${PYTHON_USE_WITH_ATOM}"
360fi 445fi
361 446
362# @FUNCTION: python_disable_pyc 447# @FUNCTION: python_disable_pyc
363# @DESCRIPTION: 448# @DESCRIPTION:
364# Tells python not to automatically recompile modules to .pyc/.pyo 449# Tell Python not to automatically recompile modules to .pyc/.pyo
365# 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
366# to protect sandbox. 451# to protect sandbox.
367#
368# note: supported by >=dev-lang/python-2.2.3-r3 only.
369#
370python_disable_pyc() { 452python_disable_pyc() {
371 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above 453 export PYTHONDONTWRITEBYTECODE="1"
372 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
373} 454}
374 455
375# @FUNCTION: python_enable_pyc 456# @FUNCTION: python_enable_pyc
376# @DESCRIPTION: 457# @DESCRIPTION:
377# Tells python to automatically recompile modules to .pyc/.pyo if the 458# Tell Python to automatically recompile modules to .pyc/.pyo if the
378# timestamps/version stamps change 459# timestamps/version stamps have changed.
379python_enable_pyc() { 460python_enable_pyc() {
380 unset PYTHONDONTWRITEBYTECODE 461 unset PYTHONDONTWRITEBYTECODE
381 unset PYTHON_DONTCOMPILE
382} 462}
383 463
384python_disable_pyc 464python_disable_pyc
385 465
386# @FUNCTION: python_need_rebuild 466# @FUNCTION: python_need_rebuild
418# @FUNCTION: python_get_sitedir 498# @FUNCTION: python_get_sitedir
419# @DESCRIPTION: 499# @DESCRIPTION:
420# Run without arguments, returns the Python site-packages directory. 500# Run without arguments, returns the Python site-packages directory.
421python_get_sitedir() { 501python_get_sitedir() {
422 echo "$(python_get_libdir)/site-packages" 502 echo "$(python_get_libdir)/site-packages"
423}
424
425# @FUNCTION: python_makesym
426# @DESCRIPTION:
427# Run without arguments, it will create the /usr/bin/python symlinks
428# to the latest installed version
429python_makesym() {
430 alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]"
431 alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]"
432} 503}
433 504
434# @FUNCTION: python_tkinter_exists 505# @FUNCTION: python_tkinter_exists
435# @DESCRIPTION: 506# @DESCRIPTION:
436# Run without arguments, checks if python was compiled with Tkinter 507# Run without arguments, checks if python was compiled with Tkinter
497 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 568 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
498 done 569 done
499 570
500 if ((${#myfiles[@]})); then 571 if ((${#myfiles[@]})); then
501 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 572 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}"
502 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 573 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null
503 else 574 else
504 ewarn "No files to compile!" 575 ewarn "No files to compile!"
505 fi 576 fi
506} 577}
507 578
555 else 626 else
556 ewarn "'${root}/$1' doesn't exist!" 627 ewarn "'${root}/$1' doesn't exist!"
557 fi 628 fi
558 else 629 else
559 for PYTHON_ABI in ${PYTHON_ABIS}; do 630 for PYTHON_ABI in ${PYTHON_ABIS}; do
560 if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then 631 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
561 site_packages_dirs+=("$1") 632 site_packages_dirs+=("$1")
562 break 633 break
563 elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then 634 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
564 site_packages_files+=("$1") 635 site_packages_files+=("$1")
565 break 636 break
566 elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then 637 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
567 ewarn "'$1' is not a file or a directory!" 638 ewarn "'$1' is not a file or a directory!"
568 else 639 else
569 ewarn "'$1' doesn't exist!" 640 ewarn "'$1' doesn't exist!"
570 fi 641 fi
571 done 642 done
582 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 653 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
583 return_code="0" 654 return_code="0"
584 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 655 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
585 if ((${#site_packages_dirs[@]})); then 656 if ((${#site_packages_dirs[@]})); then
586 for dir in "${site_packages_dirs[@]}"; do 657 for dir in "${site_packages_dirs[@]}"; do
587 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 658 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
588 done 659 done
589 "$(get_python)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 660 "$(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" 661 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
591 fi 662 fi
592 if ((${#site_packages_files[@]})); then 663 if ((${#site_packages_files[@]})); then
593 for file in "${site_packages_files[@]}"; do 664 for file in "${site_packages_files[@]}"; do
594 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 665 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
595 done 666 done
596 "$(get_python)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 667 "$(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" 668 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
598 fi 669 fi
599 eend "${return_code}" 670 eend "${return_code}"
600 fi 671 fi
601 unset site_packages_absolute_dirs site_packages_absolute_files 672 unset site_packages_absolute_dirs site_packages_absolute_files
602 done 673 done
606 677
607 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 678 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
608 return_code="0" 679 return_code="0"
609 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." 680 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
610 if ((${#other_dirs[@]})); then 681 if ((${#other_dirs[@]})); then
611 python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 682 python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
612 python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 683 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
613 fi 684 fi
614 if ((${#other_files[@]})); then 685 if ((${#other_files[@]})); then
615 python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 686 python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
616 python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 687 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
617 fi 688 fi
618 eend "${return_code}" 689 eend "${return_code}"
619 fi 690 fi
620 else 691 else
621 local myroot mydirs=() myfiles=() myopts=() 692 local myroot mydirs=() myfiles=() myopts=() return_code="0"
622 693
623 # strip trailing slash 694 # strip trailing slash
624 myroot="${ROOT%/}" 695 myroot="${ROOT%/}"
625 696
626 # respect ROOT and options passed to compileall.py 697 # respect ROOT and options passed to compileall.py
664 735
665 ebegin "Byte compiling python modules for python-${PYVER} .." 736 ebegin "Byte compiling python modules for python-${PYVER} .."
666 if ((${#mydirs[@]})); then 737 if ((${#mydirs[@]})); then
667 python${PYVER} \ 738 python${PYVER} \
668 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 739 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
669 "${myopts[@]}" "${mydirs[@]}" 740 "${myopts[@]}" "${mydirs[@]}" || return_code="1"
670 python${PYVER} -O \ 741 python${PYVER} -O \
671 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 742 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
672 "${myopts[@]}" "${mydirs[@]}" 743 "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
673 fi 744 fi
674 745
675 if ((${#myfiles[@]})); then 746 if ((${#myfiles[@]})); then
676 python_mod_compile "${myfiles[@]}" 747 python_mod_compile "${myfiles[@]}"
677 fi 748 fi
678 749
679 eend $? 750 eend "${return_code}"
680 fi 751 fi
681} 752}
682 753
683# @FUNCTION: python_mod_cleanup 754# @FUNCTION: python_mod_cleanup
684# @USAGE: [directory] 755# @USAGE: [directory]
707 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 778 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
708 elif [[ "$1" =~ ^/ ]]; then 779 elif [[ "$1" =~ ^/ ]]; then
709 SEARCH_PATH+=("${root}/${1#/}") 780 SEARCH_PATH+=("${root}/${1#/}")
710 else 781 else
711 for PYTHON_ABI in ${PYTHON_ABIS}; do 782 for PYTHON_ABI in ${PYTHON_ABIS}; do
712 SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") 783 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
713 done 784 done
714 fi 785 fi
715 shift 786 shift
716 done 787 done
717 else 788 else
721 else 792 else
722 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) 793 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
723 fi 794 fi
724 795
725 for path in "${SEARCH_PATH[@]}"; do 796 for path in "${SEARCH_PATH[@]}"; do
797 [[ ! -d "${path}" ]] && continue
726 einfo "Cleaning orphaned Python bytecode from ${path} .." 798 einfo "Cleaning orphaned Python bytecode from ${path} .."
727 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do 799 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
728 src_py="${REPLY%[co]}" 800 src_py="${REPLY%[co]}"
729 [[ -f "${src_py}" ]] && continue 801 [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue
730 einfo "Purging ${src_py}[co]" 802 einfo "Purging ${src_py}[co]"
731 rm -f "${src_py}"[co] 803 rm -f "${src_py}"[co]
732 done 804 done
733 805
734 # Attempt to remove directories that may be empty. 806 # Attempt to remove directories that may be empty.
735 find "${path}" -type d | sort -r | while read -r dir; do 807 find "${path}" -type d | sort -r | while read -r dir; do
736 rmdir "${dir}" 2>/dev/null 808 rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}"
737 done 809 done
738 done 810 done
739} 811}

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

  ViewVC Help
Powered by ViewVC 1.1.20