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

Diff of /eclass/python.eclass

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

Revision 1.91 Revision 1.95
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.91 2010/02/28 15:49:33 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
188# @DESCRIPTION: 188# @DESCRIPTION:
189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
190# are respected. Only exported if one of those variables is set. 190# are respected. Only exported if one of those variables is set.
191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
192 python_pkg_setup() { 192 python_pkg_setup() {
193 # Check if phase is pkg_setup().
194 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
195
193 python_pkg_setup_fail() { 196 python_pkg_setup_fail() {
194 eerror "${1}" 197 eerror "${1}"
195 die "${1}" 198 die "${1}"
196 } 199 }
197 200
198 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return 201 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
202 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
203 use ${PYTHON_USE_WITH_OPT#!} && return
204 else
205 use !${PYTHON_USE_WITH_OPT} && return
206 fi
207 fi
199 208
200 python_pkg_setup_check_USE_flags() { 209 python_pkg_setup_check_USE_flags() {
201 local pyatom use 210 local pyatom use
202 pyatom="$(python_get_implementational_package)" 211 pyatom="$(python_get_implementational_package)"
203 212
216 if [[ ${PYTHON_USE_WITH_OR} ]]; then 225 if [[ ${PYTHON_USE_WITH_OR} ]]; then
217 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" 226 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
218 fi 227 fi
219 } 228 }
220 229
221 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 230 if _python_package_supporting_installation_for_multiple_python_abis; then
222 python_execute_function -q python_pkg_setup_check_USE_flags 231 python_execute_function -q python_pkg_setup_check_USE_flags
223 else 232 else
224 python_pkg_setup_check_USE_flags 233 python_pkg_setup_check_USE_flags
225 fi 234 fi
226 235
227 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail 236 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
228 } 237 }
229 238
230 EXPORT_FUNCTIONS pkg_setup 239 EXPORT_FUNCTIONS pkg_setup
231 240
232 _PYTHON_USE_WITH_ATOM="" 241 _PYTHON_USE_WITH_ATOMS_ARRAY=()
233 if [[ -n "${PYTHON_USE_WITH}" ]]; then 242 if [[ -n "${PYTHON_USE_WITH}" ]]; then
234 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 243 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
235 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 244 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]")
236 done 245 done
237 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )"
238 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 246 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
239 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 247 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
240 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 248 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
241 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${_USE_flag}]" 249 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
242 done 250 done
243 done 251 done
244 unset _USE_flag 252 unset _USE_flag
253 fi
254 if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
245 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )" 255 _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
256 else
257 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
246 fi 258 fi
247 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then 259 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
248 _PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOM} )" 260 _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
249 fi 261 fi
250 DEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 262 DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
251 RDEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 263 RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
252 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOM 264 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
253fi 265fi
254 266
255unset _PYTHON_ATOMS 267unset _PYTHON_ATOMS
256 268
257# ================================================================================================ 269# ================================================================================================
258# ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ======== 270# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
259# ================================================================================================ 271# ================================================================================================
260 272
261# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 273# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
262# @DESCRIPTION: 274# @DESCRIPTION:
263# Set this in EAPI <= 4 to indicate that current package supports installation for 275# Set this in EAPI <= 4 to indicate that current package supports installation for
264# multiple versions of Python. 276# multiple Python ABIs.
265 277
266# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 278# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
267# @DESCRIPTION: 279# @DESCRIPTION:
268# Set this to export phase functions for the following ebuild phases: 280# Set this to export phase functions for the following ebuild phases:
269# src_prepare, src_configure, src_compile, src_test, src_install. 281# src_prepare, src_configure, src_compile, src_test, src_install.
270if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 282if ! has "${EAPI:-0}" 0 1; then
271 python_src_prepare() { 283 python_src_prepare() {
284 if ! _python_package_supporting_installation_for_multiple_python_abis; then
285 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
286 fi
287
272 python_copy_sources 288 python_copy_sources
273 } 289 }
274 290
275 for python_default_function in src_configure src_compile src_test src_install; do 291 for python_default_function in src_configure src_compile src_test src_install; do
276 eval "python_${python_default_function}() { python_execute_function -d -s; }" 292 eval "python_${python_default_function}() {
293 if ! _python_package_supporting_installation_for_multiple_python_abis; then
294 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
295 fi
296
297 python_execute_function -d -s \"\$@\"
298 }"
277 done 299 done
278 unset python_default_function 300 unset python_default_function
279 301
280 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 302 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
281 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 303 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
287# @FUNCTION: validate_PYTHON_ABIS 309# @FUNCTION: validate_PYTHON_ABIS
288# @DESCRIPTION: 310# @DESCRIPTION:
289# Ensure that PYTHON_ABIS variable has valid value. 311# Ensure that PYTHON_ABIS variable has valid value.
290# This function usually should not be directly called in ebuilds. 312# This function usually should not be directly called in ebuilds.
291validate_PYTHON_ABIS() { 313validate_PYTHON_ABIS() {
292 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable. 314 if ! _python_package_supporting_installation_for_multiple_python_abis; then
293 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 315 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
294 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
295 fi 316 fi
296 317
297 _python_initial_sanity_checks 318 _python_initial_sanity_checks
298 319
299 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. 320 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
300 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 321 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
301 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 322 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS=
302 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 323 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}"
303 324
304 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 325 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
305 local python2_enabled="0" python3_enabled="0" 326 local cpython_enabled="0"
306 327
307 if [[ -z "${USE_PYTHON}" ]]; then 328 if [[ -z "${USE_PYTHON}" ]]; then
308 die "USE_PYTHON variable is empty" 329 die "USE_PYTHON variable is empty"
309 fi 330 fi
310 331
311 for PYTHON_ABI in ${USE_PYTHON}; do 332 for PYTHON_ABI in ${USE_PYTHON}; do
312 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 333 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
313 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 334 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
314 fi 335 fi
315 336
316 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}"; then 337 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
317 python2_enabled="1" 338 cpython_enabled="1"
318 fi
319 if has "${PYTHON_ABI}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
320 python3_enabled="1"
321 fi 339 fi
322 340
323 support_ABI="1" 341 support_ABI="1"
324 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 342 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
325 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 343 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
329 done 347 done
330 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 348 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
331 done 349 done
332 350
333 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 351 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
334 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}" 352 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
335 fi 353 fi
336 354
337 if [[ "${python2_enabled}" == "0" ]]; then 355 if [[ "${cpython_enabled}" == "0" ]]; then
338 ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported."
339 fi
340 if [[ "${python3_enabled}" == "0" ]]; then
341 ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported."
342 fi
343 if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "0" ]]; then
344 die "USE_PYTHON variable does not enable any version of CPython" 356 die "USE_PYTHON variable does not enable any CPython ABI"
345 fi 357 fi
346 else 358 else
347 local python_version python2_version= python3_version= support_python_major_version 359 local python_version python2_version= python3_version= support_python_major_version
348 360
349 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 361 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
426# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] 438# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments]
427# @DESCRIPTION: 439# @DESCRIPTION:
428# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 440# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
429# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 441# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
430python_execute_function() { 442python_execute_function() {
443 if ! _python_package_supporting_installation_for_multiple_python_abis; then
444 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
445 fi
446
431 _python_set_color_variables 447 _python_set_color_variables
432 448
433 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= 449 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir=
434 450
435 while (($#)); do 451 while (($#)); do
488 504
489 if [[ -z "$(type -t "${function}")" ]]; then 505 if [[ -z "$(type -t "${function}")" ]]; then
490 die "${FUNCNAME}(): '${function}' function is not defined" 506 die "${FUNCNAME}(): '${function}' function is not defined"
491 fi 507 fi
492 else 508 else
493 if [[ "$#" -ne 0 ]]; then
494 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
495 fi
496 if has "${EAPI:-0}" 0 1; then 509 if has "${EAPI:-0}" 0 1; then
497 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" 510 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
498 fi 511 fi
499 512
500 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 513 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
501 if has "${EAPI}" 2 3; then 514 if has "${EAPI}" 2 3; then
502 python_default_function() { 515 python_default_function() {
503 econf 516 econf "$@"
504 } 517 }
505 else 518 else
506 python_default_function() { 519 python_default_function() {
507 nonfatal econf 520 nonfatal econf "$@"
508 } 521 }
509 fi 522 fi
510 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 523 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
511 python_default_function() { 524 python_default_function() {
512 emake 525 emake "$@"
513 } 526 }
514 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 527 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
515 python_default_function() { 528 python_default_function() {
516 if emake -j1 -n check &> /dev/null; then 529 if emake -j1 -n check &> /dev/null; then
517 emake -j1 check 530 emake -j1 check "$@"
518 elif emake -j1 -n test &> /dev/null; then 531 elif emake -j1 -n test &> /dev/null; then
519 emake -j1 test 532 emake -j1 test "$@"
520 fi 533 fi
521 } 534 }
522 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 535 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
523 python_default_function() { 536 python_default_function() {
524 emake DESTDIR="${D}" install 537 emake DESTDIR="${D}" install "$@"
525 } 538 }
526 else 539 else
527 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" 540 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
528 fi 541 fi
529 function="python_default_function" 542 function="python_default_function"
530 fi 543 fi
531 544
545 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
532 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 546 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do
533 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then 547 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
534 die "${FUNCNAME}(): Invalid call stack" 548 die "${FUNCNAME}(): Invalid call stack"
535 fi 549 fi
536 done 550 done
607 fi 621 fi
608 if [[ "${quiet}" == "0" ]]; then 622 if [[ "${quiet}" == "0" ]]; then
609 ewarn "${_RED}${failure_message}${_NORMAL}" 623 ewarn "${_RED}${failure_message}${_NORMAL}"
610 fi 624 fi
611 if [[ -z "${PYTHON_ABIS}" ]]; then 625 if [[ -z "${PYTHON_ABIS}" ]]; then
612 die "${function}() function failed with all enabled versions of Python" 626 die "${function}() function failed with all enabled Python ABIs"
613 fi 627 fi
614 else 628 else
615 die "${failure_message}" 629 die "${failure_message}"
616 fi 630 fi
617 fi 631 fi
651# @FUNCTION: python_copy_sources 665# @FUNCTION: python_copy_sources
652# @USAGE: <directory="${S}"> [directory] 666# @USAGE: <directory="${S}"> [directory]
653# @DESCRIPTION: 667# @DESCRIPTION:
654# Copy unpacked sources of current package to separate build directory for each Python ABI. 668# Copy unpacked sources of current package to separate build directory for each Python ABI.
655python_copy_sources() { 669python_copy_sources() {
670 if ! _python_package_supporting_installation_for_multiple_python_abis; then
671 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
672 fi
673
656 local dir dirs=() PYTHON_ABI 674 local dir dirs=() PYTHON_ABI
657 675
658 if [[ "$#" -eq 0 ]]; then 676 if [[ "$#" -eq 0 ]]; then
659 if [[ "${WORKDIR}" == "${S}" ]]; then 677 if [[ "${WORKDIR}" == "${S}" ]]; then
660 die "${FUNCNAME}() cannot be used" 678 die "${FUNCNAME}() cannot be used"
661 fi 679 fi
662 dirs=("${S}") 680 dirs=("${S%/}")
663 else 681 else
664 dirs=("$@") 682 dirs=("$@")
665 fi 683 fi
666 684
667 validate_PYTHON_ABIS 685 validate_PYTHON_ABIS
670 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 688 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
671 done 689 done
672 done 690 done
673} 691}
674 692
675# @FUNCTION: python_set_build_dir_symlink
676# @USAGE: <directory="build">
677# @DESCRIPTION:
678# Create build directory symlink.
679python_set_build_dir_symlink() {
680 local dir="$1"
681
682 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
683 [[ -z "${dir}" ]] && dir="build"
684
685 # Do not delete preexistent directories.
686 rm -f "${dir}" || die "Deletion of '${dir}' failed"
687 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
688}
689
690# @FUNCTION: python_generate_wrapper_scripts 693# @FUNCTION: python_generate_wrapper_scripts
691# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 694# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
692# @DESCRIPTION: 695# @DESCRIPTION:
693# Generate wrapper scripts. Existing files are overwritten only with --force option. 696# Generate wrapper scripts. Existing files are overwritten only with --force option.
694# If --respect-EPYTHON option is specified, then generated wrapper scripts will 697# If --respect-EPYTHON option is specified, then generated wrapper scripts will
695# respect EPYTHON variable at run time. 698# respect EPYTHON variable at run time.
696python_generate_wrapper_scripts() { 699python_generate_wrapper_scripts() {
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then
701 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi
703
697 _python_initialize_prefix_variables 704 _python_initialize_prefix_variables
698 705
699 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 706 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
700 707
701 while (($#)); do 708 while (($#)); do
753 if [[ -f "${file}" && "${force}" == "0" ]]; then 760 if [[ -f "${file}" && "${force}" == "0" ]]; then
754 die "${FUNCNAME}(): '$1' already exists" 761 die "${FUNCNAME}(): '$1' already exists"
755 fi 762 fi
756 763
757 if [[ "${quiet}" == "0" ]]; then 764 if [[ "${quiet}" == "0" ]]; then
758 einfo "Generating '${file#${D%/}}' wrapper script" 765 einfo "Generating '${file#${ED%/}}' wrapper script"
759 fi 766 fi
760 767
761 cat << EOF > "${file}" 768 cat << EOF > "${file}"
762#!/usr/bin/env python 769#!/usr/bin/env python
763# Gentoo '${file##*/}' wrapper script 770# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
764 771
765import os 772import os
766import re 773import re
767import subprocess 774import subprocess
768import sys 775import sys
769 776
770EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 777EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
778python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
779python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
771 780
772EOF 781EOF
773 if [[ "$?" != "0" ]]; then 782 if [[ "$?" != "0" ]]; then
774 die "${FUNCNAME}(): Generation of '$1' failed" 783 die "${FUNCNAME}(): Generation of '$1' failed"
775 fi 784 fi
790 raise ValueError 799 raise ValueError
791 except (OSError, ValueError): 800 except (OSError, ValueError):
792 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 801 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
793 sys.exit(1) 802 sys.exit(1)
794 803
795 eselect_output = eselect_process.stdout.read() 804 EPYTHON = eselect_process.stdout.read()
796 if not isinstance(eselect_output, str): 805 if not isinstance(EPYTHON, str):
797 # Python 3 806 # Python 3
798 eselect_output = eselect_output.decode() 807 EPYTHON = EPYTHON.decode()
808 EPYTHON = EPYTHON.rstrip("\n")
799 809
800 EPYTHON_matched = EPYTHON_re.match(eselect_output) 810 EPYTHON_matched = EPYTHON_re.match(EPYTHON)
801 if EPYTHON_matched: 811 if EPYTHON_matched:
802 PYTHON_ABI = EPYTHON_matched.group(1) 812 PYTHON_ABI = EPYTHON_matched.group(1)
803 else: 813 else:
804 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 814 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
805 sys.exit(1) 815 sys.exit(1)
806EOF 816EOF
807 if [[ "$?" != "0" ]]; then 817 if [[ "$?" != "0" ]]; then
808 die "${FUNCNAME}(): Generation of '$1' failed" 818 die "${FUNCNAME}(): Generation of '$1' failed"
809 fi 819 fi
815 raise ValueError 825 raise ValueError
816except (OSError, ValueError): 826except (OSError, ValueError):
817 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 827 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
818 sys.exit(1) 828 sys.exit(1)
819 829
820eselect_output = eselect_process.stdout.read() 830EPYTHON = eselect_process.stdout.read()
821if not isinstance(eselect_output, str): 831if not isinstance(EPYTHON, str):
822 # Python 3 832 # Python 3
823 eselect_output = eselect_output.decode() 833 EPYTHON = EPYTHON.decode()
834EPYTHON = EPYTHON.rstrip("\n")
824 835
825EPYTHON_matched = EPYTHON_re.match(eselect_output) 836EPYTHON_matched = EPYTHON_re.match(EPYTHON)
826if EPYTHON_matched: 837if EPYTHON_matched:
827 PYTHON_ABI = EPYTHON_matched.group(1) 838 PYTHON_ABI = EPYTHON_matched.group(1)
828else: 839else:
829 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 840 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
830 sys.exit(1) 841 sys.exit(1)
831EOF 842EOF
832 if [[ "$?" != "0" ]]; then 843 if [[ "$?" != "0" ]]; then
833 die "${FUNCNAME}(): Generation of '$1' failed" 844 die "${FUNCNAME}(): Generation of '$1' failed"
834 fi 845 fi
835 fi 846 fi
836 cat << EOF >> "${file}" 847 cat << EOF >> "${file}"
837 848
849wrapper_script_path = os.path.realpath(sys.argv[0])
850target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
838os.environ["PYTHON_SCRIPT_NAME"] = sys.argv[0] 851os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
839target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) 852os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
840if not os.path.exists(target_executable): 853if not os.path.exists(target_executable_path):
841 sys.stderr.write("'%s' does not exist\n" % target_executable) 854 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
842 sys.exit(1) 855 sys.exit(1)
843 856
857target_executable = open(target_executable_path, "rb")
858target_executable_first_line = target_executable.readline()
859if not isinstance(target_executable_first_line, str):
860 # Python 3
861 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
862
863python_shebang_matched = python_shebang_re.match(target_executable_first_line)
864target_executable.close()
865
866if python_shebang_matched:
867 try:
868 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
869 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
870 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
871 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
872 if python_verification_process.wait() != 0:
873 raise ValueError
874
875 python_verification_output = python_verification_process.stdout.read()
876 if not isinstance(python_verification_output, str):
877 # Python 3
878 python_verification_output = python_verification_output.decode()
879
880 if not python_verification_output_re.match(python_verification_output):
881 raise ValueError
882
883 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
884 except:
885 pass
886 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
887 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
888
844os.execv(target_executable, sys.argv) 889os.execv(target_executable_path, sys.argv)
845EOF 890EOF
846 if [[ "$?" != "0" ]]; then 891 if [[ "$?" != "0" ]]; then
847 die "${FUNCNAME}(): Generation of '$1' failed" 892 die "${FUNCNAME}(): Generation of '$1' failed"
848 fi 893 fi
849 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" 894 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
850 done 895 done
851} 896}
852 897
853# ================================================================================================ 898# ================================================================================================
854# ====== FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ====== 899# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
855# ================================================================================================ 900# ================================================================================================
856 901
857# @FUNCTION: python_set_active_version 902# @FUNCTION: python_set_active_version
858# @USAGE: <CPython_ABI|2|3> 903# @USAGE: <CPython_ABI|2|3>
859# @DESCRIPTION: 904# @DESCRIPTION:
860# Set specified version of CPython as active version of Python. 905# Set specified version of CPython as active version of Python.
861python_set_active_version() { 906python_set_active_version() {
862 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 907 if _python_package_supporting_installation_for_multiple_python_abis; then
863 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 908 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
864 fi 909 fi
865 910
866 if [[ "$#" -ne 1 ]]; then 911 if [[ "$#" -ne 1 ]]; then
867 die "${FUNCNAME}() requires 1 argument" 912 die "${FUNCNAME}() requires 1 argument"
868 fi 913 fi
901 946
902# @FUNCTION: python_need_rebuild 947# @FUNCTION: python_need_rebuild
903# @DESCRIPTION: Mark current package for rebuilding by python-updater after 948# @DESCRIPTION: Mark current package for rebuilding by python-updater after
904# switching of active version of Python. 949# switching of active version of Python.
905python_need_rebuild() { 950python_need_rebuild() {
906 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 951 if _python_package_supporting_installation_for_multiple_python_abis; then
907 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 952 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
908 fi 953 fi
909 954
910 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 955 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
911} 956}
912 957
989 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1034 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
990 fi 1035 fi
991 1036
992 if [[ "$#" -eq 0 ]]; then 1037 if [[ "$#" -eq 0 ]]; then
993 if [[ "${final_ABI}" == "1" ]]; then 1038 if [[ "${final_ABI}" == "1" ]]; then
994 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1039 if ! _python_package_supporting_installation_for_multiple_python_abis; then
995 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" 1040 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
996 fi 1041 fi
997 validate_PYTHON_ABIS 1042 validate_PYTHON_ABIS
998 PYTHON_ABI="${PYTHON_ABIS##* }" 1043 PYTHON_ABI="${PYTHON_ABIS##* }"
999 elif [[ "${python2}" == "1" ]]; then 1044 elif [[ "${python2}" == "1" ]]; then
1000 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1045 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1008 if [[ -z "${PYTHON_ABI}" ]]; then 1053 if [[ -z "${PYTHON_ABI}" ]]; then
1009 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1054 die "${FUNCNAME}(): Active Python 3 interpreter not set"
1010 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1055 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1011 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1056 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1012 fi 1057 fi
1013 elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 1058 elif ! _python_package_supporting_installation_for_multiple_python_abis; then
1014 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1059 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1015 elif [[ -z "${PYTHON_ABI}" ]]; then 1060 elif [[ -z "${PYTHON_ABI}" ]]; then
1016 die "${FUNCNAME}(): Invalid usage: Python ABI not specified" 1061 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1017 fi 1062 fi
1018 elif [[ "$#" -eq 1 ]]; then 1063 elif [[ "$#" -eq 1 ]]; then
1019 if [[ "${final_ABI}" == "1" ]]; then 1064 if [[ "${final_ABI}" == "1" ]]; then
1020 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1065 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1021 fi 1066 fi
1074 esac 1119 esac
1075 shift 1120 shift
1076 done 1121 done
1077 1122
1078 if [[ "${final_ABI}" == "1" ]]; then 1123 if [[ "${final_ABI}" == "1" ]]; then
1124 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1125 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1126 fi
1079 PYTHON_ABI="$(PYTHON -f --ABI)" 1127 PYTHON_ABI="$(PYTHON -f --ABI)"
1080 elif [[ -z "${PYTHON_ABI}" ]]; then 1128 elif [[ -z "${PYTHON_ABI}" ]]; then
1081 PYTHON_ABI="$(PYTHON --ABI)" 1129 PYTHON_ABI="$(PYTHON --ABI)"
1082 fi 1130 fi
1083 1131
1106 esac 1154 esac
1107 shift 1155 shift
1108 done 1156 done
1109 1157
1110 if [[ "${final_ABI}" == "1" ]]; then 1158 if [[ "${final_ABI}" == "1" ]]; then
1159 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1160 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1161 fi
1111 PYTHON_ABI="$(PYTHON -f --ABI)" 1162 PYTHON_ABI="$(PYTHON -f --ABI)"
1112 elif [[ -z "${PYTHON_ABI}" ]]; then 1163 elif [[ -z "${PYTHON_ABI}" ]]; then
1113 PYTHON_ABI="$(PYTHON --ABI)" 1164 PYTHON_ABI="$(PYTHON --ABI)"
1114 fi 1165 fi
1115 1166
1142 esac 1193 esac
1143 shift 1194 shift
1144 done 1195 done
1145 1196
1146 if [[ "${final_ABI}" == "1" ]]; then 1197 if [[ "${final_ABI}" == "1" ]]; then
1198 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1199 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1200 fi
1147 PYTHON_ABI="$(PYTHON -f --ABI)" 1201 PYTHON_ABI="$(PYTHON -f --ABI)"
1148 elif [[ -z "${PYTHON_ABI}" ]]; then 1202 elif [[ -z "${PYTHON_ABI}" ]]; then
1149 PYTHON_ABI="$(PYTHON --ABI)" 1203 PYTHON_ABI="$(PYTHON --ABI)"
1150 fi 1204 fi
1151 1205
1178 esac 1232 esac
1179 shift 1233 shift
1180 done 1234 done
1181 1235
1182 if [[ "${final_ABI}" == "1" ]]; then 1236 if [[ "${final_ABI}" == "1" ]]; then
1237 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1238 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1239 fi
1183 PYTHON_ABI="$(PYTHON -f --ABI)" 1240 PYTHON_ABI="$(PYTHON -f --ABI)"
1184 elif [[ -z "${PYTHON_ABI}" ]]; then 1241 elif [[ -z "${PYTHON_ABI}" ]]; then
1185 PYTHON_ABI="$(PYTHON --ABI)" 1242 PYTHON_ABI="$(PYTHON --ABI)"
1186 fi 1243 fi
1187 1244
1201 local options=() 1258 local options=()
1202 1259
1203 while (($#)); do 1260 while (($#)); do
1204 case "$1" in 1261 case "$1" in
1205 -f|--final-ABI) 1262 -f|--final-ABI)
1263 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1264 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1265 fi
1206 options+=("$1") 1266 options+=("$1")
1207 ;; 1267 ;;
1208 -*) 1268 -*)
1209 die "${FUNCNAME}(): Unrecognized option '$1'" 1269 die "${FUNCNAME}(): Unrecognized option '$1'"
1210 ;; 1270 ;;
1244 esac 1304 esac
1245 shift 1305 shift
1246 done 1306 done
1247 1307
1248 if [[ "${final_ABI}" == "1" ]]; then 1308 if [[ "${final_ABI}" == "1" ]]; then
1309 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1310 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1311 fi
1249 PYTHON_ABI="$(PYTHON -f --ABI)" 1312 PYTHON_ABI="$(PYTHON -f --ABI)"
1250 elif [[ -z "${PYTHON_ABI}" ]]; then 1313 elif [[ -z "${PYTHON_ABI}" ]]; then
1251 PYTHON_ABI="$(PYTHON --ABI)" 1314 PYTHON_ABI="$(PYTHON --ABI)"
1252 fi 1315 fi
1253 1316
1261 die "${FUNCNAME}(): Jython does not have shared library" 1324 die "${FUNCNAME}(): Jython does not have shared library"
1262 fi 1325 fi
1263} 1326}
1264 1327
1265# @FUNCTION: python_get_version 1328# @FUNCTION: python_get_version
1266# @USAGE: [-f|--final-ABI] [--major] [--minor] [--micro] 1329# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro]
1267# @DESCRIPTION: 1330# @DESCRIPTION:
1268# Print Python version. 1331# Print Python version.
1269# --major, --minor and --micro options cannot be specified simultaneously. 1332# --full, --major, --minor and --micro options cannot be specified simultaneously.
1270# If --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1333# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1271# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1334# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1272python_get_version() { 1335python_get_version() {
1273 local final_ABI="0" major="0" minor="0" micro="0" python_command 1336 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1274 1337
1275 while (($#)); do 1338 while (($#)); do
1276 case "$1" in 1339 case "$1" in
1277 -f|--final-ABI) 1340 -f|--final-ABI)
1278 final_ABI="1" 1341 final_ABI="1"
1279 ;; 1342 ;;
1343 --full)
1344 full="1"
1345 ;;
1280 --major) 1346 --major)
1281 major="1" 1347 major="1"
1282 ;; 1348 ;;
1283 --minor) 1349 --minor)
1284 minor="1" 1350 minor="1"
1294 ;; 1360 ;;
1295 esac 1361 esac
1296 shift 1362 shift
1297 done 1363 done
1298 1364
1299 if [[ "$((${major} + ${minor} + ${micro}))" -gt 1 ]]; then 1365 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
1300 die "${FUNCNAME}(): '--major', '--minor' or '--micro' options cannot be specified simultaneously" 1366 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
1301 fi 1367 fi
1302 1368
1369 if [[ "${full}" == "1" ]]; then
1370 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
1303 if [[ "${major}" == "1" ]]; then 1371 elif [[ "${major}" == "1" ]]; then
1304 python_command="from sys import version_info; print(version_info[0])" 1372 python_command="from sys import version_info; print(version_info[0])"
1305 elif [[ "${minor}" == "1" ]]; then 1373 elif [[ "${minor}" == "1" ]]; then
1306 python_command="from sys import version_info; print(version_info[1])" 1374 python_command="from sys import version_info; print(version_info[1])"
1307 elif [[ "${micro}" == "1" ]]; then 1375 elif [[ "${micro}" == "1" ]]; then
1308 python_command="from sys import version_info; print(version_info[2])" 1376 python_command="from sys import version_info; print(version_info[2])"
1309 else 1377 else
1378 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
1379 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1380 echo "${PYTHON_ABI}"
1381 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1382 echo "${PYTHON_ABI%-jython}"
1383 fi
1384 return
1385 fi
1310 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" 1386 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1311 fi 1387 fi
1312 1388
1313 if [[ "${final_ABI}" == "1" ]]; then 1389 if [[ "${final_ABI}" == "1" ]]; then
1390 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1391 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1392 fi
1314 "$(PYTHON -f)" -c "${python_command}" 1393 "$(PYTHON -f)" -c "${python_command}"
1315 else 1394 else
1316 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1395 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1317 fi 1396 fi
1318} 1397}
1326 return 0 1405 return 0
1327 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then 1406 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1328 return 0 1407 return 0
1329 else 1408 else
1330 return 1 1409 return 1
1410 fi
1411}
1412
1413_python_package_supporting_installation_for_multiple_python_abis() {
1414 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1415 die "${FUNCNAME}() cannot be used in global scope"
1416 fi
1417
1418 if has "${EAPI:-0}" 0 1 2 3 4; then
1419 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1420 return 0
1421 else
1422 return 1
1423 fi
1424 else
1425 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1331 fi 1426 fi
1332} 1427}
1333 1428
1334_python_initialize_prefix_variables() { 1429_python_initialize_prefix_variables() {
1335 if has "${EAPI:-0}" 0 1 2; then 1430 if has "${EAPI:-0}" 0 1 2; then
1448 die "${FUNCNAME}(): '${argument}' does not exist" 1543 die "${FUNCNAME}(): '${argument}' does not exist"
1449 elif [[ -f "${argument}" ]]; then 1544 elif [[ -f "${argument}" ]]; then
1450 files+=("${argument}") 1545 files+=("${argument}")
1451 elif [[ -d "${argument}" ]]; then 1546 elif [[ -d "${argument}" ]]; then
1452 if [[ "${recursive}" == "1" ]]; then 1547 if [[ "${recursive}" == "1" ]]; then
1453 if [[ "${only_executables}" == "1" ]]; then 1548 while read -d $'\0' -r file; do
1454 files+=($(find "${argument}" -perm /111 -type f)) 1549 files+=("${file}")
1455 else 1550 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1456 files+=($(find "${argument}" -type f))
1457 fi
1458 else 1551 else
1459 die "${FUNCNAME}(): '${argument}' is not a regular file" 1552 die "${FUNCNAME}(): '${argument}' is not a regular file"
1460 fi 1553 fi
1461 else 1554 else
1462 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" 1555 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1466 for file in "${files[@]}"; do 1559 for file in "${files[@]}"; do
1467 file="${file#./}" 1560 file="${file#./}"
1468 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue 1561 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1469 1562
1470 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then 1563 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1564 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1565
1471 if [[ "${quiet}" == "0" ]]; then 1566 if [[ "${quiet}" == "0" ]]; then
1472 einfo "Converting shebang in '${file}'" 1567 einfo "Converting shebang in '${file}'"
1473 fi 1568 fi
1569
1474 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" 1570 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1475 1571
1476 # Delete potential whitespace after "#!". 1572 # Delete potential whitespace after "#!".
1477 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 1573 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1478 fi 1574 fi
1479 done 1575 done
1576}
1577
1578# @FUNCTION: python_clean_sitedirs
1579# @DESCRIPTION:
1580# Delete needless files in site-packages directories in ${ED}.
1581python_clean_sitedirs() {
1582 _python_initialize_prefix_variables
1583
1584 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1480} 1585}
1481 1586
1482# ================================================================================================ 1587# ================================================================================================
1483# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1588# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1484# ================================================================================================ 1589# ================================================================================================
1487# @DESCRIPTION: 1592# @DESCRIPTION:
1488# User-configurable verbosity of tests of Python modules. 1593# User-configurable verbosity of tests of Python modules.
1489# Supported values: 0, 1, 2, 3, 4. 1594# Supported values: 0, 1, 2, 3, 4.
1490PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}" 1595PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
1491 1596
1597_python_test_hook() {
1598 if [[ "$#" -ne 1 ]]; then
1599 die "${FUNCNAME}() requires 1 argument"
1600 fi
1601
1602 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
1603 "${FUNCNAME[3]}_$1_hook"
1604 fi
1605}
1606
1492# @FUNCTION: python_execute_nosetests 1607# @FUNCTION: python_execute_nosetests
1493# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1608# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1494# @DESCRIPTION: 1609# @DESCRIPTION:
1495# Execute nosetests for all enabled versions of Python. 1610# Execute nosetests for all enabled Python ABIs.
1611# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1612# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1496python_execute_nosetests() { 1613python_execute_nosetests() {
1497 _python_set_color_variables 1614 _python_set_color_variables
1498 1615
1499 local PYTHONPATH_template= separate_build_dirs= 1616 local PYTHONPATH_template= separate_build_dirs=
1500 1617
1529 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1646 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1530 unset evaluated_PYTHONPATH 1647 unset evaluated_PYTHONPATH
1531 fi 1648 fi
1532 fi 1649 fi
1533 1650
1651 _python_test_hook pre
1652
1534 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1653 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1535 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1654 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1536 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1655 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1537 else 1656 else
1538 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1657 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1539 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1658 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1540 fi 1659 fi
1660
1661 _python_test_hook post
1541 } 1662 }
1542 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1663 if _python_package_supporting_installation_for_multiple_python_abis; then
1543 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1664 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1544 else 1665 else
1545 if [[ -n "${separate_build_dirs}" ]]; then 1666 if [[ -n "${separate_build_dirs}" ]]; then
1546 die "${FUNCNAME}(): Invalid usage" 1667 die "${FUNCNAME}(): Invalid usage"
1547 fi 1668 fi
1552} 1673}
1553 1674
1554# @FUNCTION: python_execute_py.test 1675# @FUNCTION: python_execute_py.test
1555# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1676# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1556# @DESCRIPTION: 1677# @DESCRIPTION:
1557# Execute py.test for all enabled versions of Python. 1678# Execute py.test for all enabled Python ABIs.
1679# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1680# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1558python_execute_py.test() { 1681python_execute_py.test() {
1559 _python_set_color_variables 1682 _python_set_color_variables
1560 1683
1561 local PYTHONPATH_template= separate_build_dirs= 1684 local PYTHONPATH_template= separate_build_dirs=
1562 1685
1591 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1714 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1592 unset evaluated_PYTHONPATH 1715 unset evaluated_PYTHONPATH
1593 fi 1716 fi
1594 fi 1717 fi
1595 1718
1719 _python_test_hook pre
1720
1596 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1721 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1597 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1722 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1598 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" 1723 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
1599 else 1724 else
1600 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} 1725 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
1601 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" 1726 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
1602 fi 1727 fi
1728
1729 _python_test_hook post
1603 } 1730 }
1604 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1731 if _python_package_supporting_installation_for_multiple_python_abis; then
1605 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1732 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1606 else 1733 else
1607 if [[ -n "${separate_build_dirs}" ]]; then 1734 if [[ -n "${separate_build_dirs}" ]]; then
1608 die "${FUNCNAME}(): Invalid usage" 1735 die "${FUNCNAME}(): Invalid usage"
1609 fi 1736 fi
1614} 1741}
1615 1742
1616# @FUNCTION: python_execute_trial 1743# @FUNCTION: python_execute_trial
1617# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1744# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1618# @DESCRIPTION: 1745# @DESCRIPTION:
1619# Execute trial for all enabled versions of Python. 1746# Execute trial for all enabled Python ABIs.
1747# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1748# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1620python_execute_trial() { 1749python_execute_trial() {
1621 _python_set_color_variables 1750 _python_set_color_variables
1622 1751
1623 local PYTHONPATH_template= separate_build_dirs= 1752 local PYTHONPATH_template= separate_build_dirs=
1624 1753
1653 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1782 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1654 unset evaluated_PYTHONPATH 1783 unset evaluated_PYTHONPATH
1655 fi 1784 fi
1656 fi 1785 fi
1657 1786
1787 _python_test_hook pre
1788
1658 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1789 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1659 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1790 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1660 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1791 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1661 else 1792 else
1662 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1793 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1663 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1794 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1664 fi 1795 fi
1796
1797 _python_test_hook post
1665 } 1798 }
1666 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1799 if _python_package_supporting_installation_for_multiple_python_abis; then
1667 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1800 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1668 else 1801 else
1669 if [[ -n "${separate_build_dirs}" ]]; then 1802 if [[ -n "${separate_build_dirs}" ]]; then
1670 die "${FUNCNAME}(): Invalid usage" 1803 die "${FUNCNAME}(): Invalid usage"
1671 fi 1804 fi
1702# If no arguments supplied, it will recompile not recursively all modules 1835# If no arguments supplied, it will recompile not recursively all modules
1703# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). 1836# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1704# 1837#
1705# If supplied with arguments, it will recompile all modules recursively 1838# If supplied with arguments, it will recompile all modules recursively
1706# in the supplied directory. 1839# in the supplied directory.
1707# This function should only be run in pkg_postinst().
1708# 1840#
1709# Options passed to this function are passed to compileall.py. 1841# Options passed to this function are passed to compileall.py.
1710# 1842#
1711# Example: 1843# This function can be used only in pkg_postinst() phase.
1712# python_mod_optimize ctypesgencore
1713python_mod_optimize() { 1844python_mod_optimize() {
1714 _python_initialize_prefix_variables 1845 _python_initialize_prefix_variables
1715 1846
1716 # Check if phase is pkg_postinst(). 1847 # Check if phase is pkg_postinst().
1717 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 1848 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1718 1849
1719 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1850 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1720 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 1851 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1721 1852
1722 # Strip trailing slash from ROOT. 1853 # Strip trailing slash from ROOT.
1723 root="${EROOT%/}" 1854 root="${EROOT%/}"
1724 1855
1882# 2013#
1883# It will recursively scan all compiled Python modules in the directories and 2014# It will recursively scan all compiled Python modules in the directories and
1884# determine if they are orphaned (i.e. their corresponding .py files are missing.) 2015# determine if they are orphaned (i.e. their corresponding .py files are missing.)
1885# If they are, then it will remove their corresponding .pyc and .pyo files. 2016# If they are, then it will remove their corresponding .pyc and .pyo files.
1886# 2017#
1887# This function should only be run in pkg_postrm(). 2018# This function can be used only in pkg_postrm() phase.
1888python_mod_cleanup() { 2019python_mod_cleanup() {
1889 _python_initialize_prefix_variables 2020 _python_initialize_prefix_variables
1890 _python_set_color_variables 2021 _python_set_color_variables
1891 2022
1892 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2023 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1893 2024
1894 # Check if phase is pkg_postrm(). 2025 # Check if phase is pkg_postrm().
1895 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" 2026 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1896 2027
1897 # Strip trailing slash from ROOT. 2028 # Strip trailing slash from ROOT.
1898 root="${EROOT%/}" 2029 root="${EROOT%/}"
1899 2030
1900 if (($#)); then 2031 if (($#)); then
1901 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2032 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1902 while (($#)); do 2033 while (($#)); do
1903 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2034 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1904 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 2035 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1905 elif [[ "$1" =~ ^/ ]]; then 2036 elif [[ "$1" =~ ^/ ]]; then
1906 SEARCH_PATH+=("${root}/${1#/}") 2037 SEARCH_PATH+=("${root}/${1#/}")
1937 if [[ -d "${path}" ]]; then 2068 if [[ -d "${path}" ]]; then
1938 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do 2069 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
1939 if [[ "${REPLY}" == *[co] ]]; then 2070 if [[ "${REPLY}" == *[co] ]]; then
1940 py_file="${REPLY%[co]}" 2071 py_file="${REPLY%[co]}"
1941 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue 2072 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1942 einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" 2073 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
1943 rm -f "${py_file}"[co] 2074 rm -f "${py_file}"[co]
1944 elif [[ "${REPLY}" == *\$py.class ]]; then 2075 elif [[ "${REPLY}" == *\$py.class ]]; then
1945 py_file="${REPLY%\$py.class}.py" 2076 py_file="${REPLY%\$py.class}.py"
1946 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue 2077 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
1947 einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" 2078 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
1948 rm -f "${py_file%.py}\$py.class" 2079 rm -f "${py_file%.py}\$py.class"
1949 fi 2080 fi
1950 done 2081 done
1951 2082
1952 # Attempt to delete directories, which may be empty. 2083 # Attempt to delete directories, which may be empty.
1953 find "${path}" -type d | sort -r | while read -r dir; do 2084 find "${path}" -type d | sort -r | while read -r dir; do
1954 rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" 2085 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
1955 done 2086 done
1956 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then 2087 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
1957 if [[ (-f "${path}c" || -f "${path}o") ]]; then 2088 if [[ (-f "${path}c" || -f "${path}o") ]]; then
1958 einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" 2089 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
1959 rm -f "${path}"[co] 2090 rm -f "${path}"[co]
1960 fi 2091 fi
1961 if [[ -f "${path%.py}\$py.class" ]]; then 2092 if [[ -f "${path%.py}\$py.class" ]]; then
1962 einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" 2093 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
1963 rm -f "${path%.py}\$py.class" 2094 rm -f "${path%.py}\$py.class"
1964 fi 2095 fi
1965 fi 2096 fi
1966 done 2097 done
1967} 2098}
1973# @FUNCTION: python_version 2104# @FUNCTION: python_version
1974# @DESCRIPTION: 2105# @DESCRIPTION:
1975# Run without arguments and it will export the version of python 2106# Run without arguments and it will export the version of python
1976# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 2107# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
1977python_version() { 2108python_version() {
1978 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2109 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
1979 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." 2110 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
1980 die "${FUNCNAME}() cannot be used in this EAPI" 2111 die "${FUNCNAME}() cannot be used in this EAPI"
2112 fi
2113
2114 _python_set_color_variables
2115
2116 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2117 echo
2118 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2119 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2120 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2121 echo
2122
2123 einfo &> /dev/null
2124 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2125 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null
2126 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2127 einfo &> /dev/null
1981 fi 2128 fi
1982 2129
1983 [[ -n "${PYVER}" ]] && return 0 2130 [[ -n "${PYVER}" ]] && return 0
1984 local tmpstr 2131 local tmpstr
1985 python="${python:-${EPREFIX}/usr/bin/python}" 2132 python="${python:-${EPREFIX}/usr/bin/python}"
2004# Example: 2151# Example:
2005# if python_mod_exists gtk; then 2152# if python_mod_exists gtk; then
2006# echo "gtk support enabled" 2153# echo "gtk support enabled"
2007# fi 2154# fi
2008python_mod_exists() { 2155python_mod_exists() {
2009 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2156 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2010 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2157 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2011 die "${FUNCNAME}() cannot be used in this EAPI" 2158 die "${FUNCNAME}() cannot be used in this EAPI"
2012 fi 2159 fi
2160
2161 echo
2162 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2163 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2165 echo
2166
2167 einfo &> /dev/null
2168 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2169 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2170 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2171 einfo &> /dev/null
2013 2172
2014 if [[ "$#" -ne 1 ]]; then 2173 if [[ "$#" -ne 1 ]]; then
2015 die "${FUNCNAME}() requires 1 argument" 2174 die "${FUNCNAME}() requires 1 argument"
2016 fi 2175 fi
2017 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2176 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2020# @FUNCTION: python_tkinter_exists 2179# @FUNCTION: python_tkinter_exists
2021# @DESCRIPTION: 2180# @DESCRIPTION:
2022# Run without arguments, checks if Python was compiled with Tkinter 2181# Run without arguments, checks if Python was compiled with Tkinter
2023# support. If not, prints an error message and dies. 2182# support. If not, prints an error message and dies.
2024python_tkinter_exists() { 2183python_tkinter_exists() {
2025 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2184 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2026 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2185 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2027 die "${FUNCNAME}() cannot be used in this EAPI" 2186 die "${FUNCNAME}() cannot be used in this EAPI"
2187 fi
2188
2189 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2190 echo
2191 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2192 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2194 echo
2195
2196 einfo &> /dev/null
2197 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2198 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2199 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2200 einfo &> /dev/null
2028 fi 2201 fi
2029 2202
2030 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2203 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2031if version_info[0] == 3: 2204if version_info[0] == 3:
2032 import tkinter 2205 import tkinter
2041 2214
2042# @FUNCTION: python_mod_compile 2215# @FUNCTION: python_mod_compile
2043# @USAGE: <file> [more files ...] 2216# @USAGE: <file> [more files ...]
2044# @DESCRIPTION: 2217# @DESCRIPTION:
2045# Given filenames, it will pre-compile the module's .pyc and .pyo. 2218# Given filenames, it will pre-compile the module's .pyc and .pyo.
2046# This function should only be run in pkg_postinst() 2219# This function can be used only in pkg_postinst() phase.
2047# 2220#
2048# Example: 2221# Example:
2049# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py 2222# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2050# 2223#
2051python_mod_compile() { 2224python_mod_compile() {
2052 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2225 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2053 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2226 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2054 die "${FUNCNAME}() cannot be used in this EAPI" 2227 die "${FUNCNAME}() cannot be used in this EAPI"
2055 fi 2228 fi
2056 2229
2057 _python_initialize_prefix_variables 2230 _python_initialize_prefix_variables
2058 2231
2059 local f myroot myfiles=() 2232 local f myroot myfiles=()
2060 2233
2061 # Check if phase is pkg_postinst() 2234 # Check if phase is pkg_postinst()
2062 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 2235 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2063 2236
2064 # strip trailing slash 2237 # strip trailing slash
2065 myroot="${EROOT%/}" 2238 myroot="${EROOT%/}"
2066 2239
2067 # respect ROOT 2240 # respect ROOT

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

  ViewVC Help
Powered by ViewVC 1.1.20