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

Diff of /eclass/python.eclass

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

Revision 1.93 Revision 1.95
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.93 2010/03/12 18:27:01 betelgeuse Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 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
196 python_pkg_setup_fail() { 196 python_pkg_setup_fail() {
197 eerror "${1}" 197 eerror "${1}"
198 die "${1}" 198 die "${1}"
199 } 199 }
200 200
201 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return 201 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
202 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
203 use ${PYTHON_USE_WITH_OPT#!} && return
204 else
205 use !${PYTHON_USE_WITH_OPT} && return
206 fi
207 fi
202 208
203 python_pkg_setup_check_USE_flags() { 209 python_pkg_setup_check_USE_flags() {
204 local pyatom use 210 local pyatom use
205 pyatom="$(python_get_implementational_package)" 211 pyatom="$(python_get_implementational_package)"
206 212
219 if [[ ${PYTHON_USE_WITH_OR} ]]; then 225 if [[ ${PYTHON_USE_WITH_OR} ]]; then
220 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" 226 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
221 fi 227 fi
222 } 228 }
223 229
224 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 230 if _python_package_supporting_installation_for_multiple_python_abis; then
225 python_execute_function -q python_pkg_setup_check_USE_flags 231 python_execute_function -q python_pkg_setup_check_USE_flags
226 else 232 else
227 python_pkg_setup_check_USE_flags 233 python_pkg_setup_check_USE_flags
228 fi 234 fi
229 235
259fi 265fi
260 266
261unset _PYTHON_ATOMS 267unset _PYTHON_ATOMS
262 268
263# ================================================================================================ 269# ================================================================================================
264# ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ======== 270# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
265# ================================================================================================ 271# ================================================================================================
266 272
267# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 273# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
268# @DESCRIPTION: 274# @DESCRIPTION:
269# Set this in EAPI <= 4 to indicate that current package supports installation for 275# Set this in EAPI <= 4 to indicate that current package supports installation for
270# multiple versions of Python. 276# multiple Python ABIs.
271 277
272# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 278# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
273# @DESCRIPTION: 279# @DESCRIPTION:
274# Set this to export phase functions for the following ebuild phases: 280# Set this to export phase functions for the following ebuild phases:
275# src_prepare, src_configure, src_compile, src_test, src_install. 281# src_prepare, src_configure, src_compile, src_test, src_install.
276if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 282if ! has "${EAPI:-0}" 0 1; then
277 python_src_prepare() { 283 python_src_prepare() {
284 if ! _python_package_supporting_installation_for_multiple_python_abis; then
285 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
286 fi
287
278 python_copy_sources 288 python_copy_sources
279 } 289 }
280 290
281 for python_default_function in src_configure src_compile src_test src_install; do 291 for python_default_function in src_configure src_compile src_test src_install; do
282 eval "python_${python_default_function}() { python_execute_function -d -s; }" 292 eval "python_${python_default_function}() {
293 if ! _python_package_supporting_installation_for_multiple_python_abis; then
294 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
295 fi
296
297 python_execute_function -d -s \"\$@\"
298 }"
283 done 299 done
284 unset python_default_function 300 unset python_default_function
285 301
286 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 302 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
287 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 303 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
293# @FUNCTION: validate_PYTHON_ABIS 309# @FUNCTION: validate_PYTHON_ABIS
294# @DESCRIPTION: 310# @DESCRIPTION:
295# Ensure that PYTHON_ABIS variable has valid value. 311# Ensure that PYTHON_ABIS variable has valid value.
296# This function usually should not be directly called in ebuilds. 312# This function usually should not be directly called in ebuilds.
297validate_PYTHON_ABIS() { 313validate_PYTHON_ABIS() {
298 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable. 314 if ! _python_package_supporting_installation_for_multiple_python_abis; then
299 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 315 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
300 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
301 fi 316 fi
302 317
303 _python_initial_sanity_checks 318 _python_initial_sanity_checks
304 319
305 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. 320 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
306 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 321 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
307 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 322 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
308 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 323 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
309 324
310 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 325 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
311 local python2_enabled="0" python3_enabled="0" 326 local cpython_enabled="0"
312 327
313 if [[ -z "${USE_PYTHON}" ]]; then 328 if [[ -z "${USE_PYTHON}" ]]; then
314 die "USE_PYTHON variable is empty" 329 die "USE_PYTHON variable is empty"
315 fi 330 fi
316 331
317 for PYTHON_ABI in ${USE_PYTHON}; do 332 for PYTHON_ABI in ${USE_PYTHON}; do
318 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 333 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
319 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 334 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
320 fi 335 fi
321 336
322 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}"; then 337 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
323 python2_enabled="1" 338 cpython_enabled="1"
324 fi
325 if has "${PYTHON_ABI}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
326 python3_enabled="1"
327 fi 339 fi
328 340
329 support_ABI="1" 341 support_ABI="1"
330 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 342 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
331 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 343 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
335 done 347 done
336 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 348 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
337 done 349 done
338 350
339 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 351 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
340 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}" 352 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
341 fi 353 fi
342 354
343 if [[ "${python2_enabled}" == "0" ]]; then 355 if [[ "${cpython_enabled}" == "0" ]]; then
344 ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported."
345 fi
346 if [[ "${python3_enabled}" == "0" ]]; then
347 ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported."
348 fi
349 if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "0" ]]; then
350 die "USE_PYTHON variable does not enable any version of CPython" 356 die "USE_PYTHON variable does not enable any CPython ABI"
351 fi 357 fi
352 else 358 else
353 local python_version python2_version= python3_version= support_python_major_version 359 local python_version python2_version= python3_version= support_python_major_version
354 360
355 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 361 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
432# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] 438# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments]
433# @DESCRIPTION: 439# @DESCRIPTION:
434# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 440# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
435# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 441# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
436python_execute_function() { 442python_execute_function() {
443 if ! _python_package_supporting_installation_for_multiple_python_abis; then
444 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
445 fi
446
437 _python_set_color_variables 447 _python_set_color_variables
438 448
439 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= 449 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir=
440 450
441 while (($#)); do 451 while (($#)); do
494 504
495 if [[ -z "$(type -t "${function}")" ]]; then 505 if [[ -z "$(type -t "${function}")" ]]; then
496 die "${FUNCNAME}(): '${function}' function is not defined" 506 die "${FUNCNAME}(): '${function}' function is not defined"
497 fi 507 fi
498 else 508 else
499 if [[ "$#" -ne 0 ]]; then
500 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
501 fi
502 if has "${EAPI:-0}" 0 1; then 509 if has "${EAPI:-0}" 0 1; then
503 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" 510 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
504 fi 511 fi
505 512
506 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 513 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
507 if has "${EAPI}" 2 3; then 514 if has "${EAPI}" 2 3; then
508 python_default_function() { 515 python_default_function() {
509 econf 516 econf "$@"
510 } 517 }
511 else 518 else
512 python_default_function() { 519 python_default_function() {
513 nonfatal econf 520 nonfatal econf "$@"
514 } 521 }
515 fi 522 fi
516 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 523 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
517 python_default_function() { 524 python_default_function() {
518 emake 525 emake "$@"
519 } 526 }
520 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 527 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
521 python_default_function() { 528 python_default_function() {
522 if emake -j1 -n check &> /dev/null; then 529 if emake -j1 -n check &> /dev/null; then
523 emake -j1 check 530 emake -j1 check "$@"
524 elif emake -j1 -n test &> /dev/null; then 531 elif emake -j1 -n test &> /dev/null; then
525 emake -j1 test 532 emake -j1 test "$@"
526 fi 533 fi
527 } 534 }
528 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 535 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
529 python_default_function() { 536 python_default_function() {
530 emake DESTDIR="${D}" install 537 emake DESTDIR="${D}" install "$@"
531 } 538 }
532 else 539 else
533 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" 540 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
534 fi 541 fi
535 function="python_default_function" 542 function="python_default_function"
536 fi 543 fi
537 544
545 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
538 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 546 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do
539 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then 547 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
540 die "${FUNCNAME}(): Invalid call stack" 548 die "${FUNCNAME}(): Invalid call stack"
541 fi 549 fi
542 done 550 done
613 fi 621 fi
614 if [[ "${quiet}" == "0" ]]; then 622 if [[ "${quiet}" == "0" ]]; then
615 ewarn "${_RED}${failure_message}${_NORMAL}" 623 ewarn "${_RED}${failure_message}${_NORMAL}"
616 fi 624 fi
617 if [[ -z "${PYTHON_ABIS}" ]]; then 625 if [[ -z "${PYTHON_ABIS}" ]]; then
618 die "${function}() function failed with all enabled versions of Python" 626 die "${function}() function failed with all enabled Python ABIs"
619 fi 627 fi
620 else 628 else
621 die "${failure_message}" 629 die "${failure_message}"
622 fi 630 fi
623 fi 631 fi
657# @FUNCTION: python_copy_sources 665# @FUNCTION: python_copy_sources
658# @USAGE: <directory="${S}"> [directory] 666# @USAGE: <directory="${S}"> [directory]
659# @DESCRIPTION: 667# @DESCRIPTION:
660# Copy unpacked sources of current package to separate build directory for each Python ABI. 668# Copy unpacked sources of current package to separate build directory for each Python ABI.
661python_copy_sources() { 669python_copy_sources() {
670 if ! _python_package_supporting_installation_for_multiple_python_abis; then
671 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
672 fi
673
662 local dir dirs=() PYTHON_ABI 674 local dir dirs=() PYTHON_ABI
663 675
664 if [[ "$#" -eq 0 ]]; then 676 if [[ "$#" -eq 0 ]]; then
665 if [[ "${WORKDIR}" == "${S}" ]]; then 677 if [[ "${WORKDIR}" == "${S}" ]]; then
666 die "${FUNCNAME}() cannot be used" 678 die "${FUNCNAME}() cannot be used"
667 fi 679 fi
668 dirs=("${S}") 680 dirs=("${S%/}")
669 else 681 else
670 dirs=("$@") 682 dirs=("$@")
671 fi 683 fi
672 684
673 validate_PYTHON_ABIS 685 validate_PYTHON_ABIS
676 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 688 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
677 done 689 done
678 done 690 done
679} 691}
680 692
681# @FUNCTION: python_set_build_dir_symlink
682# @USAGE: <directory="build">
683# @DESCRIPTION:
684# Create build directory symlink.
685python_set_build_dir_symlink() {
686 local dir="$1"
687
688 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
689 [[ -z "${dir}" ]] && dir="build"
690
691 # Do not delete preexistent directories.
692 rm -f "${dir}" || die "Deletion of '${dir}' failed"
693 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
694}
695
696# @FUNCTION: python_generate_wrapper_scripts 693# @FUNCTION: python_generate_wrapper_scripts
697# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 694# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
698# @DESCRIPTION: 695# @DESCRIPTION:
699# Generate wrapper scripts. Existing files are overwritten only with --force option. 696# Generate wrapper scripts. Existing files are overwritten only with --force option.
700# If --respect-EPYTHON option is specified, then generated wrapper scripts will 697# If --respect-EPYTHON option is specified, then generated wrapper scripts will
701# respect EPYTHON variable at run time. 698# respect EPYTHON variable at run time.
702python_generate_wrapper_scripts() { 699python_generate_wrapper_scripts() {
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then
701 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi
703
703 _python_initialize_prefix_variables 704 _python_initialize_prefix_variables
704 705
705 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 706 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
706 707
707 while (($#)); do 708 while (($#)); do
759 if [[ -f "${file}" && "${force}" == "0" ]]; then 760 if [[ -f "${file}" && "${force}" == "0" ]]; then
760 die "${FUNCNAME}(): '$1' already exists" 761 die "${FUNCNAME}(): '$1' already exists"
761 fi 762 fi
762 763
763 if [[ "${quiet}" == "0" ]]; then 764 if [[ "${quiet}" == "0" ]]; then
764 einfo "Generating '${file#${D%/}}' wrapper script" 765 einfo "Generating '${file#${ED%/}}' wrapper script"
765 fi 766 fi
766 767
767 cat << EOF > "${file}" 768 cat << EOF > "${file}"
768#!/usr/bin/env python 769#!/usr/bin/env python
769# Gentoo '${file##*/}' wrapper script 770# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
770 771
771import os 772import os
772import re 773import re
773import subprocess 774import subprocess
774import sys 775import sys
775 776
776EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 777EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
778python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
779python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
777 780
778EOF 781EOF
779 if [[ "$?" != "0" ]]; then 782 if [[ "$?" != "0" ]]; then
780 die "${FUNCNAME}(): Generation of '$1' failed" 783 die "${FUNCNAME}(): Generation of '$1' failed"
781 fi 784 fi
796 raise ValueError 799 raise ValueError
797 except (OSError, ValueError): 800 except (OSError, ValueError):
798 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 801 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
799 sys.exit(1) 802 sys.exit(1)
800 803
801 eselect_output = eselect_process.stdout.read() 804 EPYTHON = eselect_process.stdout.read()
802 if not isinstance(eselect_output, str): 805 if not isinstance(EPYTHON, str):
803 # Python 3 806 # Python 3
804 eselect_output = eselect_output.decode() 807 EPYTHON = EPYTHON.decode()
808 EPYTHON = EPYTHON.rstrip("\n")
805 809
806 EPYTHON_matched = EPYTHON_re.match(eselect_output) 810 EPYTHON_matched = EPYTHON_re.match(EPYTHON)
807 if EPYTHON_matched: 811 if EPYTHON_matched:
808 PYTHON_ABI = EPYTHON_matched.group(1) 812 PYTHON_ABI = EPYTHON_matched.group(1)
809 else: 813 else:
810 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 814 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
811 sys.exit(1) 815 sys.exit(1)
812EOF 816EOF
813 if [[ "$?" != "0" ]]; then 817 if [[ "$?" != "0" ]]; then
814 die "${FUNCNAME}(): Generation of '$1' failed" 818 die "${FUNCNAME}(): Generation of '$1' failed"
815 fi 819 fi
821 raise ValueError 825 raise ValueError
822except (OSError, ValueError): 826except (OSError, ValueError):
823 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 827 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
824 sys.exit(1) 828 sys.exit(1)
825 829
826eselect_output = eselect_process.stdout.read() 830EPYTHON = eselect_process.stdout.read()
827if not isinstance(eselect_output, str): 831if not isinstance(EPYTHON, str):
828 # Python 3 832 # Python 3
829 eselect_output = eselect_output.decode() 833 EPYTHON = EPYTHON.decode()
834EPYTHON = EPYTHON.rstrip("\n")
830 835
831EPYTHON_matched = EPYTHON_re.match(eselect_output) 836EPYTHON_matched = EPYTHON_re.match(EPYTHON)
832if EPYTHON_matched: 837if EPYTHON_matched:
833 PYTHON_ABI = EPYTHON_matched.group(1) 838 PYTHON_ABI = EPYTHON_matched.group(1)
834else: 839else:
835 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 840 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
836 sys.exit(1) 841 sys.exit(1)
837EOF 842EOF
838 if [[ "$?" != "0" ]]; then 843 if [[ "$?" != "0" ]]; then
839 die "${FUNCNAME}(): Generation of '$1' failed" 844 die "${FUNCNAME}(): Generation of '$1' failed"
840 fi 845 fi
841 fi 846 fi
842 cat << EOF >> "${file}" 847 cat << EOF >> "${file}"
843 848
849wrapper_script_path = os.path.realpath(sys.argv[0])
850target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
844os.environ["PYTHON_SCRIPT_NAME"] = sys.argv[0] 851os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
845target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) 852os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
846if not os.path.exists(target_executable): 853if not os.path.exists(target_executable_path):
847 sys.stderr.write("'%s' does not exist\n" % target_executable) 854 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
848 sys.exit(1) 855 sys.exit(1)
849 856
857target_executable = open(target_executable_path, "rb")
858target_executable_first_line = target_executable.readline()
859if not isinstance(target_executable_first_line, str):
860 # Python 3
861 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
862
863python_shebang_matched = python_shebang_re.match(target_executable_first_line)
864target_executable.close()
865
866if python_shebang_matched:
867 try:
868 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
869 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
870 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
871 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
872 if python_verification_process.wait() != 0:
873 raise ValueError
874
875 python_verification_output = python_verification_process.stdout.read()
876 if not isinstance(python_verification_output, str):
877 # Python 3
878 python_verification_output = python_verification_output.decode()
879
880 if not python_verification_output_re.match(python_verification_output):
881 raise ValueError
882
883 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
884 except:
885 pass
886 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
887 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
888
850os.execv(target_executable, sys.argv) 889os.execv(target_executable_path, sys.argv)
851EOF 890EOF
852 if [[ "$?" != "0" ]]; then 891 if [[ "$?" != "0" ]]; then
853 die "${FUNCNAME}(): Generation of '$1' failed" 892 die "${FUNCNAME}(): Generation of '$1' failed"
854 fi 893 fi
855 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 894 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
856 done 895 done
857} 896}
858 897
859# ================================================================================================ 898# ================================================================================================
860# ====== FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ====== 899# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
861# ================================================================================================ 900# ================================================================================================
862 901
863# @FUNCTION: python_set_active_version 902# @FUNCTION: python_set_active_version
864# @USAGE: <CPython_ABI|2|3> 903# @USAGE: <CPython_ABI|2|3>
865# @DESCRIPTION: 904# @DESCRIPTION:
866# Set specified version of CPython as active version of Python. 905# Set specified version of CPython as active version of Python.
867python_set_active_version() { 906python_set_active_version() {
868 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 907 if _python_package_supporting_installation_for_multiple_python_abis; then
869 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 908 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
870 fi 909 fi
871 910
872 if [[ "$#" -ne 1 ]]; then 911 if [[ "$#" -ne 1 ]]; then
873 die "${FUNCNAME}() requires 1 argument" 912 die "${FUNCNAME}() requires 1 argument"
874 fi 913 fi
907 946
908# @FUNCTION: python_need_rebuild 947# @FUNCTION: python_need_rebuild
909# @DESCRIPTION: Mark current package for rebuilding by python-updater after 948# @DESCRIPTION: Mark current package for rebuilding by python-updater after
910# switching of active version of Python. 949# switching of active version of Python.
911python_need_rebuild() { 950python_need_rebuild() {
912 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 951 if _python_package_supporting_installation_for_multiple_python_abis; then
913 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 952 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
914 fi 953 fi
915 954
916 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 955 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
917} 956}
918 957
995 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1034 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
996 fi 1035 fi
997 1036
998 if [[ "$#" -eq 0 ]]; then 1037 if [[ "$#" -eq 0 ]]; then
999 if [[ "${final_ABI}" == "1" ]]; then 1038 if [[ "${final_ABI}" == "1" ]]; then
1000 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1039 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1001 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" 1040 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1002 fi 1041 fi
1003 validate_PYTHON_ABIS 1042 validate_PYTHON_ABIS
1004 PYTHON_ABI="${PYTHON_ABIS##* }" 1043 PYTHON_ABI="${PYTHON_ABIS##* }"
1005 elif [[ "${python2}" == "1" ]]; then 1044 elif [[ "${python2}" == "1" ]]; then
1006 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1045 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1014 if [[ -z "${PYTHON_ABI}" ]]; then 1053 if [[ -z "${PYTHON_ABI}" ]]; then
1015 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1054 die "${FUNCNAME}(): Active Python 3 interpreter not set"
1016 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1055 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1017 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1056 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1018 fi 1057 fi
1019 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1058 elif ! _python_package_supporting_installation_for_multiple_python_abis; then
1020 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1059 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1021 elif [[ -z "${PYTHON_ABI}" ]]; then 1060 elif [[ -z "${PYTHON_ABI}" ]]; then
1022 die "${FUNCNAME}(): Invalid usage: Python ABI not specified" 1061 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1023 fi 1062 fi
1024 elif [[ "$#" -eq 1 ]]; then 1063 elif [[ "$#" -eq 1 ]]; then
1025 if [[ "${final_ABI}" == "1" ]]; then 1064 if [[ "${final_ABI}" == "1" ]]; then
1026 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1065 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1027 fi 1066 fi
1080 esac 1119 esac
1081 shift 1120 shift
1082 done 1121 done
1083 1122
1084 if [[ "${final_ABI}" == "1" ]]; then 1123 if [[ "${final_ABI}" == "1" ]]; then
1124 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1125 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1126 fi
1085 PYTHON_ABI="$(PYTHON -f --ABI)" 1127 PYTHON_ABI="$(PYTHON -f --ABI)"
1086 elif [[ -z "${PYTHON_ABI}" ]]; then 1128 elif [[ -z "${PYTHON_ABI}" ]]; then
1087 PYTHON_ABI="$(PYTHON --ABI)" 1129 PYTHON_ABI="$(PYTHON --ABI)"
1088 fi 1130 fi
1089 1131
1112 esac 1154 esac
1113 shift 1155 shift
1114 done 1156 done
1115 1157
1116 if [[ "${final_ABI}" == "1" ]]; then 1158 if [[ "${final_ABI}" == "1" ]]; then
1159 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1160 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1161 fi
1117 PYTHON_ABI="$(PYTHON -f --ABI)" 1162 PYTHON_ABI="$(PYTHON -f --ABI)"
1118 elif [[ -z "${PYTHON_ABI}" ]]; then 1163 elif [[ -z "${PYTHON_ABI}" ]]; then
1119 PYTHON_ABI="$(PYTHON --ABI)" 1164 PYTHON_ABI="$(PYTHON --ABI)"
1120 fi 1165 fi
1121 1166
1148 esac 1193 esac
1149 shift 1194 shift
1150 done 1195 done
1151 1196
1152 if [[ "${final_ABI}" == "1" ]]; then 1197 if [[ "${final_ABI}" == "1" ]]; then
1198 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1199 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1200 fi
1153 PYTHON_ABI="$(PYTHON -f --ABI)" 1201 PYTHON_ABI="$(PYTHON -f --ABI)"
1154 elif [[ -z "${PYTHON_ABI}" ]]; then 1202 elif [[ -z "${PYTHON_ABI}" ]]; then
1155 PYTHON_ABI="$(PYTHON --ABI)" 1203 PYTHON_ABI="$(PYTHON --ABI)"
1156 fi 1204 fi
1157 1205
1184 esac 1232 esac
1185 shift 1233 shift
1186 done 1234 done
1187 1235
1188 if [[ "${final_ABI}" == "1" ]]; then 1236 if [[ "${final_ABI}" == "1" ]]; then
1237 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1238 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1239 fi
1189 PYTHON_ABI="$(PYTHON -f --ABI)" 1240 PYTHON_ABI="$(PYTHON -f --ABI)"
1190 elif [[ -z "${PYTHON_ABI}" ]]; then 1241 elif [[ -z "${PYTHON_ABI}" ]]; then
1191 PYTHON_ABI="$(PYTHON --ABI)" 1242 PYTHON_ABI="$(PYTHON --ABI)"
1192 fi 1243 fi
1193 1244
1207 local options=() 1258 local options=()
1208 1259
1209 while (($#)); do 1260 while (($#)); do
1210 case "$1" in 1261 case "$1" in
1211 -f|--final-ABI) 1262 -f|--final-ABI)
1263 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1264 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1265 fi
1212 options+=("$1") 1266 options+=("$1")
1213 ;; 1267 ;;
1214 -*) 1268 -*)
1215 die "${FUNCNAME}(): Unrecognized option '$1'" 1269 die "${FUNCNAME}(): Unrecognized option '$1'"
1216 ;; 1270 ;;
1250 esac 1304 esac
1251 shift 1305 shift
1252 done 1306 done
1253 1307
1254 if [[ "${final_ABI}" == "1" ]]; then 1308 if [[ "${final_ABI}" == "1" ]]; then
1309 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1310 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1311 fi
1255 PYTHON_ABI="$(PYTHON -f --ABI)" 1312 PYTHON_ABI="$(PYTHON -f --ABI)"
1256 elif [[ -z "${PYTHON_ABI}" ]]; then 1313 elif [[ -z "${PYTHON_ABI}" ]]; then
1257 PYTHON_ABI="$(PYTHON --ABI)" 1314 PYTHON_ABI="$(PYTHON --ABI)"
1258 fi 1315 fi
1259 1316
1328 fi 1385 fi
1329 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" 1386 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1330 fi 1387 fi
1331 1388
1332 if [[ "${final_ABI}" == "1" ]]; then 1389 if [[ "${final_ABI}" == "1" ]]; then
1390 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1391 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1392 fi
1333 "$(PYTHON -f)" -c "${python_command}" 1393 "$(PYTHON -f)" -c "${python_command}"
1334 else 1394 else
1335 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1395 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1336 fi 1396 fi
1337} 1397}
1345 return 0 1405 return 0
1346 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then 1406 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1347 return 0 1407 return 0
1348 else 1408 else
1349 return 1 1409 return 1
1410 fi
1411}
1412
1413_python_package_supporting_installation_for_multiple_python_abis() {
1414 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1415 die "${FUNCNAME}() cannot be used in global scope"
1416 fi
1417
1418 if has "${EAPI:-0}" 0 1 2 3 4; then
1419 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1420 return 0
1421 else
1422 return 1
1423 fi
1424 else
1425 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1350 fi 1426 fi
1351} 1427}
1352 1428
1353_python_initialize_prefix_variables() { 1429_python_initialize_prefix_variables() {
1354 if has "${EAPI:-0}" 0 1 2; then 1430 if has "${EAPI:-0}" 0 1 2; then
1467 die "${FUNCNAME}(): '${argument}' does not exist" 1543 die "${FUNCNAME}(): '${argument}' does not exist"
1468 elif [[ -f "${argument}" ]]; then 1544 elif [[ -f "${argument}" ]]; then
1469 files+=("${argument}") 1545 files+=("${argument}")
1470 elif [[ -d "${argument}" ]]; then 1546 elif [[ -d "${argument}" ]]; then
1471 if [[ "${recursive}" == "1" ]]; then 1547 if [[ "${recursive}" == "1" ]]; then
1472 if [[ "${only_executables}" == "1" ]]; then 1548 while read -d $'\0' -r file; do
1473 files+=($(find "${argument}" -perm /111 -type f)) 1549 files+=("${file}")
1474 else 1550 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1475 files+=($(find "${argument}" -type f))
1476 fi
1477 else 1551 else
1478 die "${FUNCNAME}(): '${argument}' is not a regular file" 1552 die "${FUNCNAME}(): '${argument}' is not a regular file"
1479 fi 1553 fi
1480 else 1554 else
1481 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" 1555 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1485 for file in "${files[@]}"; do 1559 for file in "${files[@]}"; do
1486 file="${file#./}" 1560 file="${file#./}"
1487 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 1561 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1488 1562
1489 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 1563 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1564 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1565
1490 if [[ "${quiet}" == "0" ]]; then 1566 if [[ "${quiet}" == "0" ]]; then
1491 einfo "Converting shebang in '${file}'" 1567 einfo "Converting shebang in '${file}'"
1492 fi 1568 fi
1569
1493 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 1570 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1494 1571
1495 # Delete potential whitespace after "#!". 1572 # Delete potential whitespace after "#!".
1496 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 1573 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1497 fi 1574 fi
1498 done 1575 done
1576}
1577
1578# @FUNCTION: python_clean_sitedirs
1579# @DESCRIPTION:
1580# Delete needless files in site-packages directories in ${ED}.
1581python_clean_sitedirs() {
1582 _python_initialize_prefix_variables
1583
1584 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1499} 1585}
1500 1586
1501# ================================================================================================ 1587# ================================================================================================
1502# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1588# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1503# ================================================================================================ 1589# ================================================================================================
1511_python_test_hook() { 1597_python_test_hook() {
1512 if [[ "$#" -ne 1 ]]; then 1598 if [[ "$#" -ne 1 ]]; then
1513 die "${FUNCNAME}() requires 1 argument" 1599 die "${FUNCNAME}() requires 1 argument"
1514 fi 1600 fi
1515 1601
1516 if [[ -n "${SUPPORT_PYTHON_ABIS}" && "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then 1602 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
1517 "${FUNCNAME[3]}_$1_hook" 1603 "${FUNCNAME[3]}_$1_hook"
1518 fi 1604 fi
1519} 1605}
1520 1606
1521# @FUNCTION: python_execute_nosetests 1607# @FUNCTION: python_execute_nosetests
1522# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1608# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1523# @DESCRIPTION: 1609# @DESCRIPTION:
1524# Execute nosetests for all enabled versions of Python. 1610# Execute nosetests for all enabled Python ABIs.
1525# In ebuilds of packages supporting installation for multiple versions of Python, this function 1611# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1526# calls python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 1612# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1527python_execute_nosetests() { 1613python_execute_nosetests() {
1528 _python_set_color_variables 1614 _python_set_color_variables
1529 1615
1530 local PYTHONPATH_template= separate_build_dirs= 1616 local PYTHONPATH_template= separate_build_dirs=
1531 1617
1572 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 1658 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1573 fi 1659 fi
1574 1660
1575 _python_test_hook post 1661 _python_test_hook post
1576 } 1662 }
1577 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1663 if _python_package_supporting_installation_for_multiple_python_abis; then
1578 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1664 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1579 else 1665 else
1580 if [[ -n "${separate_build_dirs}" ]]; then 1666 if [[ -n "${separate_build_dirs}" ]]; then
1581 die "${FUNCNAME}(): Invalid usage" 1667 die "${FUNCNAME}(): Invalid usage"
1582 fi 1668 fi
1587} 1673}
1588 1674
1589# @FUNCTION: python_execute_py.test 1675# @FUNCTION: python_execute_py.test
1590# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1676# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1591# @DESCRIPTION: 1677# @DESCRIPTION:
1592# Execute py.test for all enabled versions of Python. 1678# Execute py.test for all enabled Python ABIs.
1593# In ebuilds of packages supporting installation for multiple versions of Python, this function 1679# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1594# calls python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 1680# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1595python_execute_py.test() { 1681python_execute_py.test() {
1596 _python_set_color_variables 1682 _python_set_color_variables
1597 1683
1598 local PYTHONPATH_template= separate_build_dirs= 1684 local PYTHONPATH_template= separate_build_dirs=
1599 1685
1640 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" 1726 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
1641 fi 1727 fi
1642 1728
1643 _python_test_hook post 1729 _python_test_hook post
1644 } 1730 }
1645 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1731 if _python_package_supporting_installation_for_multiple_python_abis; then
1646 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1732 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1647 else 1733 else
1648 if [[ -n "${separate_build_dirs}" ]]; then 1734 if [[ -n "${separate_build_dirs}" ]]; then
1649 die "${FUNCNAME}(): Invalid usage" 1735 die "${FUNCNAME}(): Invalid usage"
1650 fi 1736 fi
1655} 1741}
1656 1742
1657# @FUNCTION: python_execute_trial 1743# @FUNCTION: python_execute_trial
1658# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1744# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1659# @DESCRIPTION: 1745# @DESCRIPTION:
1660# Execute trial for all enabled versions of Python. 1746# Execute trial for all enabled Python ABIs.
1661# In ebuilds of packages supporting installation for multiple versions of Python, this function 1747# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1662# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 1748# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1663python_execute_trial() { 1749python_execute_trial() {
1664 _python_set_color_variables 1750 _python_set_color_variables
1665 1751
1666 local PYTHONPATH_template= separate_build_dirs= 1752 local PYTHONPATH_template= separate_build_dirs=
1708 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 1794 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1709 fi 1795 fi
1710 1796
1711 _python_test_hook post 1797 _python_test_hook post
1712 } 1798 }
1713 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1799 if _python_package_supporting_installation_for_multiple_python_abis; then
1714 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1800 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1715 else 1801 else
1716 if [[ -n "${separate_build_dirs}" ]]; then 1802 if [[ -n "${separate_build_dirs}" ]]; then
1717 die "${FUNCNAME}(): Invalid usage" 1803 die "${FUNCNAME}(): Invalid usage"
1718 fi 1804 fi
1757# This function can be used only in pkg_postinst() phase. 1843# This function can be used only in pkg_postinst() phase.
1758python_mod_optimize() { 1844python_mod_optimize() {
1759 _python_initialize_prefix_variables 1845 _python_initialize_prefix_variables
1760 1846
1761 # Check if phase is pkg_postinst(). 1847 # Check if phase is pkg_postinst().
1762 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 1848 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1763 1849
1764 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1850 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1765 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=() 1851 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=()
1766 1852
1767 # Strip trailing slash from ROOT. 1853 # Strip trailing slash from ROOT.
1768 root="${EROOT%/}" 1854 root="${EROOT%/}"
1769 1855
1935 _python_set_color_variables 2021 _python_set_color_variables
1936 2022
1937 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2023 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1938 2024
1939 # Check if phase is pkg_postrm(). 2025 # Check if phase is pkg_postrm().
1940 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2026 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1941 2027
1942 # Strip trailing slash from ROOT. 2028 # Strip trailing slash from ROOT.
1943 root="${EROOT%/}" 2029 root="${EROOT%/}"
1944 2030
1945 if (($#)); then 2031 if (($#)); then
1946 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2032 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1947 while (($#)); do 2033 while (($#)); do
1948 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2034 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1949 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 2035 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1950 elif [[ "$1" =~ ^/ ]]; then 2036 elif [[ "$1" =~ ^/ ]]; then
1951 SEARCH_PATH+=("${root}/${1#/}") 2037 SEARCH_PATH+=("${root}/${1#/}")
1982 if [[ -d "${path}" ]]; then 2068 if [[ -d "${path}" ]]; then
1983 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do 2069 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
1984 if [[ "${REPLY}" == *[co] ]]; then 2070 if [[ "${REPLY}" == *[co] ]]; then
1985 py_file="${REPLY%[co]}" 2071 py_file="${REPLY%[co]}"
1986 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue 2072 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1987 einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" 2073 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
1988 rm -f "${py_file}"[co] 2074 rm -f "${py_file}"[co]
1989 elif [[ "${REPLY}" == *\$py.class ]]; then 2075 elif [[ "${REPLY}" == *\$py.class ]]; then
1990 py_file="${REPLY%\$py.class}.py" 2076 py_file="${REPLY%\$py.class}.py"
1991 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue 2077 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
1992 einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" 2078 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
1993 rm -f "${py_file%.py}\$py.class" 2079 rm -f "${py_file%.py}\$py.class"
1994 fi 2080 fi
1995 done 2081 done
1996 2082
1997 # Attempt to delete directories, which may be empty. 2083 # Attempt to delete directories, which may be empty.
1998 find "${path}" -type d | sort -r | while read -r dir; do 2084 find "${path}" -type d | sort -r | while read -r dir; do
1999 rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" 2085 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
2000 done 2086 done
2001 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then 2087 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
2002 if [[ (-f "${path}c" || -f "${path}o") ]]; then 2088 if [[ (-f "${path}c" || -f "${path}o") ]]; then
2003 einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" 2089 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
2004 rm -f "${path}"[co] 2090 rm -f "${path}"[co]
2005 fi 2091 fi
2006 if [[ -f "${path%.py}\$py.class" ]]; then 2092 if [[ -f "${path%.py}\$py.class" ]]; then
2007 einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" 2093 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2008 rm -f "${path%.py}\$py.class" 2094 rm -f "${path%.py}\$py.class"
2009 fi 2095 fi
2010 fi 2096 fi
2011 done 2097 done
2012} 2098}
2018# @FUNCTION: python_version 2104# @FUNCTION: python_version
2019# @DESCRIPTION: 2105# @DESCRIPTION:
2020# Run without arguments and it will export the version of python 2106# Run without arguments and it will export the version of python
2021# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 2107# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2022python_version() { 2108python_version() {
2023 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2109 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2024 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." 2110 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2025 die "${FUNCNAME}() cannot be used in this EAPI" 2111 die "${FUNCNAME}() cannot be used in this EAPI"
2026 fi 2112 fi
2027 2113
2114 _python_set_color_variables
2115
2028 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then 2116 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2029 einfo 2117 echo
2118 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2119 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2120 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2121 echo
2122
2123 einfo &> /dev/null
2030 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2124 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2031 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." 2125 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null
2032 einfo 2126 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2127 einfo &> /dev/null
2033 fi 2128 fi
2034 2129
2035 [[ -n "${PYVER}" ]] && return 0 2130 [[ -n "${PYVER}" ]] && return 0
2036 local tmpstr 2131 local tmpstr
2037 python="${python:-${EPREFIX}/usr/bin/python}" 2132 python="${python:-${EPREFIX}/usr/bin/python}"
2056# Example: 2151# Example:
2057# if python_mod_exists gtk; then 2152# if python_mod_exists gtk; then
2058# echo "gtk support enabled" 2153# echo "gtk support enabled"
2059# fi 2154# fi
2060python_mod_exists() { 2155python_mod_exists() {
2061 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2156 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2062 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2157 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2063 die "${FUNCNAME}() cannot be used in this EAPI" 2158 die "${FUNCNAME}() cannot be used in this EAPI"
2064 fi 2159 fi
2065 2160
2066 einfo 2161 echo
2162 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2163 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2165 echo
2166
2167 einfo &> /dev/null
2067 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2168 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2068 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2169 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2069 einfo 2170 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2171 einfo &> /dev/null
2070 2172
2071 if [[ "$#" -ne 1 ]]; then 2173 if [[ "$#" -ne 1 ]]; then
2072 die "${FUNCNAME}() requires 1 argument" 2174 die "${FUNCNAME}() requires 1 argument"
2073 fi 2175 fi
2074 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2176 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2077# @FUNCTION: python_tkinter_exists 2179# @FUNCTION: python_tkinter_exists
2078# @DESCRIPTION: 2180# @DESCRIPTION:
2079# Run without arguments, checks if Python was compiled with Tkinter 2181# Run without arguments, checks if Python was compiled with Tkinter
2080# support. If not, prints an error message and dies. 2182# support. If not, prints an error message and dies.
2081python_tkinter_exists() { 2183python_tkinter_exists() {
2082 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2184 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2083 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2185 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2084 die "${FUNCNAME}() cannot be used in this EAPI" 2186 die "${FUNCNAME}() cannot be used in this EAPI"
2085 fi 2187 fi
2086 2188
2087 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then 2189 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2088 einfo 2190 echo
2191 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2192 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2194 echo
2195
2196 einfo &> /dev/null
2089 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2197 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2090 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2198 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2091 einfo 2199 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2200 einfo &> /dev/null
2092 fi 2201 fi
2093 2202
2094 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2203 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2095if version_info[0] == 3: 2204if version_info[0] == 3:
2096 import tkinter 2205 import tkinter
2111# 2220#
2112# Example: 2221# Example:
2113# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py 2222# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2114# 2223#
2115python_mod_compile() { 2224python_mod_compile() {
2116 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2225 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2117 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2226 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2118 die "${FUNCNAME}() cannot be used in this EAPI" 2227 die "${FUNCNAME}() cannot be used in this EAPI"
2119 fi 2228 fi
2120 2229
2121 _python_initialize_prefix_variables 2230 _python_initialize_prefix_variables
2122 2231
2123 local f myroot myfiles=() 2232 local f myroot myfiles=()
2124 2233
2125 # Check if phase is pkg_postinst() 2234 # Check if phase is pkg_postinst()
2126 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2235 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2127 2236
2128 # strip trailing slash 2237 # strip trailing slash
2129 myroot="${EROOT%/}" 2238 myroot="${EROOT%/}"
2130 2239
2131 # respect ROOT 2240 # respect ROOT

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.95

  ViewVC Help
Powered by ViewVC 1.1.20