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

Diff of /eclass/python.eclass

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

Revision 1.60 Revision 1.70
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.60 2009/08/05 18:31:30 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.70 2009/09/05 17:30:08 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 [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then 122 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
117 die "/usr/bin/python isn't valid program" 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 [[ "$(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 131 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" 132 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
133
134 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
135 if [[ -z "${USE_PYTHON}" ]]; then
136 die "USE_PYTHON variable is empty"
137 fi
138
127 for ABI in ${USE_PYTHON}; do 139 for ABI in ${USE_PYTHON}; do
128 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 140 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
129 ewarn "Ignoring unsupported Python ABI '${ABI}'" 141 die "USE_PYTHON variable contains invalid value '${ABI}'"
130 continue
131 fi 142 fi
132 support_ABI="1" 143 support_ABI="1"
144 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
145 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
146 support_ABI="0"
147 break
148 fi
149 done
150 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
151 done
152 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
153
154 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
155 die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}"
156 fi
157 else
158 local restricted_ABI
159 python_version
160
133 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 161 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
134 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 162 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then
135 support_ABI="0" 163 die "Active Python version isn't supported by ${CATEGORY}/${PF}"
136 break
137 fi 164 fi
138 done 165 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}" 166 export PYTHON_ABIS="${PYVER}"
147 fi 167 fi
168 fi
169
170 # Ensure that EPYTHON variable is respected.
171 local PYTHON_ABI
172 for PYTHON_ABI in ${PYTHON_ABIS}; do
173 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
174 die "'python' doesn't respect EPYTHON variable"
175 fi
176 done
148} 177}
149 178
150# @FUNCTION: python_copy_sources 179# @FUNCTION: python_copy_sources
151# @USAGE: [directory] 180# @USAGE: [directory]
152# @DESCRIPTION: 181# @DESCRIPTION:
176# @DESCRIPTION: 205# @DESCRIPTION:
177# Create build directory symlink. 206# Create build directory symlink.
178python_set_build_dir_symlink() { 207python_set_build_dir_symlink() {
179 local dir="$1" 208 local dir="$1"
180 209
181 [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" 210 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
182 [[ -z "${dir}" ]] && dir="build" 211 [[ -z "${dir}" ]] && dir="build"
183 212
184 # Don't delete preexistent directories. 213 # Don't delete preexistent directories.
185 rm -f "${dir}" || die "Deletion of '${dir}' failed" 214 rm -f "${dir}" || die "Deletion of '${dir}' failed"
186 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 215 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
215 ;; 244 ;;
216 -s|--separate-build-dirs) 245 -s|--separate-build-dirs)
217 separate_build_dirs="1" 246 separate_build_dirs="1"
218 ;; 247 ;;
219 -*) 248 -*)
220 die "${FUNCNAME}(): Unrecognized option $1" 249 die "${FUNCNAME}(): Unrecognized option '$1'"
221 ;; 250 ;;
222 *) 251 *)
223 break 252 break
224 ;; 253 ;;
225 esac 254 esac
230 if [[ "$#" -eq "0" ]]; then 259 if [[ "$#" -eq "0" ]]; then
231 die "${FUNCNAME}(): Missing function name" 260 die "${FUNCNAME}(): Missing function name"
232 fi 261 fi
233 function="$1" 262 function="$1"
234 shift 263 shift
264
265 if [[ -z "$(type -t "${function}")" ]]; then
266 die "${FUNCNAME}(): '${function}' function isn't defined"
267 fi
235 else 268 else
236 if [[ "$#" -ne "0" ]]; then 269 if [[ "$#" -ne "0" ]]; then
237 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" 270 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
238 fi 271 fi
239 if has "${EAPI:-0}" 0 1; then 272 if has "${EAPI:-0}" 0 1; then
240 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" 273 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
241 fi 274 fi
242 275
243 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 276 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
277 if has "${EAPI}" 2; then
244 python_default_function() { 278 python_default_function() {
245 econf 279 econf
246 } 280 }
281 else
282 python_default_function() {
283 nonfatal econf
284 }
285 fi
247 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 286 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
248 python_default_function() { 287 python_default_function() {
249 emake 288 emake
250 } 289 }
251 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 290 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
301 else 340 else
302 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 341 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
303 fi 342 fi
304 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 343 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
305 fi 344 fi
345
306 if [[ "${separate_build_dirs}" == "1" ]]; then 346 if [[ "${separate_build_dirs}" == "1" ]]; then
307 export BUILDDIR="${S}-${PYTHON_ABI}" 347 export BUILDDIR="${S}-${PYTHON_ABI}"
308 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 348 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
309 else 349 else
310 export BUILDDIR="${S}" 350 export BUILDDIR="${S}"
311 fi 351 fi
352
353 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
354 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
355 else
312 if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then 356 EPYTHON="$(PYTHON)" "${function}" "$@"
357 fi
358
359 if [[ "$?" != "0" ]]; then
313 if [[ -n "${failure_message_template}" ]]; then 360 if [[ -n "${failure_message_template}" ]]; then
314 failure_message="$(eval echo -n "${failure_message_template}")" 361 failure_message="$(eval echo -n "${failure_message_template}")"
315 else 362 else
316 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 363 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
317 fi 364 fi
318 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 365
319 local ABI enabled_PYTHON_ABIS 366 if [[ "${nonfatal}" == "1" ]]; then
320 for ABI in ${PYTHON_ABIS}; do
321 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
322 done
323 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
324 if [[ "${quiet}" == "0" ]]; then 367 if [[ "${quiet}" == "0" ]]; then
325 ewarn "${RED}${failure_message}${NORMAL}" 368 ewarn "${RED}${failure_message}${NORMAL}"
326 fi 369 fi
370 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
371 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
372 local ABI enabled_PYTHON_ABIS=
373 for ABI in ${PYTHON_ABIS}; do
374 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
375 done
376 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
377 fi
378 if [[ "${quiet}" == "0" ]]; then
379 ewarn "${RED}${failure_message}${NORMAL}"
380 fi
381 if [[ -z "${PYTHON_ABIS}" ]]; then
382 die "${function}() function failed with all enabled versions of Python"
383 fi
327 else 384 else
328 die "${failure_message}" 385 die "${failure_message}"
329 fi 386 fi
330 fi 387 fi
388
331 if [[ "${separate_build_dirs}" == "1" ]]; then 389 if [[ "${separate_build_dirs}" == "1" ]]; then
332 popd > /dev/null || die "popd failed" 390 popd > /dev/null || die "popd failed"
333 fi 391 fi
334 unset BUILDDIR 392 unset BUILDDIR
335 done 393 done
358 416
359# @FUNCTION: python_pkg_setup 417# @FUNCTION: python_pkg_setup
360# @DESCRIPTION: 418# @DESCRIPTION:
361# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 419# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
362# are respected. Only exported if one of those variables is set. 420# are respected. Only exported if one of those variables is set.
363if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 421if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
364 python_pkg_setup_fail() { 422 python_pkg_setup_fail() {
365 eerror "${1}" 423 eerror "${1}"
366 die "${1}" 424 die "${1}"
367 } 425 }
368 426
410 fi 468 fi
411 DEPEND="${PYTHON_USE_WITH_ATOM}" 469 DEPEND="${PYTHON_USE_WITH_ATOM}"
412 RDEPEND="${PYTHON_USE_WITH_ATOM}" 470 RDEPEND="${PYTHON_USE_WITH_ATOM}"
413fi 471fi
414 472
473# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
474# @DESCRIPTION:
475# Set this to define default functions for the following ebuild phases:
476# src_prepare, src_configure, src_compile, src_test, src_install.
477if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
478 python_src_prepare() {
479 python_copy_sources
480 }
481
482 for python_default_function in src_configure src_compile src_test src_install; do
483 eval "python_${python_default_function}() { python_execute_function -d -s; }"
484 done
485 unset python_default_function
486
487 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
488fi
489
415# @FUNCTION: python_disable_pyc 490# @FUNCTION: python_disable_pyc
416# @DESCRIPTION: 491# @DESCRIPTION:
417# Tells python not to automatically recompile modules to .pyc/.pyo 492# Tell Python not to automatically recompile modules to .pyc/.pyo
418# even if the timestamps/version stamps don't match. This is done 493# even if the timestamps/version stamps don't match. This is done
419# to protect sandbox. 494# to protect sandbox.
420#
421# note: supported by >=dev-lang/python-2.2.3-r3 only.
422#
423python_disable_pyc() { 495python_disable_pyc() {
424 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above 496 export PYTHONDONTWRITEBYTECODE="1"
425 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
426} 497}
427 498
428# @FUNCTION: python_enable_pyc 499# @FUNCTION: python_enable_pyc
429# @DESCRIPTION: 500# @DESCRIPTION:
430# Tells python to automatically recompile modules to .pyc/.pyo if the 501# Tell Python to automatically recompile modules to .pyc/.pyo if the
431# timestamps/version stamps change 502# timestamps/version stamps have changed.
432python_enable_pyc() { 503python_enable_pyc() {
433 unset PYTHONDONTWRITEBYTECODE 504 unset PYTHONDONTWRITEBYTECODE
434 unset PYTHON_DONTCOMPILE
435} 505}
436 506
437python_disable_pyc 507python_disable_pyc
438 508
439# @FUNCTION: python_need_rebuild 509# @FUNCTION: python_need_rebuild
471# @FUNCTION: python_get_sitedir 541# @FUNCTION: python_get_sitedir
472# @DESCRIPTION: 542# @DESCRIPTION:
473# Run without arguments, returns the Python site-packages directory. 543# Run without arguments, returns the Python site-packages directory.
474python_get_sitedir() { 544python_get_sitedir() {
475 echo "$(python_get_libdir)/site-packages" 545 echo "$(python_get_libdir)/site-packages"
476}
477
478# @FUNCTION: python_makesym
479# @DESCRIPTION:
480# Run without arguments, it will create the /usr/bin/python symlinks
481# to the latest installed version
482python_makesym() {
483 alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]"
484 alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]"
485} 546}
486 547
487# @FUNCTION: python_tkinter_exists 548# @FUNCTION: python_tkinter_exists
488# @DESCRIPTION: 549# @DESCRIPTION:
489# Run without arguments, checks if python was compiled with Tkinter 550# Run without arguments, checks if python was compiled with Tkinter
550 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 611 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
551 done 612 done
552 613
553 if ((${#myfiles[@]})); then 614 if ((${#myfiles[@]})); then
554 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 615 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}"
555 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 616 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null
556 else 617 else
557 ewarn "No files to compile!" 618 ewarn "No files to compile!"
558 fi 619 fi
559} 620}
560 621
608 else 669 else
609 ewarn "'${root}/$1' doesn't exist!" 670 ewarn "'${root}/$1' doesn't exist!"
610 fi 671 fi
611 else 672 else
612 for PYTHON_ABI in ${PYTHON_ABIS}; do 673 for PYTHON_ABI in ${PYTHON_ABIS}; do
613 if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then 674 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
614 site_packages_dirs+=("$1") 675 site_packages_dirs+=("$1")
615 break 676 break
616 elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then 677 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
617 site_packages_files+=("$1") 678 site_packages_files+=("$1")
618 break 679 break
619 elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then 680 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
620 ewarn "'$1' is not a file or a directory!" 681 ewarn "'$1' is not a file or a directory!"
621 else 682 else
622 ewarn "'$1' doesn't exist!" 683 ewarn "'$1' doesn't exist!"
623 fi 684 fi
624 done 685 done
635 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 696 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
636 return_code="0" 697 return_code="0"
637 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 698 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
638 if ((${#site_packages_dirs[@]})); then 699 if ((${#site_packages_dirs[@]})); then
639 for dir in "${site_packages_dirs[@]}"; do 700 for dir in "${site_packages_dirs[@]}"; do
640 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 701 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
641 done 702 done
642 "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 703 "$(PYTHON)" "${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" 704 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
644 fi 705 fi
645 if ((${#site_packages_files[@]})); then 706 if ((${#site_packages_files[@]})); then
646 for file in "${site_packages_files[@]}"; do 707 for file in "${site_packages_files[@]}"; do
647 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 708 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
648 done 709 done
649 "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 710 "$(PYTHON)" "${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" 711 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
651 fi 712 fi
652 eend "${return_code}" 713 eend "${return_code}"
653 fi 714 fi
654 unset site_packages_absolute_dirs site_packages_absolute_files 715 unset site_packages_absolute_dirs site_packages_absolute_files
655 done 716 done
659 720
660 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 721 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
661 return_code="0" 722 return_code="0"
662 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." 723 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
663 if ((${#other_dirs[@]})); then 724 if ((${#other_dirs[@]})); then
664 python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 725 python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
665 python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 726 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
666 fi 727 fi
667 if ((${#other_files[@]})); then 728 if ((${#other_files[@]})); then
668 python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 729 python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
669 python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 730 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
670 fi 731 fi
671 eend "${return_code}" 732 eend "${return_code}"
672 fi 733 fi
673 else 734 else
674 local myroot mydirs=() myfiles=() myopts=() 735 local myroot mydirs=() myfiles=() myopts=() return_code="0"
675 736
676 # strip trailing slash 737 # strip trailing slash
677 myroot="${ROOT%/}" 738 myroot="${ROOT%/}"
678 739
679 # respect ROOT and options passed to compileall.py 740 # respect ROOT and options passed to compileall.py
717 778
718 ebegin "Byte compiling python modules for python-${PYVER} .." 779 ebegin "Byte compiling python modules for python-${PYVER} .."
719 if ((${#mydirs[@]})); then 780 if ((${#mydirs[@]})); then
720 python${PYVER} \ 781 python${PYVER} \
721 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 782 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
722 "${myopts[@]}" "${mydirs[@]}" 783 "${myopts[@]}" "${mydirs[@]}" || return_code="1"
723 python${PYVER} -O \ 784 python${PYVER} -O \
724 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 785 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
725 "${myopts[@]}" "${mydirs[@]}" 786 "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
726 fi 787 fi
727 788
728 if ((${#myfiles[@]})); then 789 if ((${#myfiles[@]})); then
729 python_mod_compile "${myfiles[@]}" 790 python_mod_compile "${myfiles[@]}"
730 fi 791 fi
731 792
732 eend $? 793 eend "${return_code}"
733 fi 794 fi
734} 795}
735 796
736# @FUNCTION: python_mod_cleanup 797# @FUNCTION: python_mod_cleanup
737# @USAGE: [directory] 798# @USAGE: [directory]
760 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 821 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
761 elif [[ "$1" =~ ^/ ]]; then 822 elif [[ "$1" =~ ^/ ]]; then
762 SEARCH_PATH+=("${root}/${1#/}") 823 SEARCH_PATH+=("${root}/${1#/}")
763 else 824 else
764 for PYTHON_ABI in ${PYTHON_ABIS}; do 825 for PYTHON_ABI in ${PYTHON_ABIS}; do
765 SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") 826 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
766 done 827 done
767 fi 828 fi
768 shift 829 shift
769 done 830 done
770 else 831 else
774 else 835 else
775 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) 836 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
776 fi 837 fi
777 838
778 for path in "${SEARCH_PATH[@]}"; do 839 for path in "${SEARCH_PATH[@]}"; do
840 [[ ! -d "${path}" ]] && continue
779 einfo "Cleaning orphaned Python bytecode from ${path} .." 841 einfo "Cleaning orphaned Python bytecode from ${path} .."
780 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do 842 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
781 src_py="${REPLY%[co]}" 843 src_py="${REPLY%[co]}"
782 [[ -f "${src_py}" ]] && continue 844 [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue
783 einfo "Purging ${src_py}[co]" 845 einfo "Purging ${src_py}[co]"
784 rm -f "${src_py}"[co] 846 rm -f "${src_py}"[co]
785 done 847 done
786 848
787 # Attempt to remove directories that may be empty. 849 # Attempt to remove directories that may be empty.
788 find "${path}" -type d | sort -r | while read -r dir; do 850 find "${path}" -type d | sort -r | while read -r dir; do
789 rmdir "${dir}" 2>/dev/null 851 rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}"
790 done 852 done
791 done 853 done
792} 854}

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

  ViewVC Help
Powered by ViewVC 1.1.20