/[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.62
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.62 2009/08/13 16:57:01 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#
239 if has "${EAPI:-0}" 0 1; then 239 if has "${EAPI:-0}" 0 1; then
240 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" 240 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI"
241 fi 241 fi
242 242
243 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 243 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
244 if has "${EAPI}" 2; then
244 python_default_function() { 245 python_default_function() {
245 econf 246 econf
246 } 247 }
248 else
249 python_default_function() {
250 nonfatal econf
251 }
252 fi
247 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 253 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
248 python_default_function() { 254 python_default_function() {
249 emake 255 emake
250 } 256 }
251 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 257 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
550 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 556 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
551 done 557 done
552 558
553 if ((${#myfiles[@]})); then 559 if ((${#myfiles[@]})); then
554 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 560 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[@]}" 561 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 2> /dev/null
556 else 562 else
557 ewarn "No files to compile!" 563 ewarn "No files to compile!"
558 fi 564 fi
559} 565}
560 566
608 else 614 else
609 ewarn "'${root}/$1' doesn't exist!" 615 ewarn "'${root}/$1' doesn't exist!"
610 fi 616 fi
611 else 617 else
612 for PYTHON_ABI in ${PYTHON_ABIS}; do 618 for PYTHON_ABI in ${PYTHON_ABIS}; do
613 if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then 619 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
614 site_packages_dirs+=("$1") 620 site_packages_dirs+=("$1")
615 break 621 break
616 elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then 622 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
617 site_packages_files+=("$1") 623 site_packages_files+=("$1")
618 break 624 break
619 elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then 625 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
620 ewarn "'$1' is not a file or a directory!" 626 ewarn "'$1' is not a file or a directory!"
621 else 627 else
622 ewarn "'$1' doesn't exist!" 628 ewarn "'$1' doesn't exist!"
623 fi 629 fi
624 done 630 done
635 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 641 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
636 return_code="0" 642 return_code="0"
637 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 643 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
638 if ((${#site_packages_dirs[@]})); then 644 if ((${#site_packages_dirs[@]})); then
639 for dir in "${site_packages_dirs[@]}"; do 645 for dir in "${site_packages_dirs[@]}"; do
640 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 646 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
641 done 647 done
642 "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 648 "$(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" 649 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" 2> /dev/null || return_code="1"
644 fi 650 fi
645 if ((${#site_packages_files[@]})); then 651 if ((${#site_packages_files[@]})); then
646 for file in "${site_packages_files[@]}"; do 652 for file in "${site_packages_files[@]}"; do
647 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 653 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
648 done 654 done
649 "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 655 "$(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" 656 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" 2> /dev/null || return_code="1"
651 fi 657 fi
652 eend "${return_code}" 658 eend "${return_code}"
653 fi 659 fi
654 unset site_packages_absolute_dirs site_packages_absolute_files 660 unset site_packages_absolute_dirs site_packages_absolute_files
655 done 661 done
659 665
660 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 666 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
661 return_code="0" 667 return_code="0"
662 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." 668 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
663 if ((${#other_dirs[@]})); then 669 if ((${#other_dirs[@]})); then
664 python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 670 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" 671 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" 2> /dev/null || return_code="1"
666 fi 672 fi
667 if ((${#other_files[@]})); then 673 if ((${#other_files[@]})); then
668 python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 674 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" 675 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" 2> /dev/null || return_code="1"
670 fi 676 fi
671 eend "${return_code}" 677 eend "${return_code}"
672 fi 678 fi
673 else 679 else
674 local myroot mydirs=() myfiles=() myopts=() 680 local myroot mydirs=() myfiles=() myopts=()
720 python${PYVER} \ 726 python${PYVER} \
721 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 727 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
722 "${myopts[@]}" "${mydirs[@]}" 728 "${myopts[@]}" "${mydirs[@]}"
723 python${PYVER} -O \ 729 python${PYVER} -O \
724 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 730 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
725 "${myopts[@]}" "${mydirs[@]}" 731 "${myopts[@]}" "${mydirs[@]}" 2> /dev/null
726 fi 732 fi
727 733
728 if ((${#myfiles[@]})); then 734 if ((${#myfiles[@]})); then
729 python_mod_compile "${myfiles[@]}" 735 python_mod_compile "${myfiles[@]}"
730 fi 736 fi
760 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 766 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
761 elif [[ "$1" =~ ^/ ]]; then 767 elif [[ "$1" =~ ^/ ]]; then
762 SEARCH_PATH+=("${root}/${1#/}") 768 SEARCH_PATH+=("${root}/${1#/}")
763 else 769 else
764 for PYTHON_ABI in ${PYTHON_ABIS}; do 770 for PYTHON_ABI in ${PYTHON_ABIS}; do
765 SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") 771 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
766 done 772 done
767 fi 773 fi
768 shift 774 shift
769 done 775 done
770 else 776 else
774 else 780 else
775 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) 781 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
776 fi 782 fi
777 783
778 for path in "${SEARCH_PATH[@]}"; do 784 for path in "${SEARCH_PATH[@]}"; do
785 [[ ! -d "${path}" ]] && continue
779 einfo "Cleaning orphaned Python bytecode from ${path} .." 786 einfo "Cleaning orphaned Python bytecode from ${path} .."
780 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do 787 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
781 src_py="${REPLY%[co]}" 788 src_py="${REPLY%[co]}"
782 [[ -f "${src_py}" ]] && continue 789 [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue
783 einfo "Purging ${src_py}[co]" 790 einfo "Purging ${src_py}[co]"
784 rm -f "${src_py}"[co] 791 rm -f "${src_py}"[co]
785 done 792 done
786 793
787 # Attempt to remove directories that may be empty. 794 # Attempt to remove directories that may be empty.
788 find "${path}" -type d | sort -r | while read -r dir; do 795 find "${path}" -type d | sort -r | while read -r dir; do
789 rmdir "${dir}" 2>/dev/null 796 rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}"
790 done 797 done
791 done 798 done
792} 799}

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

  ViewVC Help
Powered by ViewVC 1.1.20