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

Diff of /eclass/python.eclass

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

Revision 1.81 Revision 1.82
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.81 2009/11/22 16:45:54 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.82 2009/12/23 23:43:42 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# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules. 8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules.
56 56
57python_version() { 57python_version() {
58 [[ -n "${PYVER}" ]] && return 0 58 [[ -n "${PYVER}" ]] && return 0
59 local tmpstr 59 local tmpstr
60 python=${python:-/usr/bin/python} 60 python=${python:-/usr/bin/python}
61 tmpstr="$(${python} -V 2>&1 )" 61 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
62 export PYVER_ALL="${tmpstr#Python }" 62 export PYVER_ALL="${tmpstr#Python }"
63 __python_version_extract $PYVER_ALL 63 __python_version_extract $PYVER_ALL
64} 64}
65 65
66# @FUNCTION: PYTHON 66# @FUNCTION: PYTHON
67# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}"> 67# @USAGE: [-2] [-3] [-A|--only-ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
68# @DESCRIPTION: 68# @DESCRIPTION:
69# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 69# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
70# is ommitted, then PYTHON_ABI environment variable must be set and is used. 70# is ommitted, then PYTHON_ABI environment variable must be set and is used.
71# If -2 option is specified, then active version of Python 2 is used.
72# If -3 option is specified, then active version of Python 3 is used.
73# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
74# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
75# If --only-ABI option is specified, then only specified Python ABI is printed instead of
76# Python interpreter filename.
77# --only-ABI and --absolute-path options cannot be specified simultaneously.
71PYTHON() { 78PYTHON() {
72 local absolute_path="0" slot= 79 local absolute_path="0" final_ABI="0" only_ABI="0" python2="0" python3="0" slot=
73 80
74 while (($#)); do 81 while (($#)); do
75 case "$1" in 82 case "$1" in
83 -2)
84 python2="1"
85 ;;
86 -3)
87 python3="1"
88 ;;
89 -A|--only-ABI)
90 only_ABI="1"
91 ;;
76 -a|--absolute-path) 92 -a|--absolute-path)
77 absolute_path="1" 93 absolute_path="1"
78 ;; 94 ;;
95 -f|--final-ABI)
96 final_ABI="1"
97 ;;
79 --) 98 --)
80 break 99 break
81 ;; 100 ;;
82 -*) 101 -*)
83 die "${FUNCNAME}(): Unrecognized option $1" 102 die "${FUNCNAME}(): Unrecognized option '$1'"
84 ;; 103 ;;
85 *) 104 *)
86 break 105 break
87 ;; 106 ;;
88 esac 107 esac
89 shift 108 shift
90 done 109 done
91 110
111 if [[ "${only_ABI}" == "1" && "${absolute_path}" == "1" ]]; then
112 die "${FUNCNAME}(): '--only-ABI and '--absolute-path' options cannot be specified simultaneously"
113 fi
114
115 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt "1" ]]; then
116 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
117 fi
118
92 if [[ "$#" -eq "0" ]]; then 119 if [[ "$#" -eq "0" ]]; then
120 if [[ "${final_ABI}" == "1" ]]; then
121 validate_PYTHON_ABIS
122 slot="${PYTHON_ABIS##* }"
123 elif [[ "${python2}" == "1" ]]; then
124 slot="$(eselect python show --python2)"
125 if [[ -z "${slot}" ]]; then
126 die "${FUNCNAME}(): Active Python 2 interpreter not set"
127 elif [[ "${slot}" != "python2."* ]]; then
128 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
129 fi
130 slot="${slot#python}"
131 elif [[ "${python3}" == "1" ]]; then
132 slot="$(eselect python show --python3)"
133 if [[ -z "${slot}" ]]; then
134 die "${FUNCNAME}(): Active Python 3 interpreter not set"
135 elif [[ "${slot}" != "python3."* ]]; then
136 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
137 fi
138 slot="${slot#python}"
93 if [[ -n "${PYTHON_ABI}" ]]; then 139 elif [[ -n "${PYTHON_ABI}" ]]; then
94 slot="${PYTHON_ABI}" 140 slot="${PYTHON_ABI}"
95 else 141 else
96 die "${FUNCNAME}(): Invalid usage" 142 die "${FUNCNAME}(): Invalid usage"
97 fi 143 fi
98 elif [[ "$#" -eq "1" ]]; then 144 elif [[ "$#" -eq "1" ]]; then
145 if [[ "${final_ABI}" == "1" ]]; then
146 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
147 fi
148 if [[ "${python2}" == "1" ]]; then
149 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
150 fi
151 if [[ "${python3}" == "1" ]]; then
152 die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously"
153 fi
99 slot="$1" 154 slot="$1"
100 else 155 else
101 die "${FUNCNAME}(): Invalid usage" 156 die "${FUNCNAME}(): Invalid usage"
102 fi 157 fi
103 158
159 if [[ "${only_ABI}" == "1" ]]; then
160 echo -n "${slot}"
161 return
104 if [[ "${absolute_path}" == "1" ]]; then 162 elif [[ "${absolute_path}" == "1" ]]; then
105 echo -n "/usr/bin/python${slot}" 163 echo -n "/usr/bin/python${slot}"
106 else 164 else
107 echo -n "python${slot}" 165 echo -n "python${slot}"
108 fi 166 fi
109 167
110 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then 168 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
111 echo -n "-${ABI}" 169 echo -n "-${ABI}"
112 fi 170 fi
171}
172
173# @FUNCTION: python_set_active_version
174# @USAGE: <Python_ABI|2|3>
175# @DESCRIPTION:
176# Set active version of Python.
177python_set_active_version() {
178 if [[ "$#" -ne "1" ]]; then
179 die "${FUNCNAME}() requires 1 argument"
180 fi
181
182 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
183 if ! has_version "dev-lang/python:$1"; then
184 die "${FUNCNAME}(): 'dev-lang/python:$1' isn't installed"
185 fi
186 export EPYTHON="$(PYTHON "$1")"
187 elif [[ "$1" == "2" ]]; then
188 if ! has_version "=dev-lang/python-2*"; then
189 die "${FUNCNAME}(): '=dev-lang/python-2*' isn't installed"
190 fi
191 export EPYTHON="$(PYTHON -2)"
192 elif [[ "$1" == "3" ]]; then
193 if ! has_version "=dev-lang/python-3*"; then
194 die "${FUNCNAME}(): '=dev-lang/python-3*' isn't installed"
195 fi
196 export EPYTHON="$(PYTHON -3)"
197 else
198 die "${FUNCNAME}(): Unrecognized argument '$1'"
199 fi
200
201 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
202 # so it doesn't need to be exported to subprocesses.
203 PYTHON_ABI="${EPYTHON#python}"
204 PYTHON_ABI="${PYTHON_ABI%%-*}"
113} 205}
114 206
115unset PYTHON_ABIS 207unset PYTHON_ABIS
116unset PYTHON_ABIS_SANITY_CHECKS 208unset PYTHON_ABIS_SANITY_CHECKS
117 209
130 fi 222 fi
131 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 223 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
132 die "'/usr/bin/python-config' isn't valid script" 224 die "'/usr/bin/python-config' isn't valid script"
133 fi 225 fi
134 226
135 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 227 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
136 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then 228 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
137 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS= 229 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
138 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 230 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
139 python2_supported_versions="2.4 2.5 2.6 2.7" 231 python2_supported_versions="2.4 2.5 2.6 2.7"
140 python3_supported_versions="3.0 3.1 3.2" 232 python3_supported_versions="3.0 3.1 3.2"
141 233
163 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 255 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
164 support_ABI="0" 256 support_ABI="0"
165 break 257 break
166 fi 258 fi
167 done 259 done
168 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${PYTHON_ABI}" 260 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
169 done 261 done
170 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
171 262
172 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 263 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
173 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}" 264 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
174 fi 265 fi
175 266
236 else 327 else
237 python3_version="" 328 python3_version=""
238 fi 329 fi
239 fi 330 fi
240 331
241 if ! has "${python_version}" "${python2_version}" "${python3_version}"; then 332 if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
242 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 or /usr/bin/python3 symlink" 333 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 symlink"
334 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
335 die "Incorrect configuration of Python"
336 fi
337 if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
338 eerror "Python wrapper is configured incorrectly or /usr/bin/python3 symlink"
243 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 339 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
244 die "Incorrect configuration of Python" 340 die "Incorrect configuration of Python"
245 fi 341 fi
246 342
247 PYTHON_ABIS="${python2_version} ${python3_version}" 343 PYTHON_ABIS="${python2_version} ${python3_version}"
251 fi 347 fi
252 348
253 if [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then 349 if [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then
254 local PYTHON_ABI 350 local PYTHON_ABI
255 for PYTHON_ABI in ${PYTHON_ABIS}; do 351 for PYTHON_ABI in ${PYTHON_ABIS}; do
256 # Ensure that appropriate Python version is installed. 352 # Ensure that appropriate version of Python is installed.
257 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then 353 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
258 die "dev-lang/python:${PYTHON_ABI} isn't installed" 354 die "dev-lang/python:${PYTHON_ABI} isn't installed"
259 fi 355 fi
260 356
261 # Ensure that EPYTHON variable is respected. 357 # Ensure that EPYTHON variable is respected.
402 if has "${EAPI:-0}" 0 1; then 498 if has "${EAPI:-0}" 0 1; then
403 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" 499 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
404 fi 500 fi
405 501
406 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 502 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
407 if has "${EAPI}" 2; then 503 if has "${EAPI}" 2 3; then
408 python_default_function() { 504 python_default_function() {
409 econf 505 econf
410 } 506 }
411 else 507 else
412 python_default_function() { 508 python_default_function() {
428 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 524 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
429 python_default_function() { 525 python_default_function() {
430 emake DESTDIR="${D}" install 526 emake DESTDIR="${D}" install
431 } 527 }
432 else 528 else
433 die "${FUNCNAME}(): --default-function option cannot be used in this ebuild phase" 529 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
434 fi 530 fi
435 function="python_default_function" 531 function="python_default_function"
436 fi 532 fi
437 533
438 if [[ "${quiet}" == "0" ]]; then 534 if [[ "${quiet}" == "0" ]]; then
486 582
487 previous_directory="$(pwd)" 583 previous_directory="$(pwd)"
488 previous_directory_stack="$(dirs -p)" 584 previous_directory_stack="$(dirs -p)"
489 previous_directory_stack_length="$(dirs -p | wc -l)" 585 previous_directory_stack_length="$(dirs -p | wc -l)"
490 586
491 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 587 if ! has "${EAPI}" 0 1 2 3 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
492 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 588 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
493 else 589 else
494 EPYTHON="$(PYTHON)" "${function}" "$@" 590 EPYTHON="$(PYTHON)" "${function}" "$@"
495 fi 591 fi
496 592
507 fi 603 fi
508 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 604 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
509 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 605 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
510 local enabled_PYTHON_ABIS= other_PYTHON_ABI 606 local enabled_PYTHON_ABIS= other_PYTHON_ABI
511 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 607 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
512 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${other_PYTHON_ABI}" 608 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
513 done 609 done
514 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" 610 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
515 fi 611 fi
516 if [[ "${quiet}" == "0" ]]; then 612 if [[ "${quiet}" == "0" ]]; then
517 ewarn "${RED}${failure_message}${NORMAL}" 613 ewarn "${RED}${failure_message}${NORMAL}"
518 fi 614 fi
519 if [[ -z "${PYTHON_ABIS}" ]]; then 615 if [[ -z "${PYTHON_ABIS}" ]]; then
619 for file in "${files[@]}"; do 715 for file in "${files[@]}"; do
620 file="${file#./}" 716 file="${file#./}"
621 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 717 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
622 718
623 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 719 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
720 if [[ "${quiet}" == "0" ]]; then
624 [[ "${quiet}" == "0" ]] && einfo "Converting shebang in '${file}'" 721 einfo "Converting shebang in '${file}'"
722 fi
625 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 723 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
626 724
627 # Delete potential whitespace after "#!". 725 # Delete potential whitespace after "#!".
628 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 726 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
629 fi 727 fi
728 done
729}
730
731# @FUNCTION: python_generate_wrapper_scripts
732# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
733# @DESCRIPTION:
734# Generate wrapper scripts. Existing files are overwritten only with --force option.
735# If --respect-EPYTHON option is specified, then generated wrapper scripts will
736# respect EPYTHON variable at run time.
737python_generate_wrapper_scripts() {
738 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python2_supported_versions python3_enabled="0" python3_supported_versions respect_EPYTHON="0"
739 python2_supported_versions="2.4 2.5 2.6 2.7"
740 python3_supported_versions="3.0 3.1 3.2"
741
742 while (($#)); do
743 case "$1" in
744 -E|--respect-EPYTHON)
745 respect_EPYTHON="1"
746 ;;
747 -f|--force)
748 force="1"
749 ;;
750 -q|--quiet)
751 quiet="1"
752 ;;
753 --)
754 break
755 ;;
756 -*)
757 die "${FUNCNAME}(): Unrecognized option '$1'"
758 ;;
759 *)
760 break
761 ;;
762 esac
763 shift
764 done
765
766 if [[ "$#" -eq 0 ]]; then
767 die "${FUNCNAME}(): Missing arguments"
768 fi
769
770 validate_PYTHON_ABIS
771 for PYTHON_ABI in ${python2_supported_versions}; do
772 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
773 python2_enabled="1"
774 fi
775 done
776 for PYTHON_ABI in ${python3_supported_versions}; do
777 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
778 python3_enabled="1"
779 fi
780 done
781
782 if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "1" ]]; then
783 eselect_python_option=
784 elif [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "0" ]]; then
785 eselect_python_option="--python2"
786 elif [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "1" ]]; then
787 eselect_python_option="--python3"
788 else
789 die "${FUNCNAME}(): Unsupported environment"
790 fi
791
792 for file in "$@"; do
793 if [[ -f "${file}" && "${force}" == "0" ]]; then
794 die "${FUNCNAME}(): '$1' already exists"
795 fi
796
797 if [[ "${quiet}" == "0" ]]; then
798 einfo "Generating '${file#${D%/}}' wrapper script"
799 fi
800
801 cat << EOF > "${file}"
802#!/usr/bin/env python
803# Gentoo '${file##*/}' wrapper script
804
805import os
806import re
807import subprocess
808import sys
809
810EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
811
812EOF
813 if [[ "$?" != "0" ]]; then
814 die "${FUNCNAME}(): Generation of '$1' failed"
815 fi
816 if [[ "${respect_EPYTHON}" == "1" ]]; then
817 cat << EOF >> "${file}"
818EPYTHON = os.environ.get("EPYTHON")
819if EPYTHON:
820 EPYTHON_matched = EPYTHON_re.match(EPYTHON)
821 if EPYTHON_matched:
822 PYTHON_ABI = EPYTHON_matched.group(1)
823 else:
824 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON)
825 sys.exit(1)
826else:
827 try:
828 eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
829 if eselect_process.wait() != 0:
830 raise ValueError
831 except (OSError, ValueError):
832 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
833 sys.exit(1)
834
835 eselect_output = eselect_process.stdout.read()
836 if not isinstance(eselect_output, str):
837 # Python 3
838 eselect_output = eselect_output.decode()
839
840 EPYTHON_matched = EPYTHON_re.match(eselect_output)
841 if EPYTHON_matched:
842 PYTHON_ABI = EPYTHON_matched.group(1)
843 else:
844 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output)
845 sys.exit(1)
846EOF
847 if [[ "$?" != "0" ]]; then
848 die "${FUNCNAME}(): Generation of '$1' failed"
849 fi
850 else
851 cat << EOF >> "${file}"
852try:
853 eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
854 if eselect_process.wait() != 0:
855 raise ValueError
856except (OSError, ValueError):
857 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
858 sys.exit(1)
859
860eselect_output = eselect_process.stdout.read()
861if not isinstance(eselect_output, str):
862 # Python 3
863 eselect_output = eselect_output.decode()
864
865EPYTHON_matched = EPYTHON_re.match(eselect_output)
866if EPYTHON_matched:
867 PYTHON_ABI = EPYTHON_matched.group(1)
868else:
869 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output)
870 sys.exit(1)
871EOF
872 if [[ "$?" != "0" ]]; then
873 die "${FUNCNAME}(): Generation of '$1' failed"
874 fi
875 fi
876 cat << EOF >> "${file}"
877
878target_executable = "%s-%s" % (sys.argv[0], PYTHON_ABI)
879if not os.path.exists(target_executable):
880 sys.stderr.write("'%s' does not exist\n" % target_executable)
881 sys.exit(1)
882
883os.execv(target_executable, sys.argv)
884EOF
885 if [[ "$?" != "0" ]]; then
886 die "${FUNCNAME}(): Generation of '$1' failed"
887 fi
888 fperms +x "${file#${D%/}}" || die "fperms '${file}' failed"
630 done 889 done
631} 890}
632 891
633# @ECLASS-VARIABLE: PYTHON_USE_WITH 892# @ECLASS-VARIABLE: PYTHON_USE_WITH
634# @DESCRIPTION: 893# @DESCRIPTION:
833 1092
834 # Check if phase is pkg_postinst() 1093 # Check if phase is pkg_postinst()
835 [[ ${EBUILD_PHASE} != postinst ]] &&\ 1094 [[ ${EBUILD_PHASE} != postinst ]] &&\
836 die "${FUNCNAME} should only be run in pkg_postinst()" 1095 die "${FUNCNAME} should only be run in pkg_postinst()"
837 1096
838 # allow compiling for older python versions
839 if [[ "${PYTHON_OVERRIDE_PYVER}" ]]; then 1097 if [[ -n "${PYTHON_ABI}" ]]; then
840 PYVER=${PYTHON_OVERRIDE_PYVER} 1098 PYVER="${PYTHON_ABI}"
841 else 1099 else
842 python_version 1100 python_version
843 fi 1101 fi
844 1102
845 # strip trailing slash 1103 # strip trailing slash
1003 ;; 1261 ;;
1004 esac 1262 esac
1005 shift 1263 shift
1006 done 1264 done
1007 1265
1008 # allow compiling for older python versions
1009 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then 1266 if [[ -n "${PYTHON_ABI}" ]]; then
1010 PYVER=${PYTHON_OVERRIDE_PYVER} 1267 PYVER="${PYTHON_ABI}"
1011 else 1268 else
1012 python_version 1269 python_version
1013 fi 1270 fi
1014 1271
1015 # set additional opts 1272 # set additional opts

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.82

  ViewVC Help
Powered by ViewVC 1.1.20