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

Diff of /eclass/python.eclass

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

Revision 1.91 Revision 1.94
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 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.91 2010/02/28 15:49:33 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.94 2010/03/13 13:46:20 arfrever 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
188# @DESCRIPTION: 188# @DESCRIPTION:
189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
190# are respected. Only exported if one of those variables is set. 190# are respected. Only exported if one of those variables is set.
191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
192 python_pkg_setup() { 192 python_pkg_setup() {
193 # Check if phase is pkg_setup().
194 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
195
193 python_pkg_setup_fail() { 196 python_pkg_setup_fail() {
194 eerror "${1}" 197 eerror "${1}"
195 die "${1}" 198 die "${1}"
196 } 199 }
197 200
227 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail 230 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
228 } 231 }
229 232
230 EXPORT_FUNCTIONS pkg_setup 233 EXPORT_FUNCTIONS pkg_setup
231 234
232 _PYTHON_USE_WITH_ATOM="" 235 _PYTHON_USE_WITH_ATOMS_ARRAY=()
233 if [[ -n "${PYTHON_USE_WITH}" ]]; then 236 if [[ -n "${PYTHON_USE_WITH}" ]]; then
234 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 237 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
235 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 238 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]")
236 done 239 done
237 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )"
238 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 240 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
239 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 241 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
240 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 242 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
241 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${_USE_flag}]" 243 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
242 done 244 done
243 done 245 done
244 unset _USE_flag 246 unset _USE_flag
247 fi
248 if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
245 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )" 249 _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
250 else
251 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
246 fi 252 fi
247 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then 253 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
248 _PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOM} )" 254 _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
249 fi 255 fi
250 DEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 256 DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
251 RDEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 257 RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
252 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOM 258 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
253fi 259fi
254 260
255unset _PYTHON_ATOMS 261unset _PYTHON_ATOMS
256 262
257# ================================================================================================ 263# ================================================================================================
265 271
266# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 272# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
267# @DESCRIPTION: 273# @DESCRIPTION:
268# Set this to export phase functions for the following ebuild phases: 274# Set this to export phase functions for the following ebuild phases:
269# src_prepare, src_configure, src_compile, src_test, src_install. 275# src_prepare, src_configure, src_compile, src_test, src_install.
270if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 276if ! has "${EAPI:-0}" 0 1; then
271 python_src_prepare() { 277 python_src_prepare() {
272 python_copy_sources 278 python_copy_sources
273 } 279 }
274 280
275 for python_default_function in src_configure src_compile src_test src_install; do 281 for python_default_function in src_configure src_compile src_test src_install; do
276 eval "python_${python_default_function}() { python_execute_function -d -s; }" 282 eval "python_${python_default_function}() {
283 python_execute_function -d -s \"\$@\"
284 }"
277 done 285 done
278 unset python_default_function 286 unset python_default_function
279 287
280 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 288 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
281 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 289 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
300 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 308 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
301 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 309 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
302 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 310 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
303 311
304 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 312 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
305 local python2_enabled="0" python3_enabled="0" 313 local cpython_enabled="0"
306 314
307 if [[ -z "${USE_PYTHON}" ]]; then 315 if [[ -z "${USE_PYTHON}" ]]; then
308 die "USE_PYTHON variable is empty" 316 die "USE_PYTHON variable is empty"
309 fi 317 fi
310 318
311 for PYTHON_ABI in ${USE_PYTHON}; do 319 for PYTHON_ABI in ${USE_PYTHON}; do
312 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 320 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
313 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 321 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
314 fi 322 fi
315 323
316 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}"; then 324 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
317 python2_enabled="1" 325 cpython_enabled="1"
318 fi
319 if has "${PYTHON_ABI}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
320 python3_enabled="1"
321 fi 326 fi
322 327
323 support_ABI="1" 328 support_ABI="1"
324 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 329 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
325 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 330 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
332 337
333 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 338 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
334 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}" 339 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}"
335 fi 340 fi
336 341
337 if [[ "${python2_enabled}" == "0" ]]; then 342 if [[ "${cpython_enabled}" == "0" ]]; then
338 ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported."
339 fi
340 if [[ "${python3_enabled}" == "0" ]]; then
341 ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported."
342 fi
343 if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "0" ]]; then
344 die "USE_PYTHON variable does not enable any version of CPython" 343 die "USE_PYTHON variable does not enable any version of CPython"
345 fi 344 fi
346 else 345 else
347 local python_version python2_version= python3_version= support_python_major_version 346 local python_version python2_version= python3_version= support_python_major_version
348 347
488 487
489 if [[ -z "$(type -t "${function}")" ]]; then 488 if [[ -z "$(type -t "${function}")" ]]; then
490 die "${FUNCNAME}(): '${function}' function is not defined" 489 die "${FUNCNAME}(): '${function}' function is not defined"
491 fi 490 fi
492 else 491 else
493 if [[ "$#" -ne 0 ]]; then
494 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
495 fi
496 if has "${EAPI:-0}" 0 1; then 492 if has "${EAPI:-0}" 0 1; then
497 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" 493 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
498 fi 494 fi
499 495
500 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 496 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
501 if has "${EAPI}" 2 3; then 497 if has "${EAPI}" 2 3; then
502 python_default_function() { 498 python_default_function() {
503 econf 499 econf "$@"
504 } 500 }
505 else 501 else
506 python_default_function() { 502 python_default_function() {
507 nonfatal econf 503 nonfatal econf "$@"
508 } 504 }
509 fi 505 fi
510 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 506 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
511 python_default_function() { 507 python_default_function() {
512 emake 508 emake "$@"
513 } 509 }
514 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 510 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
515 python_default_function() { 511 python_default_function() {
516 if emake -j1 -n check &> /dev/null; then 512 if emake -j1 -n check &> /dev/null; then
517 emake -j1 check 513 emake -j1 check "$@"
518 elif emake -j1 -n test &> /dev/null; then 514 elif emake -j1 -n test &> /dev/null; then
519 emake -j1 test 515 emake -j1 test "$@"
520 fi 516 fi
521 } 517 }
522 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 518 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
523 python_default_function() { 519 python_default_function() {
524 emake DESTDIR="${D}" install 520 emake DESTDIR="${D}" install "$@"
525 } 521 }
526 else 522 else
527 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" 523 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
528 fi 524 fi
529 function="python_default_function" 525 function="python_default_function"
657 653
658 if [[ "$#" -eq 0 ]]; then 654 if [[ "$#" -eq 0 ]]; then
659 if [[ "${WORKDIR}" == "${S}" ]]; then 655 if [[ "${WORKDIR}" == "${S}" ]]; then
660 die "${FUNCNAME}() cannot be used" 656 die "${FUNCNAME}() cannot be used"
661 fi 657 fi
662 dirs=("${S}") 658 dirs=("${S%/}")
663 else 659 else
664 dirs=("$@") 660 dirs=("$@")
665 fi 661 fi
666 662
667 validate_PYTHON_ABIS 663 validate_PYTHON_ABIS
753 if [[ -f "${file}" && "${force}" == "0" ]]; then 749 if [[ -f "${file}" && "${force}" == "0" ]]; then
754 die "${FUNCNAME}(): '$1' already exists" 750 die "${FUNCNAME}(): '$1' already exists"
755 fi 751 fi
756 752
757 if [[ "${quiet}" == "0" ]]; then 753 if [[ "${quiet}" == "0" ]]; then
758 einfo "Generating '${file#${D%/}}' wrapper script" 754 einfo "Generating '${file#${ED%/}}' wrapper script"
759 fi 755 fi
760 756
761 cat << EOF > "${file}" 757 cat << EOF > "${file}"
762#!/usr/bin/env python 758#!/usr/bin/env python
763# Gentoo '${file##*/}' wrapper script 759# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
764 760
765import os 761import os
766import re 762import re
767import subprocess 763import subprocess
768import sys 764import sys
769 765
770EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 766EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
767python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
768python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
771 769
772EOF 770EOF
773 if [[ "$?" != "0" ]]; then 771 if [[ "$?" != "0" ]]; then
774 die "${FUNCNAME}(): Generation of '$1' failed" 772 die "${FUNCNAME}(): Generation of '$1' failed"
775 fi 773 fi
790 raise ValueError 788 raise ValueError
791 except (OSError, ValueError): 789 except (OSError, ValueError):
792 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 790 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
793 sys.exit(1) 791 sys.exit(1)
794 792
795 eselect_output = eselect_process.stdout.read() 793 EPYTHON = eselect_process.stdout.read().rstrip("\n")
796 if not isinstance(eselect_output, str): 794 if not isinstance(EPYTHON, str):
797 # Python 3 795 # Python 3
798 eselect_output = eselect_output.decode() 796 EPYTHON = EPYTHON.decode()
799 797
800 EPYTHON_matched = EPYTHON_re.match(eselect_output) 798 EPYTHON_matched = EPYTHON_re.match(EPYTHON)
801 if EPYTHON_matched: 799 if EPYTHON_matched:
802 PYTHON_ABI = EPYTHON_matched.group(1) 800 PYTHON_ABI = EPYTHON_matched.group(1)
803 else: 801 else:
804 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 802 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % EPYTHON)
805 sys.exit(1) 803 sys.exit(1)
806EOF 804EOF
807 if [[ "$?" != "0" ]]; then 805 if [[ "$?" != "0" ]]; then
808 die "${FUNCNAME}(): Generation of '$1' failed" 806 die "${FUNCNAME}(): Generation of '$1' failed"
809 fi 807 fi
815 raise ValueError 813 raise ValueError
816except (OSError, ValueError): 814except (OSError, ValueError):
817 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 815 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
818 sys.exit(1) 816 sys.exit(1)
819 817
820eselect_output = eselect_process.stdout.read() 818EPYTHON = eselect_process.stdout.read().rstrip("\n")
821if not isinstance(eselect_output, str): 819if not isinstance(EPYTHON, str):
822 # Python 3 820 # Python 3
823 eselect_output = eselect_output.decode() 821 EPYTHON = EPYTHON.decode()
824 822
825EPYTHON_matched = EPYTHON_re.match(eselect_output) 823EPYTHON_matched = EPYTHON_re.match(EPYTHON)
826if EPYTHON_matched: 824if EPYTHON_matched:
827 PYTHON_ABI = EPYTHON_matched.group(1) 825 PYTHON_ABI = EPYTHON_matched.group(1)
828else: 826else:
829 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 827 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % EPYTHON)
830 sys.exit(1) 828 sys.exit(1)
831EOF 829EOF
832 if [[ "$?" != "0" ]]; then 830 if [[ "$?" != "0" ]]; then
833 die "${FUNCNAME}(): Generation of '$1' failed" 831 die "${FUNCNAME}(): Generation of '$1' failed"
834 fi 832 fi
835 fi 833 fi
836 cat << EOF >> "${file}" 834 cat << EOF >> "${file}"
837 835
836wrapper_script_path = os.path.realpath(sys.argv[0])
837target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
838os.environ["PYTHON_SCRIPT_NAME"] = sys.argv[0] 838os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
839target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) 839os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
840if not os.path.exists(target_executable): 840if not os.path.exists(target_executable_path):
841 sys.stderr.write("'%s' does not exist\n" % target_executable) 841 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
842 sys.exit(1) 842 sys.exit(1)
843 843
844target_executable = open(target_executable_path, "rb")
845target_executable_first_line = target_executable.readline()
846if not isinstance(target_executable_first_line, str):
847 # Python 3
848 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
849
850python_shebang_matched = python_shebang_re.match(target_executable_first_line)
851target_executable.close()
852
853if python_shebang_matched:
854 try:
855 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
856 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
857 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
858 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
859 if python_verification_process.wait() != 0:
860 raise ValueError
861
862 python_verification_output = python_verification_process.stdout.read()
863 if not isinstance(python_verification_output, str):
864 # Python 3
865 python_verification_output = python_verification_output.decode()
866
867 if not python_verification_output_re.match(python_verification_output):
868 raise ValueError
869
870 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
871 except:
872 pass
873 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
874 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
875
844os.execv(target_executable, sys.argv) 876os.execv(target_executable_path, sys.argv)
845EOF 877EOF
846 if [[ "$?" != "0" ]]; then 878 if [[ "$?" != "0" ]]; then
847 die "${FUNCNAME}(): Generation of '$1' failed" 879 die "${FUNCNAME}(): Generation of '$1' failed"
848 fi 880 fi
849 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 881 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
1011 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1043 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1012 fi 1044 fi
1013 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1045 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
1014 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1046 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1015 elif [[ -z "${PYTHON_ABI}" ]]; then 1047 elif [[ -z "${PYTHON_ABI}" ]]; then
1016 die "${FUNCNAME}(): Invalid usage: Python ABI not specified" 1048 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1017 fi 1049 fi
1018 elif [[ "$#" -eq 1 ]]; then 1050 elif [[ "$#" -eq 1 ]]; then
1019 if [[ "${final_ABI}" == "1" ]]; then 1051 if [[ "${final_ABI}" == "1" ]]; then
1020 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1052 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1021 fi 1053 fi
1261 die "${FUNCNAME}(): Jython does not have shared library" 1293 die "${FUNCNAME}(): Jython does not have shared library"
1262 fi 1294 fi
1263} 1295}
1264 1296
1265# @FUNCTION: python_get_version 1297# @FUNCTION: python_get_version
1266# @USAGE: [-f|--final-ABI] [--major] [--minor] [--micro] 1298# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro]
1267# @DESCRIPTION: 1299# @DESCRIPTION:
1268# Print Python version. 1300# Print Python version.
1269# --major, --minor and --micro options cannot be specified simultaneously. 1301# --full, --major, --minor and --micro options cannot be specified simultaneously.
1270# If --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1302# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1271# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1303# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1272python_get_version() { 1304python_get_version() {
1273 local final_ABI="0" major="0" minor="0" micro="0" python_command 1305 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1274 1306
1275 while (($#)); do 1307 while (($#)); do
1276 case "$1" in 1308 case "$1" in
1277 -f|--final-ABI) 1309 -f|--final-ABI)
1278 final_ABI="1" 1310 final_ABI="1"
1279 ;; 1311 ;;
1312 --full)
1313 full="1"
1314 ;;
1280 --major) 1315 --major)
1281 major="1" 1316 major="1"
1282 ;; 1317 ;;
1283 --minor) 1318 --minor)
1284 minor="1" 1319 minor="1"
1294 ;; 1329 ;;
1295 esac 1330 esac
1296 shift 1331 shift
1297 done 1332 done
1298 1333
1299 if [[ "$((${major} + ${minor} + ${micro}))" -gt 1 ]]; then 1334 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
1300 die "${FUNCNAME}(): '--major', '--minor' or '--micro' options cannot be specified simultaneously" 1335 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
1301 fi 1336 fi
1302 1337
1338 if [[ "${full}" == "1" ]]; then
1339 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
1303 if [[ "${major}" == "1" ]]; then 1340 elif [[ "${major}" == "1" ]]; then
1304 python_command="from sys import version_info; print(version_info[0])" 1341 python_command="from sys import version_info; print(version_info[0])"
1305 elif [[ "${minor}" == "1" ]]; then 1342 elif [[ "${minor}" == "1" ]]; then
1306 python_command="from sys import version_info; print(version_info[1])" 1343 python_command="from sys import version_info; print(version_info[1])"
1307 elif [[ "${micro}" == "1" ]]; then 1344 elif [[ "${micro}" == "1" ]]; then
1308 python_command="from sys import version_info; print(version_info[2])" 1345 python_command="from sys import version_info; print(version_info[2])"
1309 else 1346 else
1347 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
1348 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1349 echo "${PYTHON_ABI}"
1350 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1351 echo "${PYTHON_ABI%-jython}"
1352 fi
1353 return
1354 fi
1310 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" 1355 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1311 fi 1356 fi
1312 1357
1313 if [[ "${final_ABI}" == "1" ]]; then 1358 if [[ "${final_ABI}" == "1" ]]; then
1314 "$(PYTHON -f)" -c "${python_command}" 1359 "$(PYTHON -f)" -c "${python_command}"
1466 for file in "${files[@]}"; do 1511 for file in "${files[@]}"; do
1467 file="${file#./}" 1512 file="${file#./}"
1468 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 1513 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1469 1514
1470 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 1515 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1516 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1517
1471 if [[ "${quiet}" == "0" ]]; then 1518 if [[ "${quiet}" == "0" ]]; then
1472 einfo "Converting shebang in '${file}'" 1519 einfo "Converting shebang in '${file}'"
1473 fi 1520 fi
1521
1474 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 1522 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1475 1523
1476 # Delete potential whitespace after "#!". 1524 # Delete potential whitespace after "#!".
1477 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 1525 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1478 fi 1526 fi
1479 done 1527 done
1528}
1529
1530# @FUNCTION: python_clean_sitedirs
1531# @DESCRIPTION:
1532# Delete needless files in site-packages directories in ${ED}.
1533python_clean_sitedirs() {
1534 _python_initialize_prefix_variables
1535
1536 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1480} 1537}
1481 1538
1482# ================================================================================================ 1539# ================================================================================================
1483# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1540# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1484# ================================================================================================ 1541# ================================================================================================
1487# @DESCRIPTION: 1544# @DESCRIPTION:
1488# User-configurable verbosity of tests of Python modules. 1545# User-configurable verbosity of tests of Python modules.
1489# Supported values: 0, 1, 2, 3, 4. 1546# Supported values: 0, 1, 2, 3, 4.
1490PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}" 1547PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
1491 1548
1549_python_test_hook() {
1550 if [[ "$#" -ne 1 ]]; then
1551 die "${FUNCNAME}() requires 1 argument"
1552 fi
1553
1554 if [[ -n "${SUPPORT_PYTHON_ABIS}" && "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
1555 "${FUNCNAME[3]}_$1_hook"
1556 fi
1557}
1558
1492# @FUNCTION: python_execute_nosetests 1559# @FUNCTION: python_execute_nosetests
1493# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1560# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1494# @DESCRIPTION: 1561# @DESCRIPTION:
1495# Execute nosetests for all enabled versions of Python. 1562# Execute nosetests for all enabled versions of Python.
1563# In ebuilds of packages supporting installation for multiple versions of Python, this function
1564# calls python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1496python_execute_nosetests() { 1565python_execute_nosetests() {
1497 _python_set_color_variables 1566 _python_set_color_variables
1498 1567
1499 local PYTHONPATH_template= separate_build_dirs= 1568 local PYTHONPATH_template= separate_build_dirs=
1500 1569
1529 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1598 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1530 unset evaluated_PYTHONPATH 1599 unset evaluated_PYTHONPATH
1531 fi 1600 fi
1532 fi 1601 fi
1533 1602
1603 _python_test_hook pre
1604
1534 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1605 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1535 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1606 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1536 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1607 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1537 else 1608 else
1538 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1609 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1539 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1610 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1540 fi 1611 fi
1612
1613 _python_test_hook post
1541 } 1614 }
1542 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1615 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1543 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1616 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1544 else 1617 else
1545 if [[ -n "${separate_build_dirs}" ]]; then 1618 if [[ -n "${separate_build_dirs}" ]]; then
1553 1626
1554# @FUNCTION: python_execute_py.test 1627# @FUNCTION: python_execute_py.test
1555# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1628# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1556# @DESCRIPTION: 1629# @DESCRIPTION:
1557# Execute py.test for all enabled versions of Python. 1630# Execute py.test for all enabled versions of Python.
1631# In ebuilds of packages supporting installation for multiple versions of Python, this function
1632# calls python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1558python_execute_py.test() { 1633python_execute_py.test() {
1559 _python_set_color_variables 1634 _python_set_color_variables
1560 1635
1561 local PYTHONPATH_template= separate_build_dirs= 1636 local PYTHONPATH_template= separate_build_dirs=
1562 1637
1591 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1666 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1592 unset evaluated_PYTHONPATH 1667 unset evaluated_PYTHONPATH
1593 fi 1668 fi
1594 fi 1669 fi
1595 1670
1671 _python_test_hook pre
1672
1596 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1673 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1597 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1674 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1598 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" 1675 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
1599 else 1676 else
1600 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} 1677 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
1601 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" 1678 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
1602 fi 1679 fi
1680
1681 _python_test_hook post
1603 } 1682 }
1604 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1683 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1605 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1684 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1606 else 1685 else
1607 if [[ -n "${separate_build_dirs}" ]]; then 1686 if [[ -n "${separate_build_dirs}" ]]; then
1615 1694
1616# @FUNCTION: python_execute_trial 1695# @FUNCTION: python_execute_trial
1617# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1696# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1618# @DESCRIPTION: 1697# @DESCRIPTION:
1619# Execute trial for all enabled versions of Python. 1698# Execute trial for all enabled versions of Python.
1699# In ebuilds of packages supporting installation for multiple versions of Python, this function
1700# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1620python_execute_trial() { 1701python_execute_trial() {
1621 _python_set_color_variables 1702 _python_set_color_variables
1622 1703
1623 local PYTHONPATH_template= separate_build_dirs= 1704 local PYTHONPATH_template= separate_build_dirs=
1624 1705
1653 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1734 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1654 unset evaluated_PYTHONPATH 1735 unset evaluated_PYTHONPATH
1655 fi 1736 fi
1656 fi 1737 fi
1657 1738
1739 _python_test_hook pre
1740
1658 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1741 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1659 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1742 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1660 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1743 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1661 else 1744 else
1662 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1745 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1663 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1746 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1664 fi 1747 fi
1748
1749 _python_test_hook post
1665 } 1750 }
1666 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1751 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1667 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1752 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1668 else 1753 else
1669 if [[ -n "${separate_build_dirs}" ]]; then 1754 if [[ -n "${separate_build_dirs}" ]]; then
1702# If no arguments supplied, it will recompile not recursively all modules 1787# If no arguments supplied, it will recompile not recursively all modules
1703# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). 1788# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1704# 1789#
1705# If supplied with arguments, it will recompile all modules recursively 1790# If supplied with arguments, it will recompile all modules recursively
1706# in the supplied directory. 1791# in the supplied directory.
1707# This function should only be run in pkg_postinst().
1708# 1792#
1709# Options passed to this function are passed to compileall.py. 1793# Options passed to this function are passed to compileall.py.
1710# 1794#
1711# Example: 1795# This function can be used only in pkg_postinst() phase.
1712# python_mod_optimize ctypesgencore
1713python_mod_optimize() { 1796python_mod_optimize() {
1714 _python_initialize_prefix_variables 1797 _python_initialize_prefix_variables
1715 1798
1716 # Check if phase is pkg_postinst(). 1799 # Check if phase is pkg_postinst().
1717 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 1800 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1718 1801
1719 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1802 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1720 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 1803 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1721 1804
1722 # Strip trailing slash from ROOT. 1805 # Strip trailing slash from ROOT.
1882# 1965#
1883# It will recursively scan all compiled Python modules in the directories and 1966# It will recursively scan all compiled Python modules in the directories and
1884# determine if they are orphaned (i.e. their corresponding .py files are missing.) 1967# determine if they are orphaned (i.e. their corresponding .py files are missing.)
1885# If they are, then it will remove their corresponding .pyc and .pyo files. 1968# If they are, then it will remove their corresponding .pyc and .pyo files.
1886# 1969#
1887# This function should only be run in pkg_postrm(). 1970# This function can be used only in pkg_postrm() phase.
1888python_mod_cleanup() { 1971python_mod_cleanup() {
1889 _python_initialize_prefix_variables 1972 _python_initialize_prefix_variables
1890 _python_set_color_variables 1973 _python_set_color_variables
1891 1974
1892 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 1975 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1893 1976
1894 # Check if phase is pkg_postrm(). 1977 # Check if phase is pkg_postrm().
1895 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" 1978 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1896 1979
1897 # Strip trailing slash from ROOT. 1980 # Strip trailing slash from ROOT.
1898 root="${EROOT%/}" 1981 root="${EROOT%/}"
1899 1982
1900 if (($#)); then 1983 if (($#)); then
1937 if [[ -d "${path}" ]]; then 2020 if [[ -d "${path}" ]]; then
1938 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do 2021 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
1939 if [[ "${REPLY}" == *[co] ]]; then 2022 if [[ "${REPLY}" == *[co] ]]; then
1940 py_file="${REPLY%[co]}" 2023 py_file="${REPLY%[co]}"
1941 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue 2024 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1942 einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" 2025 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
1943 rm -f "${py_file}"[co] 2026 rm -f "${py_file}"[co]
1944 elif [[ "${REPLY}" == *\$py.class ]]; then 2027 elif [[ "${REPLY}" == *\$py.class ]]; then
1945 py_file="${REPLY%\$py.class}.py" 2028 py_file="${REPLY%\$py.class}.py"
1946 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue 2029 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
1947 einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" 2030 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
1948 rm -f "${py_file%.py}\$py.class" 2031 rm -f "${py_file%.py}\$py.class"
1949 fi 2032 fi
1950 done 2033 done
1951 2034
1952 # Attempt to delete directories, which may be empty. 2035 # Attempt to delete directories, which may be empty.
1953 find "${path}" -type d | sort -r | while read -r dir; do 2036 find "${path}" -type d | sort -r | while read -r dir; do
1954 rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" 2037 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
1955 done 2038 done
1956 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then 2039 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
1957 if [[ (-f "${path}c" || -f "${path}o") ]]; then 2040 if [[ (-f "${path}c" || -f "${path}o") ]]; then
1958 einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" 2041 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
1959 rm -f "${path}"[co] 2042 rm -f "${path}"[co]
1960 fi 2043 fi
1961 if [[ -f "${path%.py}\$py.class" ]]; then 2044 if [[ -f "${path%.py}\$py.class" ]]; then
1962 einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" 2045 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
1963 rm -f "${path%.py}\$py.class" 2046 rm -f "${path%.py}\$py.class"
1964 fi 2047 fi
1965 fi 2048 fi
1966 done 2049 done
1967} 2050}
1976# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 2059# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
1977python_version() { 2060python_version() {
1978 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2061 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1979 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." 2062 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
1980 die "${FUNCNAME}() cannot be used in this EAPI" 2063 die "${FUNCNAME}() cannot be used in this EAPI"
2064 fi
2065
2066 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2067 einfo
2068 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2069 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2070 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2071 einfo
1981 fi 2072 fi
1982 2073
1983 [[ -n "${PYVER}" ]] && return 0 2074 [[ -n "${PYVER}" ]] && return 0
1984 local tmpstr 2075 local tmpstr
1985 python="${python:-${EPREFIX}/usr/bin/python}" 2076 python="${python:-${EPREFIX}/usr/bin/python}"
2009 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2100 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2010 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2101 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2011 die "${FUNCNAME}() cannot be used in this EAPI" 2102 die "${FUNCNAME}() cannot be used in this EAPI"
2012 fi 2103 fi
2013 2104
2105 einfo
2106 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2107 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2108 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2109 einfo
2110
2014 if [[ "$#" -ne 1 ]]; then 2111 if [[ "$#" -ne 1 ]]; then
2015 die "${FUNCNAME}() requires 1 argument" 2112 die "${FUNCNAME}() requires 1 argument"
2016 fi 2113 fi
2017 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2114 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2018} 2115}
2023# support. If not, prints an error message and dies. 2120# support. If not, prints an error message and dies.
2024python_tkinter_exists() { 2121python_tkinter_exists() {
2025 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2122 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2026 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2123 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2027 die "${FUNCNAME}() cannot be used in this EAPI" 2124 die "${FUNCNAME}() cannot be used in this EAPI"
2125 fi
2126
2127 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2128 einfo
2129 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2130 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2131 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2132 einfo
2028 fi 2133 fi
2029 2134
2030 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2135 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2031if version_info[0] == 3: 2136if version_info[0] == 3:
2032 import tkinter 2137 import tkinter
2041 2146
2042# @FUNCTION: python_mod_compile 2147# @FUNCTION: python_mod_compile
2043# @USAGE: <file> [more files ...] 2148# @USAGE: <file> [more files ...]
2044# @DESCRIPTION: 2149# @DESCRIPTION:
2045# Given filenames, it will pre-compile the module's .pyc and .pyo. 2150# Given filenames, it will pre-compile the module's .pyc and .pyo.
2046# This function should only be run in pkg_postinst() 2151# This function can be used only in pkg_postinst() phase.
2047# 2152#
2048# Example: 2153# Example:
2049# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py 2154# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2050# 2155#
2051python_mod_compile() { 2156python_mod_compile() {
2057 _python_initialize_prefix_variables 2162 _python_initialize_prefix_variables
2058 2163
2059 local f myroot myfiles=() 2164 local f myroot myfiles=()
2060 2165
2061 # Check if phase is pkg_postinst() 2166 # Check if phase is pkg_postinst()
2062 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 2167 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2063 2168
2064 # strip trailing slash 2169 # strip trailing slash
2065 myroot="${EROOT%/}" 2170 myroot="${EROOT%/}"
2066 2171
2067 # respect ROOT 2172 # respect ROOT

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.94

  ViewVC Help
Powered by ViewVC 1.1.20