/[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.125
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.125 2011/07/08 07:47:30 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
14if ! has "${EAPI:-0}" 0 1 2 3; then 14if ! has "${EAPI:-0}" 0 1 2 3; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.0 3.1 3.2 3.3) 19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3)
20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]}) 21_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]})
22 22
23# ================================================================================================ 23# ================================================================================================
24# ===================================== HANDLING OF METADATA ===================================== 24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================ 25# ================================================================================================
26
27_PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\.|-|\*|\[|\])+"
26 28
27_python_check_python_abi_matching() { 29_python_check_python_abi_matching() {
28 local pattern patterns patterns_list="0" PYTHON_ABI 30 local pattern patterns patterns_list="0" PYTHON_ABI
29 31
30 while (($#)); do 32 while (($#)); do
76 return 0 78 return 0
77 fi 79 fi
78 done <<< "${patterns}" 80 done <<< "${patterns}"
79 81
80 return 1 82 return 1
83 fi
84}
85
86_python_package_supporting_installation_for_multiple_python_abis() {
87 if has "${EAPI:-0}" 0 1 2 3 4; then
88 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
89 return 0
90 else
91 return 1
92 fi
93 else
94 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
81 fi 95 fi
82} 96}
83 97
84# @ECLASS-VARIABLE: PYTHON_DEPEND 98# @ECLASS-VARIABLE: PYTHON_DEPEND
85# @DESCRIPTION: 99# @DESCRIPTION:
283 else 297 else
284 return 1 298 return 1
285 fi 299 fi
286} 300}
287 301
288_python_package_supporting_installation_for_multiple_python_abis() {
289 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
290 die "${FUNCNAME}() cannot be used in global scope"
291 fi
292
293 if has "${EAPI:-0}" 0 1 2 3 4; then
294 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
295 return 0
296 else
297 return 1
298 fi
299 else
300 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
301 fi
302}
303
304_python_abi-specific_local_scope() { 302_python_abi-specific_local_scope() {
305 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] 303 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
306} 304}
307 305
308_python_initialize_prefix_variables() { 306_python_initialize_prefix_variables() {
706 fi 704 fi
707 705
708 _python_initial_sanity_checks 706 _python_initial_sanity_checks
709 707
710 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 708 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 709 local PYTHON_ABI
712
713 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
714 710
715 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 711 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
716 local cpython_enabled="0" 712 local cpython_enabled="0"
717 713
718 if [[ -z "${USE_PYTHON}" ]]; then 714 if [[ -z "${USE_PYTHON}" ]]; then
726 722
727 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then 723 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
728 cpython_enabled="1" 724 cpython_enabled="1"
729 fi 725 fi
730 726
731 support_ABI="1"
732 while read restricted_ABI; do
733 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then 727 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
734 support_ABI="0" 728 export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
735 break
736 fi 729 fi
737 done <<< "${restricted_ABIs}"
738 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
739 done 730 done
740 731
741 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 732 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
742 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 733 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
743 fi 734 fi
759 die "'${EPREFIX}/usr/bin/python2' is not valid symlink" 750 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
760 fi 751 fi
761 752
762 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 753 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
763 754
755 support_python_major_version="0"
764 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do 756 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
757 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
765 support_python_major_version="1" 758 support_python_major_version="1"
766 while read restricted_ABI; do 759 break
767 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
768 support_python_major_version="0"
769 fi 760 fi
770 done <<< "${restricted_ABIs}"
771 [[ "${support_python_major_version}" == "1" ]] && break
772 done 761 done
773 if [[ "${support_python_major_version}" == "1" ]]; then 762 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 763 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}" 764 die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
777 fi 765 fi
778 done <<< "${restricted_ABIs}"
779 else 766 else
780 python2_version="" 767 python2_version=""
781 fi 768 fi
782 fi 769 fi
783 770
786 die "'${EPREFIX}/usr/bin/python3' is not valid symlink" 773 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
787 fi 774 fi
788 775
789 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 776 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
790 777
778 support_python_major_version="0"
791 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do 779 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
780 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
792 support_python_major_version="1" 781 support_python_major_version="1"
793 while read restricted_ABI; do 782 break
794 if _python_check_python_abi_matching "${PYTHON_ABI}" "${restricted_ABI}"; then
795 support_python_major_version="0"
796 fi 783 fi
797 done <<< "${restricted_ABIs}"
798 [[ "${support_python_major_version}" == "1" ]] && break
799 done 784 done
800 if [[ "${support_python_major_version}" == "1" ]]; then 785 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 786 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}" 787 die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
804 fi 788 fi
805 done <<< "${restricted_ABIs}"
806 else 789 else
807 python3_version="" 790 python3_version=""
808 fi 791 fi
809 fi 792 fi
810 793
835 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"" 818 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
836 for prefix in PYTHON_USER_ PYTHON_; do 819 for prefix in PYTHON_USER_ PYTHON_; do
837 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then 820 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
838 eval "array=(\"\${${prefix}${variable}[@]}\")" 821 eval "array=(\"\${${prefix}${variable}[@]}\")"
839 for element in "${array[@]}"; do 822 for element in "${array[@]}"; do
840 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then 823 if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
841 pattern="${element%% *}" 824 pattern="${element%% *}"
842 element="${element#* }" 825 element="${element#* }"
843 operator="${element%% *}" 826 operator="${element%% *}"
844 flags="${element#* }" 827 flags="${element#* }"
845 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then 828 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
1015 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 998 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
1016 fi 999 fi
1017 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1000 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1018 if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then 1001 if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
1019 if [[ "${quiet}" == "0" ]]; then 1002 if [[ "${quiet}" == "0" ]]; then
1020 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version) skipped${_NORMAL}" 1003 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}"
1021 fi 1004 fi
1022 continue 1005 continue
1023 fi 1006 fi
1024 1007
1025 _python_prepare_flags 1008 _python_prepare_flags
1026 1009
1027 if [[ "${quiet}" == "0" ]]; then 1010 if [[ "${quiet}" == "0" ]]; then
1028 if [[ -n "${action_message_template}" ]]; then 1011 if [[ -n "${action_message_template}" ]]; then
1029 eval "action_message=\"${action_message_template}\"" 1012 eval "action_message=\"${action_message_template}\""
1030 else 1013 else
1031 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 1014 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)..."
1032 fi 1015 fi
1033 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 1016 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
1034 fi 1017 fi
1035 1018
1036 if [[ "${separate_build_dirs}" == "1" ]]; then 1019 if [[ "${separate_build_dirs}" == "1" ]]; then
1060 1043
1061 if [[ "${return_code}" -ne 0 ]]; then 1044 if [[ "${return_code}" -ne 0 ]]; then
1062 if [[ -n "${failure_message_template}" ]]; then 1045 if [[ -n "${failure_message_template}" ]]; then
1063 eval "failure_message=\"${failure_message_template}\"" 1046 eval "failure_message=\"${failure_message_template}\""
1064 else 1047 else
1065 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 1048 failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function"
1066 fi 1049 fi
1067 1050
1068 if [[ "${nonfatal}" == "1" ]]; then 1051 if [[ "${nonfatal}" == "1" ]]; then
1069 if [[ "${quiet}" == "0" ]]; then 1052 if [[ "${quiet}" == "0" ]]; then
1070 ewarn "${failure_message}" 1053 ewarn "${failure_message}"
1267 cat << EOF >> "${file}" 1250 cat << EOF >> "${file}"
1268EPYTHON = os.environ.get("EPYTHON") 1251EPYTHON = os.environ.get("EPYTHON")
1269if EPYTHON: 1252if EPYTHON:
1270 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1253 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1271 if PYTHON_ABI is None: 1254 if PYTHON_ABI is None:
1272 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) 1255 sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], EPYTHON))
1273 sys.exit(1) 1256 sys.exit(1)
1274else: 1257else:
1275 try: 1258 try:
1259 environment = os.environ.copy()
1260 environment["ROOT"] = "/"
1276 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1261 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
1277 if eselect_process.wait() != 0: 1262 if eselect_process.wait() != 0:
1278 raise ValueError 1263 raise ValueError
1279 except (OSError, ValueError): 1264 except (OSError, ValueError):
1280 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1265 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1281 sys.exit(1) 1266 sys.exit(1)
1282 1267
1283 EPYTHON = eselect_process.stdout.read() 1268 EPYTHON = eselect_process.stdout.read()
1284 if not isinstance(EPYTHON, str): 1269 if not isinstance(EPYTHON, str):
1285 # Python 3 1270 # Python 3
1286 EPYTHON = EPYTHON.decode() 1271 EPYTHON = EPYTHON.decode()
1287 EPYTHON = EPYTHON.rstrip("\n") 1272 EPYTHON = EPYTHON.rstrip("\n")
1288 1273
1289 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1274 PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1290 if PYTHON_ABI is None: 1275 if PYTHON_ABI is None:
1291 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1276 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON))
1292 sys.exit(1) 1277 sys.exit(1)
1293 1278
1294wrapper_script_path = os.path.realpath(sys.argv[0]) 1279wrapper_script_path = os.path.realpath(sys.argv[0])
1295target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1280target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1296if not os.path.exists(target_executable_path): 1281if not os.path.exists(target_executable_path):
1297 sys.stderr.write("'%s' does not exist\n" % target_executable_path) 1282 sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path))
1298 sys.exit(1) 1283 sys.exit(1)
1299EOF 1284EOF
1300 if [[ "$?" != "0" ]]; then 1285 if [[ "$?" != "0" ]]; then
1301 die "${FUNCNAME}(): Generation of '$1' failed" 1286 die "${FUNCNAME}(): Generation of '$1' failed"
1302 fi 1287 fi
1303 else 1288 else
1304 cat << EOF >> "${file}" 1289 cat << EOF >> "${file}"
1305try: 1290try:
1291 environment = os.environ.copy()
1292 environment["ROOT"] = "/"
1306 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1293 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
1307 if eselect_process.wait() != 0: 1294 if eselect_process.wait() != 0:
1308 raise ValueError 1295 raise ValueError
1309except (OSError, ValueError): 1296except (OSError, ValueError):
1310 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1297 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1311 sys.exit(1) 1298 sys.exit(1)
1312 1299
1313EPYTHON = eselect_process.stdout.read() 1300EPYTHON = eselect_process.stdout.read()
1314if not isinstance(EPYTHON, str): 1301if not isinstance(EPYTHON, str):
1315 # Python 3 1302 # Python 3
1316 EPYTHON = EPYTHON.decode() 1303 EPYTHON = EPYTHON.decode()
1317EPYTHON = EPYTHON.rstrip("\n") 1304EPYTHON = EPYTHON.rstrip("\n")
1318 1305
1319PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1306PYTHON_ABI = get_PYTHON_ABI(EPYTHON)
1320if PYTHON_ABI is None: 1307if PYTHON_ABI is None:
1321 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) 1308 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON))
1322 sys.exit(1) 1309 sys.exit(1)
1323 1310
1324wrapper_script_path = os.path.realpath(sys.argv[0]) 1311wrapper_script_path = os.path.realpath(sys.argv[0])
1325for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: 1312for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1326 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1313 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1327 if os.path.exists(target_executable_path): 1314 if os.path.exists(target_executable_path):
1328 break 1315 break
1329else: 1316else:
1330 sys.stderr.write("No target script exists for '%s'\n" % wrapper_script_path) 1317 sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
1331 sys.exit(1) 1318 sys.exit(1)
1332EOF 1319EOF
1333 if [[ "$?" != "0" ]]; then 1320 if [[ "$?" != "0" ]]; then
1334 die "${FUNCNAME}(): Generation of '$1' failed" 1321 die "${FUNCNAME}(): Generation of '$1' failed"
1335 fi 1322 fi
1773 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1760 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1774 fi 1761 fi
1775 _python_calculate_PYTHON_ABIS 1762 _python_calculate_PYTHON_ABIS
1776 PYTHON_ABI="${PYTHON_ABIS##* }" 1763 PYTHON_ABI="${PYTHON_ABIS##* }"
1777 elif [[ "${python2}" == "1" ]]; then 1764 elif [[ "${python2}" == "1" ]]; then
1778 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1765 PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)"
1779 if [[ -z "${PYTHON_ABI}" ]]; then 1766 if [[ -z "${PYTHON_ABI}" ]]; then
1780 die "${FUNCNAME}(): Active version of CPython 2 not set" 1767 die "${FUNCNAME}(): Active version of CPython 2 not set"
1781 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1768 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1782 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1769 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1783 fi 1770 fi
1784 elif [[ "${python3}" == "1" ]]; then 1771 elif [[ "${python3}" == "1" ]]; then
1785 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1772 PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)"
1786 if [[ -z "${PYTHON_ABI}" ]]; then 1773 if [[ -z "${PYTHON_ABI}" ]]; then
1787 die "${FUNCNAME}(): Active version of CPython 3 not set" 1774 die "${FUNCNAME}(): Active version of CPython 3 not set"
1788 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1775 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1789 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1776 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1790 fi 1777 fi
2152 die "${FUNCNAME}(): Jython does not have shared library" 2139 die "${FUNCNAME}(): Jython does not have shared library"
2153 fi 2140 fi
2154} 2141}
2155 2142
2156# @FUNCTION: python_get_version 2143# @FUNCTION: python_get_version
2157# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] 2144# @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro]
2158# @DESCRIPTION: 2145# @DESCRIPTION:
2159# Print Python version. 2146# Print version of Python implementation.
2160# --full, --major, --minor and --micro options cannot be specified simultaneously. 2147# --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. 2148# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
2149# If --language option is specified, then version of Python language is printed.
2150# --language and --full options cannot be specified simultaneously.
2151# --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. 2152# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2163python_get_version() { 2153python_get_version() {
2164 _python_check_python_pkg_setup_execution 2154 _python_check_python_pkg_setup_execution
2165 2155
2166 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 2156 local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command
2167 2157
2168 while (($#)); do 2158 while (($#)); do
2169 case "$1" in 2159 case "$1" in
2170 -f|--final-ABI) 2160 -f|--final-ABI)
2171 final_ABI="1" 2161 final_ABI="1"
2172 ;; 2162 ;;
2163 -l|--language)
2164 language="1"
2165 ;;
2173 --full) 2166 --full)
2174 full="1" 2167 full="1"
2175 ;; 2168 ;;
2176 --major) 2169 --major)
2177 major="1" 2170 major="1"
2189 die "${FUNCNAME}(): Invalid usage" 2182 die "${FUNCNAME}(): Invalid usage"
2190 ;; 2183 ;;
2191 esac 2184 esac
2192 shift 2185 shift
2193 done 2186 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 2187
2219 if [[ "${final_ABI}" == "1" ]]; then 2188 if [[ "${final_ABI}" == "1" ]]; then
2220 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2189 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" 2190 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2222 fi 2191 fi
2223 "$(PYTHON -f)" -c "${python_command}"
2224 else 2192 else
2225 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then 2193 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" 2194 die "${FUNCNAME}() should be used in ABI-specific local scope"
2227 fi 2195 fi
2196 fi
2197
2198 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2199 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2200 fi
2201
2202 if [[ "${language}" == "1" ]]; then
2203 if [[ "${final_ABI}" == "1" ]]; then
2204 PYTHON_ABI="$(PYTHON -f --ABI)"
2205 elif [[ -z "${PYTHON_ABI}" ]]; then
2206 PYTHON_ABI="$(PYTHON --ABI)"
2207 fi
2208 language_version="${PYTHON_ABI%%-*}"
2209 if [[ "${full}" == "1" ]]; then
2210 die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously"
2211 elif [[ "${major}" == "1" ]]; then
2212 echo "${language_version%.*}"
2213 elif [[ "${minor}" == "1" ]]; then
2214 echo "${language_version#*.}"
2215 elif [[ "${micro}" == "1" ]]; then
2216 die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously"
2217 else
2218 echo "${language_version}"
2219 fi
2220 else
2221 if [[ "${full}" == "1" ]]; then
2222 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
2223 elif [[ "${major}" == "1" ]]; then
2224 python_command="from sys import version_info; print(version_info[0])"
2225 elif [[ "${minor}" == "1" ]]; then
2226 python_command="from sys import version_info; print(version_info[1])"
2227 elif [[ "${micro}" == "1" ]]; then
2228 python_command="from sys import version_info; print(version_info[2])"
2229 else
2230 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2231 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2232 echo "${PYTHON_ABI}"
2233 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2234 echo "${PYTHON_ABI%-jython}"
2235 fi
2236 return
2237 fi
2238 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2239 fi
2240
2241 if [[ "${final_ABI}" == "1" ]]; then
2242 "$(PYTHON -f)" -c "${python_command}"
2243 else
2228 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2244 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
2245 fi
2246 fi
2247}
2248
2249# @FUNCTION: python_get_implementation_and_version
2250# @USAGE: [-f|--final-ABI]
2251# @DESCRIPTION:
2252# Print name and version of Python implementation.
2253# If version of Python implementation is not bound to version of Python language, then
2254# version of Python language is additionally printed.
2255# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2256python_get_implementation_and_version() {
2257 _python_check_python_pkg_setup_execution
2258
2259 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
2260
2261 while (($#)); do
2262 case "$1" in
2263 -f|--final-ABI)
2264 final_ABI="1"
2265 ;;
2266 -*)
2267 die "${FUNCNAME}(): Unrecognized option '$1'"
2268 ;;
2269 *)
2270 die "${FUNCNAME}(): Invalid usage"
2271 ;;
2272 esac
2273 shift
2274 done
2275
2276 if [[ "${final_ABI}" == "1" ]]; then
2277 if ! _python_package_supporting_installation_for_multiple_python_abis; then
2278 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2279 fi
2280 PYTHON_ABI="$(PYTHON -f --ABI)"
2281 else
2282 if _python_package_supporting_installation_for_multiple_python_abis; then
2283 if ! _python_abi-specific_local_scope; then
2284 die "${FUNCNAME}() should be used in ABI-specific local scope"
2285 fi
2286 else
2287 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2288 fi
2289 fi
2290
2291 if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
2292 echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})"
2293 else
2294 echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}"
2229 fi 2295 fi
2230} 2296}
2231 2297
2232# ================================================================================================ 2298# ================================================================================================
2233# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 2299# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
2579 _python_check_python_pkg_setup_execution 2645 _python_check_python_pkg_setup_execution
2580 _python_initialize_prefix_variables 2646 _python_initialize_prefix_variables
2581 2647
2582 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then 2648 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2583 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2649 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2584 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() 2650 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() stderr stderr_line
2585 2651
2586 if _python_package_supporting_installation_for_multiple_python_abis; then 2652 if _python_package_supporting_installation_for_multiple_python_abis; then
2587 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2653 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2588 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2654 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2589 fi 2655 fi
2684 options+=("-q") 2750 options+=("-q")
2685 2751
2686 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2752 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2687 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then 2753 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2688 return_code="0" 2754 return_code="0"
2755 stderr=""
2689 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2756 ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)"
2690 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then 2757 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2691 for dir in "${site_packages_dirs[@]}"; do 2758 for dir in "${site_packages_dirs[@]}"; do
2692 dirs+=("${root}$(python_get_sitedir)/${dir}") 2759 dirs+=("${root}$(python_get_sitedir)/${dir}")
2693 done 2760 done
2694 for dir in "${evaluated_dirs[@]}"; do 2761 for dir in "${evaluated_dirs[@]}"; do
2695 eval "dirs+=(\"\${root}${dir}\")" 2762 eval "dirs+=(\"\${root}${dir}\")"
2696 done 2763 done
2697 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1" 2764 stderr+="${stderr:+$'\n'}$("$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1"
2698 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2765 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2699 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" 2766 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2700 fi 2767 fi
2701 _python_clean_compiled_modules "${dirs[@]}" 2768 _python_clean_compiled_modules "${dirs[@]}"
2702 fi 2769 fi
2705 files+=("${root}$(python_get_sitedir)/${file}") 2772 files+=("${root}$(python_get_sitedir)/${file}")
2706 done 2773 done
2707 for file in "${evaluated_files[@]}"; do 2774 for file in "${evaluated_files[@]}"; do
2708 eval "files+=(\"\${root}${file}\")" 2775 eval "files+=(\"\${root}${file}\")"
2709 done 2776 done
2710 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1" 2777 stderr+="${stderr:+$'\n'}$("$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" 2>&1)" || return_code="1"
2711 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2778 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2712 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1" 2779 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2713 fi 2780 fi
2714 _python_clean_compiled_modules "${files[@]}" 2781 _python_clean_compiled_modules "${files[@]}"
2715 fi 2782 fi
2716 eend "${return_code}" 2783 eend "${return_code}"
2784 if [[ -n "${stderr}" ]]; then
2785 eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &> /dev/null
2786 while read stderr_line; do
2787 eerror " ${stderr_line}"
2788 done <<< "${stderr}"
2789 fi
2717 fi 2790 fi
2718 unset dirs files 2791 unset dirs files
2719 done 2792 done
2720 2793
2721 if _python_package_supporting_installation_for_multiple_python_abis; then 2794 if _python_package_supporting_installation_for_multiple_python_abis; then
2727 fi 2800 fi
2728 fi 2801 fi
2729 2802
2730 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2803 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
2731 return_code="0" 2804 return_code="0"
2805 stderr=""
2732 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2806 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)"
2733 if ((${#other_dirs[@]})); then 2807 if ((${#other_dirs[@]})); then
2734 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2808 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1"
2735 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2809 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2736 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2810 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2737 fi 2811 fi
2738 _python_clean_compiled_modules "${other_dirs[@]}" 2812 _python_clean_compiled_modules "${other_dirs[@]}"
2739 fi 2813 fi
2740 if ((${#other_files[@]})); then 2814 if ((${#other_files[@]})); then
2741 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2815 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" 2>&1)" || return_code="1"
2742 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2816 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2743 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2817 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2744 fi 2818 fi
2745 _python_clean_compiled_modules "${other_files[@]}" 2819 _python_clean_compiled_modules "${other_files[@]}"
2746 fi 2820 fi
2747 eend "${return_code}" 2821 eend "${return_code}"
2822 if [[ -n "${stderr}" ]]; then
2823 eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &> /dev/null
2824 while read stderr_line; do
2825 eerror " ${stderr_line}"
2826 done <<< "${stderr}"
2827 fi
2748 fi 2828 fi
2749 else 2829 else
2750 # Deprecated part of python_mod_optimize() 2830 # Deprecated part of python_mod_optimize()
2751 ewarn 2831 ewarn
2752 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" 2832 ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"

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

  ViewVC Help
Powered by ViewVC 1.1.20