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

Diff of /eclass/python.eclass

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

Revision 1.99 Revision 1.105
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.99 2010/05/25 19:49:54 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.105 2010/10/29 19:09:08 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
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) 19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_SUPPORTED_ABIS=(${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
21 26
22# @ECLASS-VARIABLE: PYTHON_DEPEND 27# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 28# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 29# Specification of dependency on dev-lang/python.
25# Syntax: 30# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 32# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 33# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 34# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 35# maximal_version: <maximal_major_version.maximal_minor_version>
31 36
32_parse_PYTHON_DEPEND() { 37_python_parse_PYTHON_DEPEND() {
33 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups 38 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
34 39
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 40 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 41 version_components_groups="${PYTHON_DEPEND}"
37 42
153} 158}
154 159
155DEPEND=">=app-admin/eselect-python-20091230" 160DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 161RDEPEND="${DEPEND}"
157 162
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 163if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 164 _python_parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON."
165 die "NEED_PYTHON cannot be used in this EAPI"
166 fi
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 165else
171 _PYTHON_ATOMS=("dev-lang/python") 166 _PYTHON_ATOMS=("dev-lang/python")
167fi
168unset -f _python_parse_PYTHON_DEPEND
169
170if [[ -n "${NEED_PYTHON}" ]]; then
171 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
172 die "NEED_PYTHON variable is banned"
172fi 173fi
173 174
174# @ECLASS-VARIABLE: PYTHON_USE_WITH 175# @ECLASS-VARIABLE: PYTHON_USE_WITH
175# @DESCRIPTION: 176# @DESCRIPTION:
176# Set this to a space separated list of USE flags the Python slot in use must be built with. 177# Set this to a space separated list of USE flags the Python slot in use must be built with.
241 else 242 else
242 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" 243 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
243 fi 244 fi
244} 245}
245 246
247_python_abi-specific_local_scope() {
248 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
249}
250
246_python_initialize_prefix_variables() { 251_python_initialize_prefix_variables() {
247 if has "${EAPI:-0}" 0 1 2; then 252 if has "${EAPI:-0}" 0 1 2; then
248 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then 253 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
249 EROOT="${ROOT%/}${EPREFIX}/" 254 EROOT="${ROOT%/}${EPREFIX}/"
250 fi 255 fi
252 ED="${D%/}${EPREFIX}/" 257 ED="${D%/}${EPREFIX}/"
253 fi 258 fi
254 fi 259 fi
255} 260}
256 261
257unset PYTHON_SANITY_CHECKS 262unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
258 263
259_python_initial_sanity_checks() { 264_python_initial_sanity_checks() {
260 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 265 if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
261 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 266 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
262 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then 267 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
263 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." 268 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
264 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 269 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
265 die "'${EPREFIX}/usr/bin/python' is not valid symlink" 270 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
271 fi 276 fi
272 fi 277 fi
273} 278}
274 279
275_python_final_sanity_checks() { 280_python_final_sanity_checks() {
276 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 281 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
277 local PYTHON_ABI="${PYTHON_ABI}" 282 local PYTHON_ABI="${PYTHON_ABI}"
278 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do 283 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
279 # Ensure that appropriate version of Python is installed. 284 # Ensure that appropriate version of Python is installed.
280 if ! has_version "$(python_get_implementational_package)"; then 285 if ! has_version "$(python_get_implementational_package)"; then
281 die "$(python_get_implementational_package) is not installed" 286 die "$(python_get_implementational_package) is not installed"
291 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" 296 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
292 die "'python' does not respect EPYTHON variable" 297 die "'python' does not respect EPYTHON variable"
293 fi 298 fi
294 done 299 done
295 fi 300 fi
296 PYTHON_SANITY_CHECKS="1" 301 PYTHON_SANITY_CHECKS_EXECUTED="1"
297} 302}
303
304# @ECLASS-VARIABLE: PYTHON_COLORS
305# @DESCRIPTION:
306# User-configurable colored output.
307PYTHON_COLORS="${PYTHON_COLORS:-0}"
298 308
299_python_set_color_variables() { 309_python_set_color_variables() {
300 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 310 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
301 _BOLD=$'\e[1m' 311 _BOLD=$'\e[1m'
302 _RED=$'\e[1;31m' 312 _RED=$'\e[1;31m'
303 _GREEN=$'\e[1;32m' 313 _GREEN=$'\e[1;32m'
304 _BLUE=$'\e[1;34m' 314 _BLUE=$'\e[1;34m'
305 _CYAN=$'\e[1;36m' 315 _CYAN=$'\e[1;36m'
313 _NORMAL= 323 _NORMAL=
314 fi 324 fi
315} 325}
316 326
317unset PYTHON_PKG_SETUP_EXECUTED 327unset PYTHON_PKG_SETUP_EXECUTED
328
329_python_check_python_pkg_setup_execution() {
330 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
331
332 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
333 die "python_pkg_setup() not called"
334 fi
335}
318 336
319# @FUNCTION: python_pkg_setup 337# @FUNCTION: python_pkg_setup
320# @DESCRIPTION: 338# @DESCRIPTION:
321# Perform sanity checks and initialize environment. 339# Perform sanity checks and initialize environment.
322# 340#
326# This function can be used only in pkg_setup() phase. 344# This function can be used only in pkg_setup() phase.
327python_pkg_setup() { 345python_pkg_setup() {
328 # Check if phase is pkg_setup(). 346 # Check if phase is pkg_setup().
329 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 347 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
330 348
349 if [[ "$#" -ne 0 ]]; then
350 die "${FUNCNAME}() does not accept arguments"
351 fi
352
331 if _python_package_supporting_installation_for_multiple_python_abis; then 353 if _python_package_supporting_installation_for_multiple_python_abis; then
332 _python_calculate_PYTHON_ABIS 354 _python_calculate_PYTHON_ABIS
333 export EPYTHON="$(PYTHON -f)" 355 export EPYTHON="$(PYTHON -f)"
334 else 356 else
335 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 357 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
366 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" 388 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
367 fi 389 fi
368 } 390 }
369 391
370 if _python_package_supporting_installation_for_multiple_python_abis; then 392 if _python_package_supporting_installation_for_multiple_python_abis; then
371 python_execute_function -q python_pkg_setup_check_USE_flags 393 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
372 else 394 else
373 python_pkg_setup_check_USE_flags 395 python_pkg_setup_check_USE_flags
374 fi 396 fi
375 397
376 unset -f python_pkg_setup_check_USE_flags 398 unset -f python_pkg_setup_check_USE_flags
377 fi 399 fi
378 400
379 PYTHON_PKG_SETUP_EXECUTED="1" 401 PYTHON_PKG_SETUP_EXECUTED="1"
380} 402}
381 403
382if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 404if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
383 EXPORT_FUNCTIONS pkg_setup 405 EXPORT_FUNCTIONS pkg_setup
384fi 406fi
385 407
386# @FUNCTION: python_convert_shebangs 408# @FUNCTION: python_convert_shebangs
387# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 409# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
388# @DESCRIPTION: 410# @DESCRIPTION:
389# Convert shebangs in specified files. Directories can be specified only with --recursive option. 411# Convert shebangs in specified files. Directories can be specified only with --recursive option.
390python_convert_shebangs() { 412python_convert_shebangs() {
413 _python_check_python_pkg_setup_execution
414
391 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 415 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
392 416
393 while (($#)); do 417 while (($#)); do
394 case "$1" in 418 case "$1" in
395 -r|--recursive) 419 -r|--recursive)
464# @FUNCTION: python_clean_installation_image 488# @FUNCTION: python_clean_installation_image
465# @USAGE: [-q|--quiet] 489# @USAGE: [-q|--quiet]
466# @DESCRIPTION: 490# @DESCRIPTION:
467# Delete needless files in installation image. 491# Delete needless files in installation image.
468python_clean_installation_image() { 492python_clean_installation_image() {
493 _python_check_python_pkg_setup_execution
469 _python_initialize_prefix_variables 494 _python_initialize_prefix_variables
470 495
471 local file files=() quiet="0" 496 local file files=() quiet="0"
472 497
473 # Check if phase is src_install(). 498 # Check if phase is src_install().
536# @DESCRIPTION: 561# @DESCRIPTION:
537# Set this to export phase functions for the following ebuild phases: 562# Set this to export phase functions for the following ebuild phases:
538# src_prepare, src_configure, src_compile, src_test, src_install. 563# src_prepare, src_configure, src_compile, src_test, src_install.
539if ! has "${EAPI:-0}" 0 1; then 564if ! has "${EAPI:-0}" 0 1; then
540 python_src_prepare() { 565 python_src_prepare() {
566 _python_check_python_pkg_setup_execution
567
541 if ! _python_package_supporting_installation_for_multiple_python_abis; then 568 if ! _python_package_supporting_installation_for_multiple_python_abis; then
542 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 569 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
543 fi 570 fi
544 571
572 if [[ "$#" -ne 0 ]]; then
573 die "${FUNCNAME}() does not accept arguments"
574 fi
575
545 python_copy_sources 576 python_copy_sources
546 } 577 }
547 578
548 for python_default_function in src_configure src_compile src_test src_install; do 579 for python_default_function in src_configure src_compile src_test src_install; do
549 eval "python_${python_default_function}() { 580 eval "python_${python_default_function}() {
581 _python_check_python_pkg_setup_execution
582
550 if ! _python_package_supporting_installation_for_multiple_python_abis; then 583 if ! _python_package_supporting_installation_for_multiple_python_abis; then
551 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 584 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
552 fi 585 fi
553 586
554 python_execute_function -d -s -- \"\$@\" 587 python_execute_function -d -s -- \"\$@\"
559 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 592 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
560 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 593 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
561 fi 594 fi
562fi 595fi
563 596
597if has "${EAPI:-0}" 0 1 2 3; then
564unset PYTHON_ABIS 598 unset PYTHON_ABIS
599fi
565 600
566_python_calculate_PYTHON_ABIS() { 601_python_calculate_PYTHON_ABIS() {
567 if ! _python_package_supporting_installation_for_multiple_python_abis; then 602 if ! _python_package_supporting_installation_for_multiple_python_abis; then
568 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 603 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
569 fi 604 fi
570 605
571 _python_initial_sanity_checks 606 _python_initial_sanity_checks
572 607
573 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
574 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 608 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
575 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 609 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
576 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 610
611 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
577 612
578 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 613 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
579 local cpython_enabled="0" 614 local cpython_enabled="0"
580 615
581 if [[ -z "${USE_PYTHON}" ]]; then 616 if [[ -z "${USE_PYTHON}" ]]; then
582 die "USE_PYTHON variable is empty" 617 die "USE_PYTHON variable is empty"
583 fi 618 fi
584 619
585 for PYTHON_ABI in ${USE_PYTHON}; do 620 for PYTHON_ABI in ${USE_PYTHON}; do
586 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 621 if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then
587 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 622 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
588 fi 623 fi
589 624
590 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 625 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
591 cpython_enabled="1" 626 cpython_enabled="1"
592 fi 627 fi
593 628
594 support_ABI="1" 629 support_ABI="1"
595 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 630 while read restricted_ABI; do
596 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 631 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
597 support_ABI="0" 632 support_ABI="0"
598 break 633 break
599 fi 634 fi
600 done 635 done <<< "${restricted_ABIs}"
601 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 636 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
602 done 637 done
603 638
604 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 639 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
605 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 640 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
624 659
625 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 660 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
626 661
627 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 662 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
628 support_python_major_version="1" 663 support_python_major_version="1"
629 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 664 while read restricted_ABI; do
630 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 665 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
631 support_python_major_version="0" 666 support_python_major_version="0"
632 fi 667 fi
633 done 668 done <<< "${restricted_ABIs}"
634 [[ "${support_python_major_version}" == "1" ]] && break 669 [[ "${support_python_major_version}" == "1" ]] && break
635 done 670 done
636 if [[ "${support_python_major_version}" == "1" ]]; then 671 if [[ "${support_python_major_version}" == "1" ]]; then
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 672 while read restricted_ABI; do
638 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 673 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
639 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 674 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
640 fi 675 fi
641 done 676 done <<< "${restricted_ABIs}"
642 else 677 else
643 python2_version="" 678 python2_version=""
644 fi 679 fi
645 fi 680 fi
646 681
651 686
652 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 687 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
653 688
654 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 689 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
655 support_python_major_version="1" 690 support_python_major_version="1"
656 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 691 while read restricted_ABI; do
657 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 692 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
658 support_python_major_version="0" 693 support_python_major_version="0"
659 fi 694 fi
660 done 695 done <<< "${restricted_ABIs}"
661 [[ "${support_python_major_version}" == "1" ]] && break 696 [[ "${support_python_major_version}" == "1" ]] && break
662 done 697 done
663 if [[ "${support_python_major_version}" == "1" ]]; then 698 if [[ "${support_python_major_version}" == "1" ]]; then
664 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 699 while read restricted_ABI; do
665 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 700 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
666 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 701 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
667 fi 702 fi
668 done 703 done <<< "${restricted_ABIs}"
669 else 704 else
670 python3_version="" 705 python3_version=""
671 fi 706 fi
672 fi 707 fi
673 708
689 fi 724 fi
690 725
691 _python_final_sanity_checks 726 _python_final_sanity_checks
692} 727}
693 728
729_python_prepare_flags() {
730 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
731
732 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
733 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
734 for prefix in PYTHON_USER_ PYTHON_; do
735 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
736 eval "array=(\"\${${prefix}${variable}[@]}\")"
737 for element in "${array[@]}"; do
738 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
739 pattern="${element%% *}"
740 element="${element#* }"
741 operator="${element%% *}"
742 flags="${element#* }"
743 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
744 if [[ "${operator}" == "+" ]]; then
745 eval "export ${variable}+=\"\${variable:+ }${flags}\""
746 elif [[ "${operator}" == "-" ]]; then
747 flags="${flags// /$'\n'}"
748 old_value="${!variable// /$'\n'}"
749 new_value=""
750 while read old_flag; do
751 while read deleted_flag; do
752 if [[ "${old_flag}" == ${deleted_flag} ]]; then
753 continue 2
754 fi
755 done <<< "${flags}"
756 new_value+="${new_value:+ }${old_flag}"
757 done <<< "${old_value}"
758 eval "export ${variable}=\"\${new_value}\""
759 fi
760 fi
761 else
762 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
763 fi
764 done
765 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
766 die "${prefix}${variable} should be indexed array"
767 fi
768 done
769 done
770}
771
772_python_restore_flags() {
773 local variable
774
775 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
776 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
777 unset _PYTHON_SAVED_${variable}
778 done
779}
780
694# @FUNCTION: python_execute_function 781# @FUNCTION: python_execute_function
695# @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] 782# @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]
696# @DESCRIPTION: 783# @DESCRIPTION:
697# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 784# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
698# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 785# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
699python_execute_function() { 786python_execute_function() {
787 _python_check_python_pkg_setup_execution
788
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 789 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" 790 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 791 fi
703 792
704 _python_set_color_variables 793 _python_set_color_variables
705 794
706 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= 795 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir=
707 796
708 while (($#)); do 797 while (($#)); do
709 case "$1" in 798 case "$1" in
710 --action-message) 799 --action-message)
711 action_message_template="$2" 800 action_message_template="$2"
798 fi 887 fi
799 function="python_default_function" 888 function="python_default_function"
800 fi 889 fi
801 890
802 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 891 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
803 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 892 if _python_abi-specific_local_scope; then
804 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
805 die "${FUNCNAME}(): Invalid call stack" 893 die "${FUNCNAME}(): Invalid call stack"
806 fi 894 fi
807 done
808 895
809 if [[ "${quiet}" == "0" ]]; then 896 if [[ "${quiet}" == "0" ]]; then
810 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 897 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
811 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 898 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
812 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 899 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
825 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 912 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
826 else 913 else
827 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 914 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
828 fi 915 fi
829 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 916 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
917 _python_prepare_flags
918
830 if [[ "${quiet}" == "0" ]]; then 919 if [[ "${quiet}" == "0" ]]; then
831 if [[ -n "${action_message_template}" ]]; then 920 if [[ -n "${action_message_template}" ]]; then
832 action_message="$(eval echo -n "${action_message_template}")" 921 eval "action_message=\"${action_message_template}\""
833 else 922 else
834 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 923 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
835 fi 924 fi
836 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 925 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
837 fi 926 fi
855 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 944 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
856 else 945 else
857 EPYTHON="$(PYTHON)" "${function}" "$@" 946 EPYTHON="$(PYTHON)" "${function}" "$@"
858 fi 947 fi
859 948
860 if [[ "$?" != "0" ]]; then 949 return_code="$?"
950
951 _python_restore_flags
952
953 if [[ "${return_code}" -ne 0 ]]; then
861 if [[ -n "${failure_message_template}" ]]; then 954 if [[ -n "${failure_message_template}" ]]; then
862 failure_message="$(eval echo -n "${failure_message_template}")" 955 eval "failure_message=\"${failure_message_template}\""
863 else 956 else
864 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 957 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
865 fi 958 fi
866 959
867 if [[ "${nonfatal}" == "1" ]]; then 960 if [[ "${nonfatal}" == "1" ]]; then
868 if [[ "${quiet}" == "0" ]]; then 961 if [[ "${quiet}" == "0" ]]; then
869 ewarn "${_RED}${failure_message}${_NORMAL}" 962 ewarn "${failure_message}"
870 fi 963 fi
871 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 964 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
872 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 965 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
873 local enabled_PYTHON_ABIS= other_PYTHON_ABI 966 local enabled_PYTHON_ABIS= other_PYTHON_ABI
874 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 967 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
875 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 968 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
876 done 969 done
877 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 970 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
878 fi 971 fi
879 if [[ "${quiet}" == "0" ]]; then 972 if [[ "${quiet}" == "0" ]]; then
880 ewarn "${_RED}${failure_message}${_NORMAL}" 973 ewarn "${failure_message}"
881 fi 974 fi
882 if [[ -z "${PYTHON_ABIS}" ]]; then 975 if [[ -z "${PYTHON_ABIS}" ]]; then
883 die "${function}() function failed with all enabled Python ABIs" 976 die "${function}() function failed with all enabled Python ABIs"
884 fi 977 fi
885 else 978 else
922# @FUNCTION: python_copy_sources 1015# @FUNCTION: python_copy_sources
923# @USAGE: <directory="${S}"> [directory] 1016# @USAGE: <directory="${S}"> [directory]
924# @DESCRIPTION: 1017# @DESCRIPTION:
925# Copy unpacked sources of current package to separate build directory for each Python ABI. 1018# Copy unpacked sources of current package to separate build directory for each Python ABI.
926python_copy_sources() { 1019python_copy_sources() {
1020 _python_check_python_pkg_setup_execution
1021
927 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1022 if ! _python_package_supporting_installation_for_multiple_python_abis; then
928 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1023 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
929 fi 1024 fi
930 1025
931 local dir dirs=() PYTHON_ABI 1026 local dir dirs=() PYTHON_ABI
952# @DESCRIPTION: 1047# @DESCRIPTION:
953# Generate wrapper scripts. Existing files are overwritten only with --force option. 1048# Generate wrapper scripts. Existing files are overwritten only with --force option.
954# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1049# If --respect-EPYTHON option is specified, then generated wrapper scripts will
955# respect EPYTHON variable at run time. 1050# respect EPYTHON variable at run time.
956python_generate_wrapper_scripts() { 1051python_generate_wrapper_scripts() {
1052 _python_check_python_pkg_setup_execution
1053
957 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1054 if ! _python_package_supporting_installation_for_multiple_python_abis; then
958 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1055 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
959 fi 1056 fi
960 1057
961 _python_initialize_prefix_variables 1058 _python_initialize_prefix_variables
1155 1252
1156# ================================================================================================ 1253# ================================================================================================
1157# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1254# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1158# ================================================================================================ 1255# ================================================================================================
1159 1256
1257unset EPYTHON PYTHON_ABI
1258
1160# @FUNCTION: python_set_active_version 1259# @FUNCTION: python_set_active_version
1161# @USAGE: <CPython_ABI|2|3> 1260# @USAGE: <CPython_ABI|2|3>
1162# @DESCRIPTION: 1261# @DESCRIPTION:
1163# Set specified version of CPython as active version of Python. 1262# Set specified version of CPython as active version of Python.
1263#
1264# This function can be used only in pkg_setup() phase.
1164python_set_active_version() { 1265python_set_active_version() {
1266 # Check if phase is pkg_setup().
1267 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1268
1165 if _python_package_supporting_installation_for_multiple_python_abis; then 1269 if _python_package_supporting_installation_for_multiple_python_abis; then
1166 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1270 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1167 fi 1271 fi
1168 1272
1169 if [[ "$#" -ne 1 ]]; then 1273 if [[ "$#" -ne 1 ]]; then
1170 die "${FUNCNAME}() requires 1 argument" 1274 die "${FUNCNAME}() requires 1 argument"
1171 fi 1275 fi
1172 1276
1173 _python_initial_sanity_checks 1277 _python_initial_sanity_checks
1174 1278
1279 if [[ -z "${PYTHON_ABI}" ]]; then
1175 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1280 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1176 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1281 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
1177 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1282 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
1178 fi 1283 fi
1179 export EPYTHON="$(PYTHON "$1")" 1284 export EPYTHON="$(PYTHON "$1")"
1180 elif [[ "$1" == "2" ]]; then 1285 elif [[ "$1" == "2" ]]; then
1181 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1286 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1182 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1287 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1183 fi 1288 fi
1184 export EPYTHON="$(PYTHON -2)" 1289 export EPYTHON="$(PYTHON -2)"
1185 elif [[ "$1" == "3" ]]; then 1290 elif [[ "$1" == "3" ]]; then
1186 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1291 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1187 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1292 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1188 fi 1293 fi
1189 export EPYTHON="$(PYTHON -3)" 1294 export EPYTHON="$(PYTHON -3)"
1190 else 1295 else
1191 die "${FUNCNAME}(): Unrecognized argument '$1'" 1296 die "${FUNCNAME}(): Unrecognized argument '$1'"
1192 fi 1297 fi
1193 1298
1194 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1299 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1195 # so it does not need to be exported to subprocesses. 1300 # so it does not need to be exported to subprocesses.
1196 PYTHON_ABI="${EPYTHON#python}" 1301 PYTHON_ABI="${EPYTHON#python}"
1197 PYTHON_ABI="${PYTHON_ABI%%-*}" 1302 PYTHON_ABI="${PYTHON_ABI%%-*}"
1303 fi
1198 1304
1199 _python_final_sanity_checks 1305 _python_final_sanity_checks
1200 1306
1201 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1307 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1202 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1308 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1204 1310
1205# @FUNCTION: python_need_rebuild 1311# @FUNCTION: python_need_rebuild
1206# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1312# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1207# switching of active version of Python. 1313# switching of active version of Python.
1208python_need_rebuild() { 1314python_need_rebuild() {
1315 _python_check_python_pkg_setup_execution
1316
1209 if _python_package_supporting_installation_for_multiple_python_abis; then 1317 if _python_package_supporting_installation_for_multiple_python_abis; then
1210 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1318 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1319 fi
1320
1321 if [[ "$#" -ne 0 ]]; then
1322 die "${FUNCNAME}() does not accept arguments"
1211 fi 1323 fi
1212 1324
1213 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1325 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1214} 1326}
1215 1327
1249# If --ABI option is specified, then only specified Python ABI is printed instead of 1361# If --ABI option is specified, then only specified Python ABI is printed instead of
1250# filename of Python interpreter. 1362# filename of Python interpreter.
1251# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1363# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1252# --ABI and --absolute-path options cannot be specified simultaneously. 1364# --ABI and --absolute-path options cannot be specified simultaneously.
1253PYTHON() { 1365PYTHON() {
1366 _python_check_python_pkg_setup_execution
1367
1254 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1368 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1255 1369
1256 while (($#)); do 1370 while (($#)); do
1257 case "$1" in 1371 case "$1" in
1258 -2) 1372 -2)
1283 esac 1397 esac
1284 shift 1398 shift
1285 done 1399 done
1286 1400
1287 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1401 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1288 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1402 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1289 fi 1403 fi
1290 1404
1291 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1405 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1292 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1406 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1293 fi 1407 fi
1311 if [[ -z "${PYTHON_ABI}" ]]; then 1425 if [[ -z "${PYTHON_ABI}" ]]; then
1312 die "${FUNCNAME}(): Active version of Python 3 not set" 1426 die "${FUNCNAME}(): Active version of Python 3 not set"
1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1427 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1428 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1315 fi 1429 fi
1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1430 elif _python_package_supporting_installation_for_multiple_python_abis; then
1431 if ! _python_abi-specific_local_scope; then
1432 die "${FUNCNAME}() should be used in ABI-specific local scope"
1433 fi
1434 else
1317 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1435 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1318 if [[ -z "${PYTHON_ABI}" ]]; then 1436 if [[ -z "${PYTHON_ABI}" ]]; then
1319 die "${FUNCNAME}(): Failure of extraction of locally active version of Python" 1437 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1320 fi 1438 fi
1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1322 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1323 fi 1439 fi
1324 elif [[ "$#" -eq 1 ]]; then 1440 elif [[ "$#" -eq 1 ]]; then
1325 if [[ "${final_ABI}" == "1" ]]; then 1441 if [[ "${final_ABI}" == "1" ]]; then
1326 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1442 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1327 fi 1443 fi
1362# @USAGE: [-f|--final-ABI] 1478# @USAGE: [-f|--final-ABI]
1363# @DESCRIPTION: 1479# @DESCRIPTION:
1364# Print name of Python implementation. 1480# Print name of Python implementation.
1365# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1481# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1366python_get_implementation() { 1482python_get_implementation() {
1483 _python_check_python_pkg_setup_execution
1484
1367 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1485 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1368 1486
1369 while (($#)); do 1487 while (($#)); do
1370 case "$1" in 1488 case "$1" in
1371 -f|--final-ABI) 1489 -f|--final-ABI)
1384 if [[ "${final_ABI}" == "1" ]]; then 1502 if [[ "${final_ABI}" == "1" ]]; then
1385 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1503 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1386 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1504 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1387 fi 1505 fi
1388 PYTHON_ABI="$(PYTHON -f --ABI)" 1506 PYTHON_ABI="$(PYTHON -f --ABI)"
1389 elif [[ -z "${PYTHON_ABI}" ]]; then 1507 else
1508 if _python_package_supporting_installation_for_multiple_python_abis; then
1509 if ! _python_abi-specific_local_scope; then
1510 die "${FUNCNAME}() should be used in ABI-specific local scope"
1511 fi
1512 else
1390 PYTHON_ABI="$(PYTHON --ABI)" 1513 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1514 fi
1391 fi 1515 fi
1392 1516
1393 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1517 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1394} 1518}
1395 1519
1397# @USAGE: [-f|--final-ABI] 1521# @USAGE: [-f|--final-ABI]
1398# @DESCRIPTION: 1522# @DESCRIPTION:
1399# Print category, name and slot of package providing Python implementation. 1523# Print category, name and slot of package providing Python implementation.
1400# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1524# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1401python_get_implementational_package() { 1525python_get_implementational_package() {
1526 _python_check_python_pkg_setup_execution
1527
1402 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1528 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1403 1529
1404 while (($#)); do 1530 while (($#)); do
1405 case "$1" in 1531 case "$1" in
1406 -f|--final-ABI) 1532 -f|--final-ABI)
1419 if [[ "${final_ABI}" == "1" ]]; then 1545 if [[ "${final_ABI}" == "1" ]]; then
1420 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1546 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1421 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1547 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1422 fi 1548 fi
1423 PYTHON_ABI="$(PYTHON -f --ABI)" 1549 PYTHON_ABI="$(PYTHON -f --ABI)"
1424 elif [[ -z "${PYTHON_ABI}" ]]; then 1550 else
1551 if _python_package_supporting_installation_for_multiple_python_abis; then
1552 if ! _python_abi-specific_local_scope; then
1553 die "${FUNCNAME}() should be used in ABI-specific local scope"
1554 fi
1555 else
1425 PYTHON_ABI="$(PYTHON --ABI)" 1556 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1426 fi 1557 fi
1558 fi
1427 1559
1560 if [[ "${EAPI:-0}" == "0" ]]; then
1428 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1561 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1429 echo "dev-lang/python:${PYTHON_ABI}" 1562 echo "=dev-lang/python-${PYTHON_ABI}*"
1430 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1563 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1564 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1565 fi
1566 else
1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1568 echo "dev-lang/python:${PYTHON_ABI}"
1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1431 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1570 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1571 fi
1432 fi 1572 fi
1433} 1573}
1434 1574
1435# @FUNCTION: python_get_includedir 1575# @FUNCTION: python_get_includedir
1436# @USAGE: [-f|--final-ABI] 1576# @USAGE: [-b|--base-path] [-f|--final-ABI]
1437# @DESCRIPTION: 1577# @DESCRIPTION:
1438# Print path to Python include directory. 1578# Print path to Python include directory.
1579# If --base-path option is specified, then path not prefixed with "/" is printed.
1439# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1580# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1440python_get_includedir() { 1581python_get_includedir() {
1582 _python_check_python_pkg_setup_execution
1583
1441 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1584 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1442 1585
1443 while (($#)); do 1586 while (($#)); do
1444 case "$1" in 1587 case "$1" in
1588 -b|--base-path)
1589 base_path="1"
1590 ;;
1445 -f|--final-ABI) 1591 -f|--final-ABI)
1446 final_ABI="1" 1592 final_ABI="1"
1447 ;; 1593 ;;
1448 -*) 1594 -*)
1449 die "${FUNCNAME}(): Unrecognized option '$1'" 1595 die "${FUNCNAME}(): Unrecognized option '$1'"
1452 die "${FUNCNAME}(): Invalid usage" 1598 die "${FUNCNAME}(): Invalid usage"
1453 ;; 1599 ;;
1454 esac 1600 esac
1455 shift 1601 shift
1456 done 1602 done
1603
1604 if [[ "${base_path}" == "0" ]]; then
1605 prefix="/"
1606 fi
1457 1607
1458 if [[ "${final_ABI}" == "1" ]]; then 1608 if [[ "${final_ABI}" == "1" ]]; then
1459 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1609 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1460 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1610 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1461 fi 1611 fi
1462 PYTHON_ABI="$(PYTHON -f --ABI)" 1612 PYTHON_ABI="$(PYTHON -f --ABI)"
1463 elif [[ -z "${PYTHON_ABI}" ]]; then 1613 else
1614 if _python_package_supporting_installation_for_multiple_python_abis; then
1615 if ! _python_abi-specific_local_scope; then
1616 die "${FUNCNAME}() should be used in ABI-specific local scope"
1617 fi
1618 else
1464 PYTHON_ABI="$(PYTHON --ABI)" 1619 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1620 fi
1465 fi 1621 fi
1466 1622
1467 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1623 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1468 echo "/usr/include/python${PYTHON_ABI}" 1624 echo "${prefix}usr/include/python${PYTHON_ABI}"
1469 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1625 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1470 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1626 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1471 fi 1627 fi
1472} 1628}
1473 1629
1474# @FUNCTION: python_get_libdir 1630# @FUNCTION: python_get_libdir
1475# @USAGE: [-f|--final-ABI] 1631# @USAGE: [-b|--base-path] [-f|--final-ABI]
1476# @DESCRIPTION: 1632# @DESCRIPTION:
1477# Print path to Python library directory. 1633# Print path to Python library directory.
1634# If --base-path option is specified, then path not prefixed with "/" is printed.
1478# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1635# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1479python_get_libdir() { 1636python_get_libdir() {
1637 _python_check_python_pkg_setup_execution
1638
1480 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1639 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1481 1640
1482 while (($#)); do 1641 while (($#)); do
1483 case "$1" in 1642 case "$1" in
1643 -b|--base-path)
1644 base_path="1"
1645 ;;
1484 -f|--final-ABI) 1646 -f|--final-ABI)
1485 final_ABI="1" 1647 final_ABI="1"
1486 ;; 1648 ;;
1487 -*) 1649 -*)
1488 die "${FUNCNAME}(): Unrecognized option '$1'" 1650 die "${FUNCNAME}(): Unrecognized option '$1'"
1491 die "${FUNCNAME}(): Invalid usage" 1653 die "${FUNCNAME}(): Invalid usage"
1492 ;; 1654 ;;
1493 esac 1655 esac
1494 shift 1656 shift
1495 done 1657 done
1658
1659 if [[ "${base_path}" == "0" ]]; then
1660 prefix="/"
1661 fi
1496 1662
1497 if [[ "${final_ABI}" == "1" ]]; then 1663 if [[ "${final_ABI}" == "1" ]]; then
1498 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1664 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1499 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1665 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1500 fi 1666 fi
1501 PYTHON_ABI="$(PYTHON -f --ABI)" 1667 PYTHON_ABI="$(PYTHON -f --ABI)"
1502 elif [[ -z "${PYTHON_ABI}" ]]; then 1668 else
1669 if _python_package_supporting_installation_for_multiple_python_abis; then
1670 if ! _python_abi-specific_local_scope; then
1671 die "${FUNCNAME}() should be used in ABI-specific local scope"
1672 fi
1673 else
1503 PYTHON_ABI="$(PYTHON --ABI)" 1674 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1675 fi
1504 fi 1676 fi
1505 1677
1506 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1678 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1507 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1679 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1508 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1680 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1509 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1681 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1510 fi 1682 fi
1511} 1683}
1512 1684
1513# @FUNCTION: python_get_sitedir 1685# @FUNCTION: python_get_sitedir
1514# @USAGE: [-f|--final-ABI] 1686# @USAGE: [-b|--base-path] [-f|--final-ABI]
1515# @DESCRIPTION: 1687# @DESCRIPTION:
1516# Print path to Python site-packages directory. 1688# Print path to Python site-packages directory.
1689# If --base-path option is specified, then path not prefixed with "/" is printed.
1517# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1690# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1518python_get_sitedir() { 1691python_get_sitedir() {
1519 local options=() 1692 _python_check_python_pkg_setup_execution
1693
1694 local final_ABI="0" options=()
1520 1695
1521 while (($#)); do 1696 while (($#)); do
1522 case "$1" in 1697 case "$1" in
1698 -b|--base-path)
1699 options+=("$1")
1700 ;;
1523 -f|--final-ABI) 1701 -f|--final-ABI)
1524 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1702 final_ABI="1"
1525 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1526 fi
1527 options+=("$1") 1703 options+=("$1")
1528 ;; 1704 ;;
1529 -*) 1705 -*)
1530 die "${FUNCNAME}(): Unrecognized option '$1'" 1706 die "${FUNCNAME}(): Unrecognized option '$1'"
1531 ;; 1707 ;;
1534 ;; 1710 ;;
1535 esac 1711 esac
1536 shift 1712 shift
1537 done 1713 done
1538 1714
1715 if [[ "${final_ABI}" == "1" ]]; then
1716 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1717 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1718 fi
1719 else
1720 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1721 die "${FUNCNAME}() should be used in ABI-specific local scope"
1722 fi
1723 fi
1724
1539 echo "$(python_get_libdir "${options[@]}")/site-packages" 1725 echo "$(python_get_libdir "${options[@]}")/site-packages"
1540} 1726}
1541 1727
1542# @FUNCTION: python_get_library 1728# @FUNCTION: python_get_library
1543# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1729# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1544# @DESCRIPTION: 1730# @DESCRIPTION:
1545# Print path to Python library. 1731# Print path to Python library.
1732# If --base-path option is specified, then path not prefixed with "/" is printed.
1546# If --linker-option is specified, then "-l${library}" linker option is printed. 1733# If --linker-option is specified, then "-l${library}" linker option is printed.
1547# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1734# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1548python_get_library() { 1735python_get_library() {
1736 _python_check_python_pkg_setup_execution
1737
1549 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1738 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1550 1739
1551 while (($#)); do 1740 while (($#)); do
1552 case "$1" in 1741 case "$1" in
1742 -b|--base-path)
1743 base_path="1"
1744 ;;
1553 -f|--final-ABI) 1745 -f|--final-ABI)
1554 final_ABI="1" 1746 final_ABI="1"
1555 ;; 1747 ;;
1556 -l|--linker-option) 1748 -l|--linker-option)
1557 linker_option="1" 1749 linker_option="1"
1563 die "${FUNCNAME}(): Invalid usage" 1755 die "${FUNCNAME}(): Invalid usage"
1564 ;; 1756 ;;
1565 esac 1757 esac
1566 shift 1758 shift
1567 done 1759 done
1760
1761 if [[ "${base_path}" == "0" ]]; then
1762 prefix="/"
1763 fi
1764
1765 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1766 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1767 fi
1568 1768
1569 if [[ "${final_ABI}" == "1" ]]; then 1769 if [[ "${final_ABI}" == "1" ]]; then
1570 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1770 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1571 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1771 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1572 fi 1772 fi
1573 PYTHON_ABI="$(PYTHON -f --ABI)" 1773 PYTHON_ABI="$(PYTHON -f --ABI)"
1574 elif [[ -z "${PYTHON_ABI}" ]]; then 1774 else
1775 if _python_package_supporting_installation_for_multiple_python_abis; then
1776 if ! _python_abi-specific_local_scope; then
1777 die "${FUNCNAME}() should be used in ABI-specific local scope"
1778 fi
1779 else
1575 PYTHON_ABI="$(PYTHON --ABI)" 1780 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1781 fi
1576 fi 1782 fi
1577 1783
1578 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1784 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1579 if [[ "${linker_option}" == "1" ]]; then 1785 if [[ "${linker_option}" == "1" ]]; then
1580 echo "-lpython${PYTHON_ABI}" 1786 echo "-lpython${PYTHON_ABI}"
1581 else 1787 else
1582 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1788 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1583 fi 1789 fi
1584 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1790 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1585 die "${FUNCNAME}(): Jython does not have shared library" 1791 die "${FUNCNAME}(): Jython does not have shared library"
1586 fi 1792 fi
1587} 1793}
1592# Print Python version. 1798# Print Python version.
1593# --full, --major, --minor and --micro options cannot be specified simultaneously. 1799# --full, --major, --minor and --micro options cannot be specified simultaneously.
1594# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1800# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1595# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1801# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1596python_get_version() { 1802python_get_version() {
1803 _python_check_python_pkg_setup_execution
1804
1597 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1805 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1598 1806
1599 while (($#)); do 1807 while (($#)); do
1600 case "$1" in 1808 case "$1" in
1601 -f|--final-ABI) 1809 -f|--final-ABI)
1651 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1859 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1652 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1860 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1653 fi 1861 fi
1654 "$(PYTHON -f)" -c "${python_command}" 1862 "$(PYTHON -f)" -c "${python_command}"
1655 else 1863 else
1864 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1865 die "${FUNCNAME}() should be used in ABI-specific local scope"
1866 fi
1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1867 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1657 fi 1868 fi
1658} 1869}
1659 1870
1660# ================================================================================================ 1871# ================================================================================================
1682# @DESCRIPTION: 1893# @DESCRIPTION:
1683# Execute nosetests for all enabled Python ABIs. 1894# Execute nosetests for all enabled Python ABIs.
1684# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1895# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1685# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 1896# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1686python_execute_nosetests() { 1897python_execute_nosetests() {
1898 _python_check_python_pkg_setup_execution
1687 _python_set_color_variables 1899 _python_set_color_variables
1688 1900
1689 local PYTHONPATH_template= separate_build_dirs= 1901 local PYTHONPATH_template= separate_build_dirs=
1690 1902
1691 while (($#)); do 1903 while (($#)); do
1710 esac 1922 esac
1711 shift 1923 shift
1712 done 1924 done
1713 1925
1714 python_test_function() { 1926 python_test_function() {
1715 local evaluated_PYTHONPATH= 1927 local evaluated_PYTHONPATH
1716 1928
1717 if [[ -n "${PYTHONPATH_template}" ]]; then
1718 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1929 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1719 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1720 unset evaluated_PYTHONPATH
1721 fi
1722 fi
1723 1930
1724 _python_test_hook pre 1931 _python_test_hook pre
1725 1932
1726 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1933 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1727 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1934 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1750# @DESCRIPTION: 1957# @DESCRIPTION:
1751# Execute py.test for all enabled Python ABIs. 1958# Execute py.test for all enabled Python ABIs.
1752# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1959# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1753# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 1960# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1754python_execute_py.test() { 1961python_execute_py.test() {
1962 _python_check_python_pkg_setup_execution
1755 _python_set_color_variables 1963 _python_set_color_variables
1756 1964
1757 local PYTHONPATH_template= separate_build_dirs= 1965 local PYTHONPATH_template= separate_build_dirs=
1758 1966
1759 while (($#)); do 1967 while (($#)); do
1778 esac 1986 esac
1779 shift 1987 shift
1780 done 1988 done
1781 1989
1782 python_test_function() { 1990 python_test_function() {
1783 local evaluated_PYTHONPATH= 1991 local evaluated_PYTHONPATH
1784 1992
1785 if [[ -n "${PYTHONPATH_template}" ]]; then
1786 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1993 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1787 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1788 unset evaluated_PYTHONPATH
1789 fi
1790 fi
1791 1994
1792 _python_test_hook pre 1995 _python_test_hook pre
1793 1996
1794 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1997 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1795 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1998 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1818# @DESCRIPTION: 2021# @DESCRIPTION:
1819# Execute trial for all enabled Python ABIs. 2022# Execute trial for all enabled Python ABIs.
1820# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2023# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1821# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2024# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1822python_execute_trial() { 2025python_execute_trial() {
2026 _python_check_python_pkg_setup_execution
1823 _python_set_color_variables 2027 _python_set_color_variables
1824 2028
1825 local PYTHONPATH_template= separate_build_dirs= 2029 local PYTHONPATH_template= separate_build_dirs=
1826 2030
1827 while (($#)); do 2031 while (($#)); do
1846 esac 2050 esac
1847 shift 2051 shift
1848 done 2052 done
1849 2053
1850 python_test_function() { 2054 python_test_function() {
1851 local evaluated_PYTHONPATH= 2055 local evaluated_PYTHONPATH
1852 2056
1853 if [[ -n "${PYTHONPATH_template}" ]]; then
1854 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2057 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1855 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1856 unset evaluated_PYTHONPATH
1857 fi
1858 fi
1859 2058
1860 _python_test_hook pre 2059 _python_test_hook pre
1861 2060
1862 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2061 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1863 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2062 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1888# @FUNCTION: python_enable_pyc 2087# @FUNCTION: python_enable_pyc
1889# @DESCRIPTION: 2088# @DESCRIPTION:
1890# Tell Python to automatically recompile modules to .pyc/.pyo if the 2089# Tell Python to automatically recompile modules to .pyc/.pyo if the
1891# timestamps/version stamps have changed. 2090# timestamps/version stamps have changed.
1892python_enable_pyc() { 2091python_enable_pyc() {
2092 _python_check_python_pkg_setup_execution
2093
2094 if [[ "$#" -ne 0 ]]; then
2095 die "${FUNCNAME}() does not accept arguments"
2096 fi
2097
1893 unset PYTHONDONTWRITEBYTECODE 2098 unset PYTHONDONTWRITEBYTECODE
1894} 2099}
1895 2100
1896# @FUNCTION: python_disable_pyc 2101# @FUNCTION: python_disable_pyc
1897# @DESCRIPTION: 2102# @DESCRIPTION:
1898# Tell Python not to automatically recompile modules to .pyc/.pyo 2103# Tell Python not to automatically recompile modules to .pyc/.pyo
1899# even if the timestamps/version stamps do not match. This is done 2104# even if the timestamps/version stamps do not match. This is done
1900# to protect sandbox. 2105# to protect sandbox.
1901python_disable_pyc() { 2106python_disable_pyc() {
2107 _python_check_python_pkg_setup_execution
2108
2109 if [[ "$#" -ne 0 ]]; then
2110 die "${FUNCNAME}() does not accept arguments"
2111 fi
2112
1902 export PYTHONDONTWRITEBYTECODE="1" 2113 export PYTHONDONTWRITEBYTECODE="1"
1903} 2114}
1904 2115
1905_python_clean_compiled_modules() { 2116_python_clean_compiled_modules() {
1906 _python_initialize_prefix_variables 2117 _python_initialize_prefix_variables
1907 _python_set_color_variables 2118 _python_set_color_variables
1908 2119
1909 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2120 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
1910 2121
1911 local base_module_name compiled_file compiled_files=() dir path py_file root 2122 local base_module_name compiled_file compiled_files=() dir path py_file root
1912 2123
1913 # Strip trailing slash from EROOT. 2124 # Strip trailing slash from EROOT.
1914 root="${EROOT%/}" 2125 root="${EROOT%/}"
1921 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) 2132 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1922 2133
1923 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2134 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1924 # Delete empty child directories. 2135 # Delete empty child directories.
1925 find "${path}" -type d | sort -r | while read -r dir; do 2136 find "${path}" -type d | sort -r | while read -r dir; do
1926 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" 2137 if rmdir "${dir}" 2> /dev/null; then
2138 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2139 fi
1927 done 2140 done
1928 fi 2141 fi
1929 elif [[ "${path}" == *.py ]]; then 2142 elif [[ "${path}" == *.py ]]; then
1930 base_module_name="${path##*/}" 2143 base_module_name="${path##*/}"
1931 base_module_name="${base_module_name%.py}" 2144 base_module_name="${base_module_name%.py}"
1977 fi 2190 fi
1978 2191
1979 # Delete empty parent directories. 2192 # Delete empty parent directories.
1980 dir="${compiled_file%/*}" 2193 dir="${compiled_file%/*}"
1981 while [[ "${dir}" != "${root}" ]]; do 2194 while [[ "${dir}" != "${root}" ]]; do
1982 if rmdir "${compiled_file%/*}" 2> /dev/null; then 2195 if rmdir "${dir}" 2> /dev/null; then
1983 echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}" 2196 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1984 else 2197 else
1985 break 2198 break
1986 fi 2199 fi
1987 dir="${dir%/*}" 2200 dir="${dir%/*}"
1988 done 2201 done
1989 done 2202 done
1990 done 2203 done
1991} 2204}
1992 2205
1993# @FUNCTION: python_mod_optimize 2206# @FUNCTION: python_mod_optimize
1994# @USAGE: [options] [directory|file] 2207# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
1995# @DESCRIPTION: 2208# @DESCRIPTION:
1996# If no arguments supplied, it will recompile not recursively all modules 2209# Byte-compile specified Python modules.
1997# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1998#
1999# If supplied with arguments, it will recompile all modules recursively
2000# in the supplied directory.
2001#
2002# Options passed to this function are passed to compileall.py. 2210# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2003# 2211#
2004# This function can be used only in pkg_postinst() phase. 2212# This function can be used only in pkg_postinst() phase.
2005python_mod_optimize() { 2213python_mod_optimize() {
2214 _python_check_python_pkg_setup_execution
2006 _python_initialize_prefix_variables 2215 _python_initialize_prefix_variables
2007 2216
2008 # Check if phase is pkg_postinst(). 2217 # Check if phase is pkg_postinst().
2009 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2218 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2010 2219
2011 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2220 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2012 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2221 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2013 local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 2222 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
2014 2223
2015 if _python_package_supporting_installation_for_multiple_python_abis; then 2224 if _python_package_supporting_installation_for_multiple_python_abis; then
2016 if [[ -z "${PYTHON_ABIS}" ]]; then 2225 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2017 die "${FUNCNAME}(): Environment not initialized" 2226 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2018 fi 2227 fi
2019 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2228 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2020 else 2229 else
2230 if has "${EAPI:-0}" 0 1 2 3; then
2021 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}" 2231 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2232 else
2233 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2234 fi
2022 fi 2235 fi
2023 2236
2024 # Strip trailing slash from EROOT. 2237 # Strip trailing slash from EROOT.
2025 root="${EROOT%/}" 2238 root="${EROOT%/}"
2026 2239
2027 while (($#)); do 2240 while (($#)); do
2028 case "$1" in 2241 case "$1" in
2242 --allow-evaluated-non-sitedir-paths)
2243 allow_evaluated_non_sitedir_paths="1"
2244 ;;
2029 -l|-f|-q) 2245 -l|-f|-q)
2030 options+=("$1") 2246 options+=("$1")
2031 ;; 2247 ;;
2032 -d|-x) 2248 -d|-x)
2033 options+=("$1" "$2") 2249 options+=("$1" "$2")
2034 shift 2250 shift
2035 ;; 2251 ;;
2252 --)
2253 shift
2254 break
2255 ;;
2036 -*) 2256 -*)
2037 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2257 die "${FUNCNAME}(): Unrecognized option '$1'"
2038 ;; 2258 ;;
2039 *) 2259 *)
2040 break 2260 break
2041 ;; 2261 ;;
2042 esac 2262 esac
2043 shift 2263 shift
2044 done 2264 done
2045 2265
2266 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2267 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2268 fi
2269
2046 if [[ "$#" -eq 0 ]]; then 2270 if [[ "$#" -eq 0 ]]; then
2047 _python_set_color_variables 2271 die "${FUNCNAME}(): Missing files or directories"
2048
2049 echo
2050 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2051 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2052 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2053 echo
2054
2055 einfo &> /dev/null
2056 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2057 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2058 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2059 einfo &> /dev/null
2060 fi 2272 fi
2061 2273
2062 while (($#)); do 2274 while (($#)); do
2275 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2276 die "${FUNCNAME}(): Invalid argument '$1'"
2063 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2277 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2064 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2278 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2065 elif [[ "$1" =~ ^/ ]]; then 2279 elif [[ "$1" =~ ^/ ]]; then
2066 if _python_package_supporting_installation_for_multiple_python_abis; then 2280 if _python_package_supporting_installation_for_multiple_python_abis; then
2281 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2067 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2282 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2068 fi 2283 fi
2069 if [[ -d "${root}$1" ]]; then 2284 if [[ "$1" != *\$* ]]; then
2070 other_dirs+=("${root}$1") 2285 die "${FUNCNAME}(): '$1' has invalid syntax"
2071 elif [[ -f "${root}$1" ]]; then 2286 fi
2072 other_files+=("${root}$1") 2287 if [[ "$1" == *.py ]]; then
2073 elif [[ -e "${root}$1" ]]; then 2288 evaluated_files+=("$1")
2074 eerror "'${root}$1' is not a file or a directory!" 2289 else
2290 evaluated_dirs+=("$1")
2291 fi
2075 else 2292 else
2293 if [[ -d "${root}$1" ]]; then
2294 other_dirs+=("${root}$1")
2295 elif [[ -f "${root}$1" ]]; then
2296 other_files+=("${root}$1")
2297 elif [[ -e "${root}$1" ]]; then
2298 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2299 else
2076 eerror "'${root}$1' does not exist!" 2300 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2301 fi
2077 fi 2302 fi
2078 else 2303 else
2079 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2304 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2080 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 2305 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2081 site_packages_dirs+=("$1") 2306 site_packages_dirs+=("$1")
2082 break 2307 break
2083 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then 2308 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2084 site_packages_files+=("$1") 2309 site_packages_files+=("$1")
2085 break 2310 break
2086 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then 2311 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2087 eerror "'$1' is not a file or a directory!" 2312 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2088 else 2313 else
2089 eerror "'$1' does not exist!" 2314 eerror "${FUNCNAME}(): '$1' does not exist"
2090 fi 2315 fi
2091 done 2316 done
2092 fi 2317 fi
2093 shift 2318 shift
2094 done 2319 done
2095 2320
2096 # Set additional options. 2321 # Set additional options.
2097 options+=("-q") 2322 options+=("-q")
2098 2323
2099 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2324 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2100 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2325 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2101 return_code="0" 2326 return_code="0"
2102 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2327 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
2103 if ((${#site_packages_dirs[@]})); then 2328 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2104 for dir in "${site_packages_dirs[@]}"; do 2329 for dir in "${site_packages_dirs[@]}"; do
2105 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2330 dirs+=("${root}$(python_get_sitedir)/${dir}")
2106 done 2331 done
2332 for dir in "${evaluated_dirs[@]}"; do
2333 eval "dirs+=(\"\${root}${dir}\")"
2334 done
2107 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2335 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
2108 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2336 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2109 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2337 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2110 fi 2338 fi
2111 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" 2339 _python_clean_compiled_modules "${dirs[@]}"
2112 fi 2340 fi
2113 if ((${#site_packages_files[@]})); then 2341 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2114 for file in "${site_packages_files[@]}"; do 2342 for file in "${site_packages_files[@]}"; do
2115 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2343 files+=("${root}$(python_get_sitedir)/${file}")
2116 done 2344 done
2345 for file in "${evaluated_files[@]}"; do
2346 eval "files+=(\"\${root}${file}\")"
2347 done
2117 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2348 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
2118 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2349 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2119 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2350 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2120 fi 2351 fi
2121 _python_clean_compiled_modules "${site_packages_absolute_files[@]}" 2352 _python_clean_compiled_modules "${files[@]}"
2122 fi 2353 fi
2123 eend "${return_code}" 2354 eend "${return_code}"
2124 fi 2355 fi
2125 unset site_packages_absolute_dirs site_packages_absolute_files 2356 unset dirs files
2126 done 2357 done
2127 2358
2128 if _python_package_supporting_installation_for_multiple_python_abis; then 2359 if _python_package_supporting_installation_for_multiple_python_abis; then
2129 # Restore previous value of PYTHON_ABI. 2360 # Restore previous value of PYTHON_ABI.
2130 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2361 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2147 if ((${#other_files[@]})); then 2378 if ((${#other_files[@]})); then
2148 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2379 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2149 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2380 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2150 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2381 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2151 fi 2382 fi
2152 _python_clean_compiled_modules "${other_dirs[@]}" 2383 _python_clean_compiled_modules "${other_files[@]}"
2153 fi 2384 fi
2154 eend "${return_code}" 2385 eend "${return_code}"
2155 fi 2386 fi
2156 else 2387 else
2157 # Deprecated part of python_mod_optimize() 2388 # Deprecated part of python_mod_optimize()
2389 # ewarn
2390 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2391 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2392 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2393 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2394 # ewarn
2158 2395
2159 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2396 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2160 2397
2161 # strip trailing slash 2398 # strip trailing slash
2162 myroot="${EROOT%/}" 2399 myroot="${EROOT%/}"
2169 ;; 2406 ;;
2170 -d|-x) 2407 -d|-x)
2171 myopts+=("$1" "$2") 2408 myopts+=("$1" "$2")
2172 shift 2409 shift
2173 ;; 2410 ;;
2411 --)
2412 shift
2413 break
2414 ;;
2174 -*) 2415 -*)
2175 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2416 die "${FUNCNAME}(): Unrecognized option '$1'"
2176 ;; 2417 ;;
2177 *) 2418 *)
2178 break 2419 break
2179 ;; 2420 ;;
2180 esac 2421 esac
2181 shift 2422 shift
2182 done 2423 done
2183 2424
2184 if [[ "$#" -eq 0 ]]; then 2425 if [[ "$#" -eq 0 ]]; then
2185 _python_set_color_variables 2426 die "${FUNCNAME}(): Missing files or directories"
2186
2187 echo
2188 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2189 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2190 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2191 echo
2192
2193 einfo &> /dev/null
2194 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2195 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2196 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2197 einfo &> /dev/null
2198 fi 2427 fi
2199 2428
2200 while (($#)); do 2429 while (($#)); do
2430 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2431 die "${FUNCNAME}(): Invalid argument '$1'"
2201 if [[ -d "${myroot}/${1#/}" ]]; then 2432 elif [[ -d "${myroot}/${1#/}" ]]; then
2202 mydirs+=("${myroot}/${1#/}") 2433 mydirs+=("${myroot}/${1#/}")
2203 elif [[ -f "${myroot}/${1#/}" ]]; then 2434 elif [[ -f "${myroot}/${1#/}" ]]; then
2204 # Files are passed to python_mod_compile which is EROOT-aware 2435 myfiles+=("${myroot}/${1#/}")
2205 myfiles+=("$1")
2206 elif [[ -e "${myroot}/${1#/}" ]]; then 2436 elif [[ -e "${myroot}/${1#/}" ]]; then
2207 eerror "${myroot}/${1#/} is not a file or directory!" 2437 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2208 else 2438 else
2209 eerror "${myroot}/${1#/} does not exist!" 2439 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2210 fi 2440 fi
2211 shift 2441 shift
2212 done 2442 done
2213 2443
2214 # set additional opts 2444 # set additional opts
2222 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2452 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2223 _python_clean_compiled_modules "${mydirs[@]}" 2453 _python_clean_compiled_modules "${mydirs[@]}"
2224 fi 2454 fi
2225 2455
2226 if ((${#myfiles[@]})); then 2456 if ((${#myfiles[@]})); then
2457 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2458 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2227 python_mod_compile "${myfiles[@]}" 2459 _python_clean_compiled_modules "${myfiles[@]}"
2228 fi 2460 fi
2229 2461
2230 eend "${return_code}" 2462 eend "${return_code}"
2231 fi 2463 fi
2232} 2464}
2233 2465
2234# @FUNCTION: python_mod_cleanup 2466# @FUNCTION: python_mod_cleanup
2235# @USAGE: [directory|file] 2467# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2236# @DESCRIPTION: 2468# @DESCRIPTION:
2237# Run with optional arguments, where arguments are Python modules. If none given, 2469# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2238# it will look in /usr/lib/python[0-9].[0-9].
2239#
2240# It will recursively scan all compiled Python modules in the directories and
2241# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2242# If they are, then it will remove their corresponding .pyc and .pyo files.
2243# 2470#
2244# This function can be used only in pkg_postrm() phase. 2471# This function can be used only in pkg_postrm() phase.
2245python_mod_cleanup() { 2472python_mod_cleanup() {
2473 _python_check_python_pkg_setup_execution
2246 _python_initialize_prefix_variables 2474 _python_initialize_prefix_variables
2247 2475
2248 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2476 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2249 2477
2250 # Check if phase is pkg_postrm(). 2478 # Check if phase is pkg_postrm().
2251 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2479 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2252 2480
2253 if _python_package_supporting_installation_for_multiple_python_abis; then 2481 if _python_package_supporting_installation_for_multiple_python_abis; then
2254 if [[ -z "${PYTHON_ABIS}" ]]; then 2482 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2255 die "${FUNCNAME}(): Environment not initialized" 2483 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2256 fi 2484 fi
2257 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2485 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2258 else 2486 else
2487 if has "${EAPI:-0}" 0 1 2 3; then
2259 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}" 2488 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2489 else
2490 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2491 fi
2260 fi 2492 fi
2261 2493
2262 # Strip trailing slash from EROOT. 2494 # Strip trailing slash from EROOT.
2263 root="${EROOT%/}" 2495 root="${EROOT%/}"
2264 2496
2497 while (($#)); do
2498 case "$1" in
2499 --allow-evaluated-non-sitedir-paths)
2500 allow_evaluated_non_sitedir_paths="1"
2501 ;;
2502 --)
2503 shift
2504 break
2505 ;;
2506 -*)
2507 die "${FUNCNAME}(): Unrecognized option '$1'"
2508 ;;
2509 *)
2510 break
2511 ;;
2512 esac
2513 shift
2514 done
2515
2516 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2517 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2518 fi
2519
2265 if [[ "$#" -gt 0 ]]; then 2520 if [[ "$#" -eq 0 ]]; then
2266 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2521 die "${FUNCNAME}(): Missing files or directories"
2522 fi
2523
2524 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2267 while (($#)); do 2525 while (($#)); do
2526 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2527 die "${FUNCNAME}(): Invalid argument '$1'"
2268 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2528 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2269 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" 2529 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2270 elif [[ "$1" =~ ^/ ]]; then 2530 elif [[ "$1" =~ ^/ ]]; then
2271 if _python_package_supporting_installation_for_multiple_python_abis; then 2531 if _python_package_supporting_installation_for_multiple_python_abis; then
2532 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2272 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2533 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2273 fi 2534 fi
2535 if [[ "$1" != *\$* ]]; then
2536 die "${FUNCNAME}(): '$1' has invalid syntax"
2537 fi
2538 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2539 eval "search_paths+=(\"\${root}$1\")"
2540 done
2541 else
2274 search_paths+=("${root}$1") 2542 search_paths+=("${root}$1")
2543 fi
2275 else 2544 else
2276 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2545 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2277 search_paths+=("${root}$(python_get_sitedir)/$1") 2546 search_paths+=("${root}$(python_get_sitedir)/$1")
2278 done
2279 fi
2280 shift
2281 done
2282 else
2283 # Deprecated part of python_mod_cleanup()
2284
2285 search_paths=("${@#/}")
2286 search_paths=("${search_paths[@]/#/${root}/}")
2287 fi
2288 else
2289 _python_set_color_variables
2290
2291 echo
2292 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2293 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2294 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2295 echo
2296
2297 einfo &> /dev/null
2298 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2299 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2300 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2301 einfo &> /dev/null
2302
2303 for dir in "${root}"/usr/lib*; do
2304 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2305 for sitedir in "${dir}"/python*/site-packages; do
2306 if [[ -d "${sitedir}" ]]; then
2307 search_paths+=("${sitedir}")
2308 fi
2309 done 2547 done
2310 fi 2548 fi
2549 shift
2311 done 2550 done
2312 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2551 else
2313 if [[ -d "${sitedir}" ]]; then 2552 # Deprecated part of python_mod_cleanup()
2553 # ewarn
2554 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2555 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2556 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2557 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2558 # ewarn
2559
2314 search_paths+=("${sitedir}") 2560 search_paths=("${@#/}")
2315 fi 2561 search_paths=("${search_paths[@]/#/${root}/}")
2316 done
2317 fi 2562 fi
2318 2563
2319 _python_clean_compiled_modules "${search_paths[@]}" 2564 _python_clean_compiled_modules "${search_paths[@]}"
2320} 2565}
2321 2566
2322# ================================================================================================ 2567# ================================================================================================
2323# ===================================== DEPRECATED FUNCTIONS ===================================== 2568# ===================================== DEPRECATED FUNCTIONS =====================================
2324# ================================================================================================ 2569# ================================================================================================
2325 2570
2326# @FUNCTION: python_version 2571# Scheduled for deletion on 2011-01-01.
2327# @DESCRIPTION:
2328# Run without arguments and it will export the version of python
2329# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2330python_version() { 2572python_version() {
2331 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2332 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2333 die "${FUNCNAME}() cannot be used in this EAPI"
2334 fi
2335
2336 _python_set_color_variables
2337
2338 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2339 echo
2340 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2341 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2342 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2343 echo
2344
2345 einfo &> /dev/null
2346 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2347 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null 2573 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2348 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2574 die "${FUNCNAME}() is banned"
2349 einfo &> /dev/null
2350 fi
2351
2352 [[ -n "${PYVER}" ]] && return 0
2353 local tmpstr
2354 python="${python:-${EPREFIX}/usr/bin/python}"
2355 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2356 export PYVER_ALL="${tmpstr#Python }"
2357 export PYVER_MAJOR="${PYVER_ALL:0:1}"
2358 export PYVER_MINOR="${PYVER_ALL:2:1}"
2359 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2360 export PYVER_MICRO="${PYVER_ALL:4}"
2361 fi
2362 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2363} 2575}
2364 2576
2365# @FUNCTION: python_mod_exists 2577# Scheduled for deletion on 2011-01-01.
2366# @USAGE: <module>
2367# @DESCRIPTION:
2368# Run with the module name as an argument. It will check if a
2369# Python module is installed and loadable. It will return
2370# TRUE(0) if the module exists, and FALSE(1) if the module does
2371# not exist.
2372#
2373# Example:
2374# if python_mod_exists gtk; then
2375# echo "gtk support enabled"
2376# fi
2377python_mod_exists() { 2578python_mod_exists() {
2378 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2379 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2579 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2380 die "${FUNCNAME}() cannot be used in this EAPI" 2580 die "${FUNCNAME}() is banned"
2381 fi
2382
2383 _python_set_color_variables
2384
2385 echo
2386 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2387 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2388 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2389 echo
2390
2391 eerror &> /dev/null
2392 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2393 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2394 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2395 eerror &> /dev/null
2396
2397 if [[ "$#" -ne 1 ]]; then
2398 die "${FUNCNAME}() requires 1 argument"
2399 fi
2400 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2401} 2581}
2402 2582
2403# @FUNCTION: python_tkinter_exists 2583# Scheduled for deletion on 2011-01-01.
2404# @DESCRIPTION:
2405# Run without arguments, checks if Python was compiled with Tkinter
2406# support. If not, prints an error message and dies.
2407python_tkinter_exists() { 2584python_tkinter_exists() {
2408 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2409 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2585 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2410 die "${FUNCNAME}() cannot be used in this EAPI" 2586 die "${FUNCNAME}() is banned"
2411 fi
2412
2413 _python_set_color_variables
2414
2415 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2416 echo
2417 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2418 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2419 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2420 echo
2421
2422 eerror &> /dev/null
2423 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2424 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2425 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2426 eerror &> /dev/null
2427 fi
2428
2429 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2430if version_info[0] == 3:
2431 import tkinter
2432else:
2433 import Tkinter" &> /dev/null; then
2434 eerror "Python needs to be rebuilt with tkinter support enabled."
2435 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2436 eerror "dev-lang/python tk"
2437 die "Python installed without support for tkinter"
2438 fi
2439} 2587}
2440 2588
2441# @FUNCTION: python_mod_compile 2589# Scheduled for deletion on 2011-04-01.
2442# @USAGE: <file> [more files ...]
2443# @DESCRIPTION:
2444# Given filenames, it will pre-compile the module's .pyc and .pyo.
2445# This function can be used only in pkg_postinst() phase.
2446#
2447# Example:
2448# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2449#
2450python_mod_compile() { 2590python_mod_compile() {
2451 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2452 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2591 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2453 die "${FUNCNAME}() cannot be used in this EAPI" 2592 die "${FUNCNAME}() is banned"
2454 fi
2455
2456 _python_initialize_prefix_variables
2457 _python_set_color_variables
2458
2459 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2460 echo
2461 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2462 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2463 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2464 echo
2465
2466 einfo &> /dev/null
2467 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2468 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2469 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2470 einfo &> /dev/null
2471 fi
2472
2473 local f myroot myfiles=()
2474
2475 # Check if phase is pkg_postinst()
2476 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2477
2478 # strip trailing slash
2479 myroot="${EROOT%/}"
2480
2481 # respect EROOT
2482 for f in "$@"; do
2483 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2484 done
2485
2486 PYTHON_ABI="$(PYTHON --ABI)"
2487
2488 if ((${#myfiles[@]})); then
2489 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2490 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2491 _python_clean_compiled_modules "${myfiles[@]}"
2492 else
2493 ewarn "No files to compile!"
2494 fi
2495} 2593}

Legend:
Removed from v.1.99  
changed lines
  Added in v.1.105

  ViewVC Help
Powered by ViewVC 1.1.20