/[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.96
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.96 2010/03/26 15:23:17 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)
851os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
844os.environ["PYTHON_SCRIPT_NAME"] = sys.argv[0] 852os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
845target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) 853os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
846if not os.path.exists(target_executable): 854if not os.path.exists(target_executable_path):
847 sys.stderr.write("'%s' does not exist\n" % target_executable) 855 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
848 sys.exit(1) 856 sys.exit(1)
849 857
858target_executable = open(target_executable_path, "rb")
859target_executable_first_line = target_executable.readline()
860if not isinstance(target_executable_first_line, str):
861 # Python 3
862 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
863
864python_shebang_matched = python_shebang_re.match(target_executable_first_line)
865target_executable.close()
866
867if python_shebang_matched:
868 try:
869 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
870 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
871 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
872 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
873 if python_verification_process.wait() != 0:
874 raise ValueError
875
876 python_verification_output = python_verification_process.stdout.read()
877 if not isinstance(python_verification_output, str):
878 # Python 3
879 python_verification_output = python_verification_output.decode()
880
881 if not python_verification_output_re.match(python_verification_output):
882 raise ValueError
883
884 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
885 except:
886 pass
887 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
888 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
889
850os.execv(target_executable, sys.argv) 890os.execv(target_executable_path, sys.argv)
851EOF 891EOF
852 if [[ "$?" != "0" ]]; then 892 if [[ "$?" != "0" ]]; then
853 die "${FUNCNAME}(): Generation of '$1' failed" 893 die "${FUNCNAME}(): Generation of '$1' failed"
854 fi 894 fi
855 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 895 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
856 done 896 done
857} 897}
858 898
859# ================================================================================================ 899# ================================================================================================
860# ====== FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ====== 900# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
861# ================================================================================================ 901# ================================================================================================
862 902
863# @FUNCTION: python_set_active_version 903# @FUNCTION: python_set_active_version
864# @USAGE: <CPython_ABI|2|3> 904# @USAGE: <CPython_ABI|2|3>
865# @DESCRIPTION: 905# @DESCRIPTION:
866# Set specified version of CPython as active version of Python. 906# Set specified version of CPython as active version of Python.
867python_set_active_version() { 907python_set_active_version() {
868 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 908 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" 909 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
870 fi 910 fi
871 911
872 if [[ "$#" -ne 1 ]]; then 912 if [[ "$#" -ne 1 ]]; then
873 die "${FUNCNAME}() requires 1 argument" 913 die "${FUNCNAME}() requires 1 argument"
874 fi 914 fi
907 947
908# @FUNCTION: python_need_rebuild 948# @FUNCTION: python_need_rebuild
909# @DESCRIPTION: Mark current package for rebuilding by python-updater after 949# @DESCRIPTION: Mark current package for rebuilding by python-updater after
910# switching of active version of Python. 950# switching of active version of Python.
911python_need_rebuild() { 951python_need_rebuild() {
912 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 952 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" 953 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
914 fi 954 fi
915 955
916 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 956 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
917} 957}
918 958
995 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1035 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
996 fi 1036 fi
997 1037
998 if [[ "$#" -eq 0 ]]; then 1038 if [[ "$#" -eq 0 ]]; then
999 if [[ "${final_ABI}" == "1" ]]; then 1039 if [[ "${final_ABI}" == "1" ]]; then
1000 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1040 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" 1041 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1002 fi 1042 fi
1003 validate_PYTHON_ABIS 1043 validate_PYTHON_ABIS
1004 PYTHON_ABI="${PYTHON_ABIS##* }" 1044 PYTHON_ABI="${PYTHON_ABIS##* }"
1005 elif [[ "${python2}" == "1" ]]; then 1045 elif [[ "${python2}" == "1" ]]; then
1006 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1046 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1014 if [[ -z "${PYTHON_ABI}" ]]; then 1054 if [[ -z "${PYTHON_ABI}" ]]; then
1015 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1055 die "${FUNCNAME}(): Active Python 3 interpreter not set"
1016 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1056 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1017 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1057 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1018 fi 1058 fi
1019 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1059 elif ! _python_package_supporting_installation_for_multiple_python_abis; then
1020 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1060 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1021 elif [[ -z "${PYTHON_ABI}" ]]; then 1061 elif [[ -z "${PYTHON_ABI}" ]]; then
1022 die "${FUNCNAME}(): Invalid usage: Python ABI not specified" 1062 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1023 fi 1063 fi
1024 elif [[ "$#" -eq 1 ]]; then 1064 elif [[ "$#" -eq 1 ]]; then
1025 if [[ "${final_ABI}" == "1" ]]; then 1065 if [[ "${final_ABI}" == "1" ]]; then
1026 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1066 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1027 fi 1067 fi
1080 esac 1120 esac
1081 shift 1121 shift
1082 done 1122 done
1083 1123
1084 if [[ "${final_ABI}" == "1" ]]; then 1124 if [[ "${final_ABI}" == "1" ]]; then
1125 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1126 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1127 fi
1085 PYTHON_ABI="$(PYTHON -f --ABI)" 1128 PYTHON_ABI="$(PYTHON -f --ABI)"
1086 elif [[ -z "${PYTHON_ABI}" ]]; then 1129 elif [[ -z "${PYTHON_ABI}" ]]; then
1087 PYTHON_ABI="$(PYTHON --ABI)" 1130 PYTHON_ABI="$(PYTHON --ABI)"
1088 fi 1131 fi
1089 1132
1112 esac 1155 esac
1113 shift 1156 shift
1114 done 1157 done
1115 1158
1116 if [[ "${final_ABI}" == "1" ]]; then 1159 if [[ "${final_ABI}" == "1" ]]; then
1160 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1161 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1162 fi
1117 PYTHON_ABI="$(PYTHON -f --ABI)" 1163 PYTHON_ABI="$(PYTHON -f --ABI)"
1118 elif [[ -z "${PYTHON_ABI}" ]]; then 1164 elif [[ -z "${PYTHON_ABI}" ]]; then
1119 PYTHON_ABI="$(PYTHON --ABI)" 1165 PYTHON_ABI="$(PYTHON --ABI)"
1120 fi 1166 fi
1121 1167
1148 esac 1194 esac
1149 shift 1195 shift
1150 done 1196 done
1151 1197
1152 if [[ "${final_ABI}" == "1" ]]; then 1198 if [[ "${final_ABI}" == "1" ]]; then
1199 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1200 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1201 fi
1153 PYTHON_ABI="$(PYTHON -f --ABI)" 1202 PYTHON_ABI="$(PYTHON -f --ABI)"
1154 elif [[ -z "${PYTHON_ABI}" ]]; then 1203 elif [[ -z "${PYTHON_ABI}" ]]; then
1155 PYTHON_ABI="$(PYTHON --ABI)" 1204 PYTHON_ABI="$(PYTHON --ABI)"
1156 fi 1205 fi
1157 1206
1184 esac 1233 esac
1185 shift 1234 shift
1186 done 1235 done
1187 1236
1188 if [[ "${final_ABI}" == "1" ]]; then 1237 if [[ "${final_ABI}" == "1" ]]; then
1238 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1239 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1240 fi
1189 PYTHON_ABI="$(PYTHON -f --ABI)" 1241 PYTHON_ABI="$(PYTHON -f --ABI)"
1190 elif [[ -z "${PYTHON_ABI}" ]]; then 1242 elif [[ -z "${PYTHON_ABI}" ]]; then
1191 PYTHON_ABI="$(PYTHON --ABI)" 1243 PYTHON_ABI="$(PYTHON --ABI)"
1192 fi 1244 fi
1193 1245
1207 local options=() 1259 local options=()
1208 1260
1209 while (($#)); do 1261 while (($#)); do
1210 case "$1" in 1262 case "$1" in
1211 -f|--final-ABI) 1263 -f|--final-ABI)
1264 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1265 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1266 fi
1212 options+=("$1") 1267 options+=("$1")
1213 ;; 1268 ;;
1214 -*) 1269 -*)
1215 die "${FUNCNAME}(): Unrecognized option '$1'" 1270 die "${FUNCNAME}(): Unrecognized option '$1'"
1216 ;; 1271 ;;
1250 esac 1305 esac
1251 shift 1306 shift
1252 done 1307 done
1253 1308
1254 if [[ "${final_ABI}" == "1" ]]; then 1309 if [[ "${final_ABI}" == "1" ]]; then
1310 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1311 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1312 fi
1255 PYTHON_ABI="$(PYTHON -f --ABI)" 1313 PYTHON_ABI="$(PYTHON -f --ABI)"
1256 elif [[ -z "${PYTHON_ABI}" ]]; then 1314 elif [[ -z "${PYTHON_ABI}" ]]; then
1257 PYTHON_ABI="$(PYTHON --ABI)" 1315 PYTHON_ABI="$(PYTHON --ABI)"
1258 fi 1316 fi
1259 1317
1328 fi 1386 fi
1329 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" 1387 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1330 fi 1388 fi
1331 1389
1332 if [[ "${final_ABI}" == "1" ]]; then 1390 if [[ "${final_ABI}" == "1" ]]; then
1391 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1392 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1393 fi
1333 "$(PYTHON -f)" -c "${python_command}" 1394 "$(PYTHON -f)" -c "${python_command}"
1334 else 1395 else
1335 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1396 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1336 fi 1397 fi
1337} 1398}
1345 return 0 1406 return 0
1346 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then 1407 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1347 return 0 1408 return 0
1348 else 1409 else
1349 return 1 1410 return 1
1411 fi
1412}
1413
1414_python_package_supporting_installation_for_multiple_python_abis() {
1415 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1416 die "${FUNCNAME}() cannot be used in global scope"
1417 fi
1418
1419 if has "${EAPI:-0}" 0 1 2 3 4; then
1420 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1421 return 0
1422 else
1423 return 1
1424 fi
1425 else
1426 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1350 fi 1427 fi
1351} 1428}
1352 1429
1353_python_initialize_prefix_variables() { 1430_python_initialize_prefix_variables() {
1354 if has "${EAPI:-0}" 0 1 2; then 1431 if has "${EAPI:-0}" 0 1 2; then
1467 die "${FUNCNAME}(): '${argument}' does not exist" 1544 die "${FUNCNAME}(): '${argument}' does not exist"
1468 elif [[ -f "${argument}" ]]; then 1545 elif [[ -f "${argument}" ]]; then
1469 files+=("${argument}") 1546 files+=("${argument}")
1470 elif [[ -d "${argument}" ]]; then 1547 elif [[ -d "${argument}" ]]; then
1471 if [[ "${recursive}" == "1" ]]; then 1548 if [[ "${recursive}" == "1" ]]; then
1472 if [[ "${only_executables}" == "1" ]]; then 1549 while read -d $'\0' -r file; do
1473 files+=($(find "${argument}" -perm /111 -type f)) 1550 files+=("${file}")
1474 else 1551 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1475 files+=($(find "${argument}" -type f))
1476 fi
1477 else 1552 else
1478 die "${FUNCNAME}(): '${argument}' is not a regular file" 1553 die "${FUNCNAME}(): '${argument}' is not a regular file"
1479 fi 1554 fi
1480 else 1555 else
1481 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" 1556 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1485 for file in "${files[@]}"; do 1560 for file in "${files[@]}"; do
1486 file="${file#./}" 1561 file="${file#./}"
1487 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 1562 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1488 1563
1489 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 1564 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1565 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1566
1490 if [[ "${quiet}" == "0" ]]; then 1567 if [[ "${quiet}" == "0" ]]; then
1491 einfo "Converting shebang in '${file}'" 1568 einfo "Converting shebang in '${file}'"
1492 fi 1569 fi
1570
1493 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 1571 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1494 1572
1495 # Delete potential whitespace after "#!". 1573 # Delete potential whitespace after "#!".
1496 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 1574 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1497 fi 1575 fi
1498 done 1576 done
1577}
1578
1579# @FUNCTION: python_clean_sitedirs
1580# @DESCRIPTION:
1581# Delete needless files in site-packages directories in ${ED}.
1582python_clean_sitedirs() {
1583 _python_initialize_prefix_variables
1584
1585 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1499} 1586}
1500 1587
1501# ================================================================================================ 1588# ================================================================================================
1502# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1589# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1503# ================================================================================================ 1590# ================================================================================================
1511_python_test_hook() { 1598_python_test_hook() {
1512 if [[ "$#" -ne 1 ]]; then 1599 if [[ "$#" -ne 1 ]]; then
1513 die "${FUNCNAME}() requires 1 argument" 1600 die "${FUNCNAME}() requires 1 argument"
1514 fi 1601 fi
1515 1602
1516 if [[ -n "${SUPPORT_PYTHON_ABIS}" && "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then 1603 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
1517 "${FUNCNAME[3]}_$1_hook" 1604 "${FUNCNAME[3]}_$1_hook"
1518 fi 1605 fi
1519} 1606}
1520 1607
1521# @FUNCTION: python_execute_nosetests 1608# @FUNCTION: python_execute_nosetests
1522# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1609# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1523# @DESCRIPTION: 1610# @DESCRIPTION:
1524# Execute nosetests for all enabled versions of Python. 1611# Execute nosetests for all enabled Python ABIs.
1525# In ebuilds of packages supporting installation for multiple versions of Python, this function 1612# 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. 1613# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1527python_execute_nosetests() { 1614python_execute_nosetests() {
1528 _python_set_color_variables 1615 _python_set_color_variables
1529 1616
1530 local PYTHONPATH_template= separate_build_dirs= 1617 local PYTHONPATH_template= separate_build_dirs=
1531 1618
1572 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 1659 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1573 fi 1660 fi
1574 1661
1575 _python_test_hook post 1662 _python_test_hook post
1576 } 1663 }
1577 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1664 if _python_package_supporting_installation_for_multiple_python_abis; then
1578 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1665 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1579 else 1666 else
1580 if [[ -n "${separate_build_dirs}" ]]; then 1667 if [[ -n "${separate_build_dirs}" ]]; then
1581 die "${FUNCNAME}(): Invalid usage" 1668 die "${FUNCNAME}(): Invalid usage"
1582 fi 1669 fi
1587} 1674}
1588 1675
1589# @FUNCTION: python_execute_py.test 1676# @FUNCTION: python_execute_py.test
1590# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1677# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1591# @DESCRIPTION: 1678# @DESCRIPTION:
1592# Execute py.test for all enabled versions of Python. 1679# Execute py.test for all enabled Python ABIs.
1593# In ebuilds of packages supporting installation for multiple versions of Python, this function 1680# 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. 1681# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1595python_execute_py.test() { 1682python_execute_py.test() {
1596 _python_set_color_variables 1683 _python_set_color_variables
1597 1684
1598 local PYTHONPATH_template= separate_build_dirs= 1685 local PYTHONPATH_template= separate_build_dirs=
1599 1686
1640 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" 1727 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
1641 fi 1728 fi
1642 1729
1643 _python_test_hook post 1730 _python_test_hook post
1644 } 1731 }
1645 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1732 if _python_package_supporting_installation_for_multiple_python_abis; then
1646 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1733 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1647 else 1734 else
1648 if [[ -n "${separate_build_dirs}" ]]; then 1735 if [[ -n "${separate_build_dirs}" ]]; then
1649 die "${FUNCNAME}(): Invalid usage" 1736 die "${FUNCNAME}(): Invalid usage"
1650 fi 1737 fi
1655} 1742}
1656 1743
1657# @FUNCTION: python_execute_trial 1744# @FUNCTION: python_execute_trial
1658# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1745# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1659# @DESCRIPTION: 1746# @DESCRIPTION:
1660# Execute trial for all enabled versions of Python. 1747# Execute trial for all enabled Python ABIs.
1661# In ebuilds of packages supporting installation for multiple versions of Python, this function 1748# 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. 1749# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1663python_execute_trial() { 1750python_execute_trial() {
1664 _python_set_color_variables 1751 _python_set_color_variables
1665 1752
1666 local PYTHONPATH_template= separate_build_dirs= 1753 local PYTHONPATH_template= separate_build_dirs=
1708 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 1795 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1709 fi 1796 fi
1710 1797
1711 _python_test_hook post 1798 _python_test_hook post
1712 } 1799 }
1713 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1800 if _python_package_supporting_installation_for_multiple_python_abis; then
1714 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1801 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1715 else 1802 else
1716 if [[ -n "${separate_build_dirs}" ]]; then 1803 if [[ -n "${separate_build_dirs}" ]]; then
1717 die "${FUNCNAME}(): Invalid usage" 1804 die "${FUNCNAME}(): Invalid usage"
1718 fi 1805 fi
1757# This function can be used only in pkg_postinst() phase. 1844# This function can be used only in pkg_postinst() phase.
1758python_mod_optimize() { 1845python_mod_optimize() {
1759 _python_initialize_prefix_variables 1846 _python_initialize_prefix_variables
1760 1847
1761 # Check if phase is pkg_postinst(). 1848 # Check if phase is pkg_postinst().
1762 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 1849 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1763 1850
1764 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1851 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=() 1852 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 1853
1767 # Strip trailing slash from ROOT. 1854 # Strip trailing slash from ROOT.
1768 root="${EROOT%/}" 1855 root="${EROOT%/}"
1769 1856
1935 _python_set_color_variables 2022 _python_set_color_variables
1936 2023
1937 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2024 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1938 2025
1939 # Check if phase is pkg_postrm(). 2026 # Check if phase is pkg_postrm().
1940 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2027 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1941 2028
1942 # Strip trailing slash from ROOT. 2029 # Strip trailing slash from ROOT.
1943 root="${EROOT%/}" 2030 root="${EROOT%/}"
1944 2031
1945 if (($#)); then 2032 if (($#)); then
1946 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2033 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1947 while (($#)); do 2034 while (($#)); do
1948 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2035 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" 2036 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1950 elif [[ "$1" =~ ^/ ]]; then 2037 elif [[ "$1" =~ ^/ ]]; then
1951 SEARCH_PATH+=("${root}/${1#/}") 2038 SEARCH_PATH+=("${root}/${1#/}")
1982 if [[ -d "${path}" ]]; then 2069 if [[ -d "${path}" ]]; then
1983 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do 2070 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
1984 if [[ "${REPLY}" == *[co] ]]; then 2071 if [[ "${REPLY}" == *[co] ]]; then
1985 py_file="${REPLY%[co]}" 2072 py_file="${REPLY%[co]}"
1986 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue 2073 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1987 einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" 2074 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
1988 rm -f "${py_file}"[co] 2075 rm -f "${py_file}"[co]
1989 elif [[ "${REPLY}" == *\$py.class ]]; then 2076 elif [[ "${REPLY}" == *\$py.class ]]; then
1990 py_file="${REPLY%\$py.class}.py" 2077 py_file="${REPLY%\$py.class}.py"
1991 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue 2078 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
1992 einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" 2079 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
1993 rm -f "${py_file%.py}\$py.class" 2080 rm -f "${py_file%.py}\$py.class"
1994 fi 2081 fi
1995 done 2082 done
1996 2083
1997 # Attempt to delete directories, which may be empty. 2084 # Attempt to delete directories, which may be empty.
1998 find "${path}" -type d | sort -r | while read -r dir; do 2085 find "${path}" -type d | sort -r | while read -r dir; do
1999 rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" 2086 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
2000 done 2087 done
2001 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then 2088 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
2002 if [[ (-f "${path}c" || -f "${path}o") ]]; then 2089 if [[ (-f "${path}c" || -f "${path}o") ]]; then
2003 einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" 2090 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
2004 rm -f "${path}"[co] 2091 rm -f "${path}"[co]
2005 fi 2092 fi
2006 if [[ -f "${path%.py}\$py.class" ]]; then 2093 if [[ -f "${path%.py}\$py.class" ]]; then
2007 einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" 2094 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2008 rm -f "${path%.py}\$py.class" 2095 rm -f "${path%.py}\$py.class"
2009 fi 2096 fi
2010 fi 2097 fi
2011 done 2098 done
2012} 2099}
2018# @FUNCTION: python_version 2105# @FUNCTION: python_version
2019# @DESCRIPTION: 2106# @DESCRIPTION:
2020# Run without arguments and it will export the version of python 2107# Run without arguments and it will export the version of python
2021# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 2108# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2022python_version() { 2109python_version() {
2023 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2110 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}()." 2111 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2025 die "${FUNCNAME}() cannot be used in this EAPI" 2112 die "${FUNCNAME}() cannot be used in this EAPI"
2026 fi 2113 fi
2027 2114
2115 _python_set_color_variables
2116
2028 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then 2117 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2029 einfo 2118 echo
2119 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2120 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2121 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2122 echo
2123
2124 einfo &> /dev/null
2030 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2125 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." 2126 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null
2032 einfo 2127 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2128 einfo &> /dev/null
2033 fi 2129 fi
2034 2130
2035 [[ -n "${PYVER}" ]] && return 0 2131 [[ -n "${PYVER}" ]] && return 0
2036 local tmpstr 2132 local tmpstr
2037 python="${python:-${EPREFIX}/usr/bin/python}" 2133 python="${python:-${EPREFIX}/usr/bin/python}"
2056# Example: 2152# Example:
2057# if python_mod_exists gtk; then 2153# if python_mod_exists gtk; then
2058# echo "gtk support enabled" 2154# echo "gtk support enabled"
2059# fi 2155# fi
2060python_mod_exists() { 2156python_mod_exists() {
2061 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2157 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}()." 2158 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2063 die "${FUNCNAME}() cannot be used in this EAPI" 2159 die "${FUNCNAME}() cannot be used in this EAPI"
2064 fi 2160 fi
2065 2161
2066 einfo 2162 echo
2163 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2165 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2166 echo
2167
2168 einfo &> /dev/null
2067 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2169 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}()." 2170 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2069 einfo 2171 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2172 einfo &> /dev/null
2070 2173
2071 if [[ "$#" -ne 1 ]]; then 2174 if [[ "$#" -ne 1 ]]; then
2072 die "${FUNCNAME}() requires 1 argument" 2175 die "${FUNCNAME}() requires 1 argument"
2073 fi 2176 fi
2074 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2177 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2077# @FUNCTION: python_tkinter_exists 2180# @FUNCTION: python_tkinter_exists
2078# @DESCRIPTION: 2181# @DESCRIPTION:
2079# Run without arguments, checks if Python was compiled with Tkinter 2182# Run without arguments, checks if Python was compiled with Tkinter
2080# support. If not, prints an error message and dies. 2183# support. If not, prints an error message and dies.
2081python_tkinter_exists() { 2184python_tkinter_exists() {
2082 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2185 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}()." 2186 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2084 die "${FUNCNAME}() cannot be used in this EAPI" 2187 die "${FUNCNAME}() cannot be used in this EAPI"
2085 fi 2188 fi
2086 2189
2087 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then 2190 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2088 einfo 2191 echo
2192 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2194 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2195 echo
2196
2197 einfo &> /dev/null
2089 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." 2198 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}()." 2199 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2091 einfo 2200 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2201 einfo &> /dev/null
2092 fi 2202 fi
2093 2203
2094 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2204 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2095if version_info[0] == 3: 2205if version_info[0] == 3:
2096 import tkinter 2206 import tkinter
2111# 2221#
2112# Example: 2222# Example:
2113# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py 2223# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2114# 2224#
2115python_mod_compile() { 2225python_mod_compile() {
2116 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2226 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}()." 2227 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2118 die "${FUNCNAME}() cannot be used in this EAPI" 2228 die "${FUNCNAME}() cannot be used in this EAPI"
2119 fi 2229 fi
2120 2230
2121 _python_initialize_prefix_variables 2231 _python_initialize_prefix_variables
2122 2232
2123 local f myroot myfiles=() 2233 local f myroot myfiles=()
2124 2234
2125 # Check if phase is pkg_postinst() 2235 # Check if phase is pkg_postinst()
2126 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2236 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2127 2237
2128 # strip trailing slash 2238 # strip trailing slash
2129 myroot="${EROOT%/}" 2239 myroot="${EROOT%/}"
2130 2240
2131 # respect ROOT 2241 # respect ROOT

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

  ViewVC Help
Powered by ViewVC 1.1.20