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

Diff of /eclass/python.eclass

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

Revision 1.116 Revision 1.118
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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.116 2011/07/04 11:27:53 djc Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.118 2011/07/08 07:37:49 djc Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
706 fi 706 fi
707 707
708 _python_initial_sanity_checks 708 _python_initial_sanity_checks
709 709
710 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 710 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
711 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS 711 local PYTHON_ABI
712
713 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
714 712
715 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 713 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
716 local cpython_enabled="0" 714 local cpython_enabled="0"
717 715
718 if [[ -z "${USE_PYTHON}" ]]; then 716 if [[ -z "${USE_PYTHON}" ]]; then
726 724
727 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then 725 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
728 cpython_enabled="1" 726 cpython_enabled="1"
729 fi 727 fi
730 728
731 support_ABI="1"
732 while read restricted_ABI; do
733 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then 729 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
734 support_ABI="0" 730 export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
735 break
736 fi 731 fi
737 done <<< "${restricted_ABIs}"
738 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
739 done 732 done
740 733
741 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 734 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
742 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 735 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
743 fi 736 fi
759 die "'${EPREFIX}/usr/bin/python2' is not valid symlink" 752 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
760 fi 753 fi
761 754
762 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 755 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
763 756
757 support_python_major_version="0"
764 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do 758 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
759 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
765 support_python_major_version="1" 760 support_python_major_version="1"
766 while read restricted_ABI; do 761 break
767 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
768 support_python_major_version="0"
769 fi 762 fi
770 done <<< "${restricted_ABIs}"
771 [[ "${support_python_major_version}" == "1" ]] && break
772 done 763 done
773 if [[ "${support_python_major_version}" == "1" ]]; then 764 if [[ "${support_python_major_version}" == "1" ]]; then
774 while read restricted_ABI; do
775 if _python_check_python_abi_matching "${python2_version}" "${restricted_ABI}"; then 765 if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
776 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}" 766 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
777 fi 767 fi
778 done <<< "${restricted_ABIs}"
779 else 768 else
780 python2_version="" 769 python2_version=""
781 fi 770 fi
782 fi 771 fi
783 772
786 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 775 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
787 fi 776 fi
788 777
789 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 778 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
790 779
780 support_python_major_version="0"
791 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do 781 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
782 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
792 support_python_major_version="1" 783 support_python_major_version="1"
793 while read restricted_ABI; do 784 break
794 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
795 support_python_major_version="0"
796 fi 785 fi
797 done <<< "${restricted_ABIs}"
798 [[ "${support_python_major_version}" == "1" ]] && break
799 done 786 done
800 if [[ "${support_python_major_version}" == "1" ]]; then 787 if [[ "${support_python_major_version}" == "1" ]]; then
801 while read restricted_ABI; do
802 if _python_check_python_abi_matching "${python3_version}" "${restricted_ABI}"; then 788 if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
803 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" 789 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
804 fi 790 fi
805 done <<< "${restricted_ABIs}"
806 else 791 else
807 python3_version="" 792 python3_version=""
808 fi 793 fi
809 fi 794 fi
810 795
2152 die "${FUNCNAME}(): Jython does not have shared library" 2137 die "${FUNCNAME}(): Jython does not have shared library"
2153 fi 2138 fi
2154} 2139}
2155 2140
2156# @FUNCTION: python_get_version 2141# @FUNCTION: python_get_version
2157# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] 2142# @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro]
2158# @DESCRIPTION: 2143# @DESCRIPTION:
2159# Print Python version. 2144# Print Python version.
2160# --full, --major, --minor and --micro options cannot be specified simultaneously. 2145# --full, --major, --minor and --micro options cannot be specified simultaneously.
2161# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 2146# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
2147# If --language option is specified, then Python language version is printed.
2148# --language and --full options cannot be specified simultaneously.
2149# --language and --micro options cannot be specified simultaneously.
2162# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 2150# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2163python_get_version() { 2151python_get_version() {
2164 _python_check_python_pkg_setup_execution 2152 _python_check_python_pkg_setup_execution
2165 2153
2166 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 2154 local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command
2167 2155
2168 while (($#)); do 2156 while (($#)); do
2169 case "$1" in 2157 case "$1" in
2170 -f|--final-ABI) 2158 -f|--final-ABI)
2171 final_ABI="1" 2159 final_ABI="1"
2172 ;; 2160 ;;
2161 -l|--language)
2162 language="1"
2163 ;;
2173 --full) 2164 --full)
2174 full="1" 2165 full="1"
2175 ;; 2166 ;;
2176 --major) 2167 --major)
2177 major="1" 2168 major="1"
2189 die "${FUNCNAME}(): Invalid usage" 2180 die "${FUNCNAME}(): Invalid usage"
2190 ;; 2181 ;;
2191 esac 2182 esac
2192 shift 2183 shift
2193 done 2184 done
2194
2195 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2196 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2197 fi
2198
2199 if [[ "${full}" == "1" ]]; then
2200 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
2201 elif [[ "${major}" == "1" ]]; then
2202 python_command="from sys import version_info; print(version_info[0])"
2203 elif [[ "${minor}" == "1" ]]; then
2204 python_command="from sys import version_info; print(version_info[1])"
2205 elif [[ "${micro}" == "1" ]]; then
2206 python_command="from sys import version_info; print(version_info[2])"
2207 else
2208 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2209 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2210 echo "${PYTHON_ABI}"
2211 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2212 echo "${PYTHON_ABI%-jython}"
2213 fi
2214 return
2215 fi
2216 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2217 fi
2218 2185
2219 if [[ "${final_ABI}" == "1" ]]; then 2186 if [[ "${final_ABI}" == "1" ]]; then
2220 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2187 if ! _python_package_supporting_installation_for_multiple_python_abis; then
2221 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 2188 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2222 fi 2189 fi
2223 "$(PYTHON -f)" -c "${python_command}"
2224 else 2190 else
2225 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then 2191 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
2226 die "${FUNCNAME}() should be used in ABI-specific local scope" 2192 die "${FUNCNAME}() should be used in ABI-specific local scope"
2227 fi 2193 fi
2194 fi
2195
2196 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2197 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2198 fi
2199
2200 if [[ "${language}" == "1" ]]; then
2201 if [[ "${final_ABI}" == "1" ]]; then
2202 PYTHON_ABI="$(PYTHON -f --ABI)"
2203 elif [[ -z "${PYTHON_ABI}" ]]; then
2204 PYTHON_ABI="$(PYTHON --ABI)"
2205 fi
2206 language_version="${PYTHON_ABI%%-*}"
2207 if [[ "${full}" == "1" ]]; then
2208 die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously"
2209 elif [[ "${major}" == "1" ]]; then
2210 echo "${language_version%.*}"
2211 elif [[ "${minor}" == "1" ]]; then
2212 echo "${language_version#*.}"
2213 elif [[ "${micro}" == "1" ]]; then
2214 die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously"
2215 else
2216 echo "${language_version}"
2217 fi
2218 else
2219 if [[ "${full}" == "1" ]]; then
2220 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
2221 elif [[ "${major}" == "1" ]]; then
2222 python_command="from sys import version_info; print(version_info[0])"
2223 elif [[ "${minor}" == "1" ]]; then
2224 python_command="from sys import version_info; print(version_info[1])"
2225 elif [[ "${micro}" == "1" ]]; then
2226 python_command="from sys import version_info; print(version_info[2])"
2227 else
2228 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2229 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2230 echo "${PYTHON_ABI}"
2231 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2232 echo "${PYTHON_ABI%-jython}"
2233 fi
2234 return
2235 fi
2236 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2237 fi
2238
2239 if [[ "${final_ABI}" == "1" ]]; then
2240 "$(PYTHON -f)" -c "${python_command}"
2241 else
2228 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2242 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
2243 fi
2229 fi 2244 fi
2230} 2245}
2231 2246
2232# ================================================================================================ 2247# ================================================================================================
2233# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 2248# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================

Legend:
Removed from v.1.116  
changed lines
  Added in v.1.118

  ViewVC Help
Powered by ViewVC 1.1.20