/[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.101
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.101 2010/07/17 23:02:14 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
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" 159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 160elif [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 161 _parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then 162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then 163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON." 164 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
165 die "NEED_PYTHON cannot be used in this EAPI" 165 die "NEED_PYTHON variable cannot be used in this EAPI"
166 fi 166 fi
167
168 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
169 _RED=$'\e[1;31m'
170 _NORMAL=$'\e[0m'
171 else
172 _RED=
173 _NORMAL=
174 fi
175
176 echo
177 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01.${_NORMAL}"
178 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_DEPEND variable instead of NEED_PYTHON variable.${_NORMAL}"
179 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
180 echo
181
182 unset _BOLD _NORMAL
183
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}") 184 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}" 185 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}" 186 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 187else
171 _PYTHON_ATOMS=("dev-lang/python") 188 _PYTHON_ATOMS=("dev-lang/python")
241 else 258 else
242 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" 259 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
243 fi 260 fi
244} 261}
245 262
263_python_abi-specific_local_scope() {
264 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
265}
266
246_python_initialize_prefix_variables() { 267_python_initialize_prefix_variables() {
247 if has "${EAPI:-0}" 0 1 2; then 268 if has "${EAPI:-0}" 0 1 2; then
248 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then 269 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
249 EROOT="${ROOT%/}${EPREFIX}/" 270 EROOT="${ROOT%/}${EPREFIX}/"
250 fi 271 fi
252 ED="${D%/}${EPREFIX}/" 273 ED="${D%/}${EPREFIX}/"
253 fi 274 fi
254 fi 275 fi
255} 276}
256 277
257unset PYTHON_SANITY_CHECKS 278unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
258 279
259_python_initial_sanity_checks() { 280_python_initial_sanity_checks() {
260 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 281 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. 282 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
262 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then 283 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
263 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." 284 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
264 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 285 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
265 die "'${EPREFIX}/usr/bin/python' is not valid symlink" 286 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
271 fi 292 fi
272 fi 293 fi
273} 294}
274 295
275_python_final_sanity_checks() { 296_python_final_sanity_checks() {
276 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 297 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}" 298 local PYTHON_ABI="${PYTHON_ABI}"
278 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do 299 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
279 # Ensure that appropriate version of Python is installed. 300 # Ensure that appropriate version of Python is installed.
280 if ! has_version "$(python_get_implementational_package)"; then 301 if ! has_version "$(python_get_implementational_package)"; then
281 die "$(python_get_implementational_package) is not installed" 302 die "$(python_get_implementational_package) is not installed"
291 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" 312 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
292 die "'python' does not respect EPYTHON variable" 313 die "'python' does not respect EPYTHON variable"
293 fi 314 fi
294 done 315 done
295 fi 316 fi
296 PYTHON_SANITY_CHECKS="1" 317 PYTHON_SANITY_CHECKS_EXECUTED="1"
297} 318}
298 319
299_python_set_color_variables() { 320_python_set_color_variables() {
300 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 321 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
301 _BOLD=$'\e[1m' 322 _BOLD=$'\e[1m'
313 _NORMAL= 334 _NORMAL=
314 fi 335 fi
315} 336}
316 337
317unset PYTHON_PKG_SETUP_EXECUTED 338unset PYTHON_PKG_SETUP_EXECUTED
339
340_python_check_python_pkg_setup_execution() {
341 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
342
343 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
344 die "python_pkg_setup() not called"
345 fi
346}
318 347
319# @FUNCTION: python_pkg_setup 348# @FUNCTION: python_pkg_setup
320# @DESCRIPTION: 349# @DESCRIPTION:
321# Perform sanity checks and initialize environment. 350# Perform sanity checks and initialize environment.
322# 351#
326# This function can be used only in pkg_setup() phase. 355# This function can be used only in pkg_setup() phase.
327python_pkg_setup() { 356python_pkg_setup() {
328 # Check if phase is pkg_setup(). 357 # Check if phase is pkg_setup().
329 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 358 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
330 359
360 if [[ "$#" -ne 0 ]]; then
361 die "${FUNCNAME}() does not accept arguments"
362 fi
363
331 if _python_package_supporting_installation_for_multiple_python_abis; then 364 if _python_package_supporting_installation_for_multiple_python_abis; then
332 _python_calculate_PYTHON_ABIS 365 _python_calculate_PYTHON_ABIS
333 export EPYTHON="$(PYTHON -f)" 366 export EPYTHON="$(PYTHON -f)"
334 else 367 else
335 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 368 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}" 399 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
367 fi 400 fi
368 } 401 }
369 402
370 if _python_package_supporting_installation_for_multiple_python_abis; then 403 if _python_package_supporting_installation_for_multiple_python_abis; then
371 python_execute_function -q python_pkg_setup_check_USE_flags 404 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
372 else 405 else
373 python_pkg_setup_check_USE_flags 406 python_pkg_setup_check_USE_flags
374 fi 407 fi
375 408
376 unset -f python_pkg_setup_check_USE_flags 409 unset -f python_pkg_setup_check_USE_flags
386# @FUNCTION: python_convert_shebangs 419# @FUNCTION: python_convert_shebangs
387# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 420# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
388# @DESCRIPTION: 421# @DESCRIPTION:
389# Convert shebangs in specified files. Directories can be specified only with --recursive option. 422# Convert shebangs in specified files. Directories can be specified only with --recursive option.
390python_convert_shebangs() { 423python_convert_shebangs() {
424 _python_check_python_pkg_setup_execution
425
391 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 426 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
392 427
393 while (($#)); do 428 while (($#)); do
394 case "$1" in 429 case "$1" in
395 -r|--recursive) 430 -r|--recursive)
464# @FUNCTION: python_clean_installation_image 499# @FUNCTION: python_clean_installation_image
465# @USAGE: [-q|--quiet] 500# @USAGE: [-q|--quiet]
466# @DESCRIPTION: 501# @DESCRIPTION:
467# Delete needless files in installation image. 502# Delete needless files in installation image.
468python_clean_installation_image() { 503python_clean_installation_image() {
504 _python_check_python_pkg_setup_execution
469 _python_initialize_prefix_variables 505 _python_initialize_prefix_variables
470 506
471 local file files=() quiet="0" 507 local file files=() quiet="0"
472 508
473 # Check if phase is src_install(). 509 # Check if phase is src_install().
536# @DESCRIPTION: 572# @DESCRIPTION:
537# Set this to export phase functions for the following ebuild phases: 573# Set this to export phase functions for the following ebuild phases:
538# src_prepare, src_configure, src_compile, src_test, src_install. 574# src_prepare, src_configure, src_compile, src_test, src_install.
539if ! has "${EAPI:-0}" 0 1; then 575if ! has "${EAPI:-0}" 0 1; then
540 python_src_prepare() { 576 python_src_prepare() {
577 _python_check_python_pkg_setup_execution
578
541 if ! _python_package_supporting_installation_for_multiple_python_abis; then 579 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" 580 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
543 fi 581 fi
544 582
583 if [[ "$#" -ne 0 ]]; then
584 die "${FUNCNAME}() does not accept arguments"
585 fi
586
545 python_copy_sources 587 python_copy_sources
546 } 588 }
547 589
548 for python_default_function in src_configure src_compile src_test src_install; do 590 for python_default_function in src_configure src_compile src_test src_install; do
549 eval "python_${python_default_function}() { 591 eval "python_${python_default_function}() {
592 _python_check_python_pkg_setup_execution
593
550 if ! _python_package_supporting_installation_for_multiple_python_abis; then 594 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\" 595 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
552 fi 596 fi
553 597
554 python_execute_function -d -s -- \"\$@\" 598 python_execute_function -d -s -- \"\$@\"
689 fi 733 fi
690 734
691 _python_final_sanity_checks 735 _python_final_sanity_checks
692} 736}
693 737
738_python_prepare_flags() {
739 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
740
741 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
742 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
743 for prefix in PYTHON_USER_ PYTHON_; do
744 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
745 eval "array=(\"\${${prefix}${variable}[@]}\")"
746 for element in "${array[@]}"; do
747 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
748 pattern="${element%% *}"
749 element="${element#* }"
750 operator="${element%% *}"
751 flags="${element#* }"
752 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
753 if [[ "${operator}" == "+" ]]; then
754 eval "export ${variable}+=\"\${variable:+ }${flags}\""
755 elif [[ "${operator}" == "-" ]]; then
756 flags="${flags// /$'\n'}"
757 old_value="${!variable// /$'\n'}"
758 new_value=""
759 while read old_flag; do
760 while read deleted_flag; do
761 if [[ "${old_flag}" == ${deleted_flag} ]]; then
762 continue 2
763 fi
764 done <<< "${flags}"
765 new_value+="${new_value:+ }${old_flag}"
766 done <<< "${old_value}"
767 eval "export ${variable}=\"\${new_value}\""
768 fi
769 fi
770 else
771 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
772 fi
773 done
774 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
775 die "${prefix}${variable} should be indexed array"
776 fi
777 done
778 done
779}
780
781_python_restore_flags() {
782 local variable
783
784 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
785 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
786 unset _PYTHON_SAVED_${variable}
787 done
788}
789
694# @FUNCTION: python_execute_function 790# @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] 791# @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: 792# @DESCRIPTION:
697# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 793# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
698# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 794# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
699python_execute_function() { 795python_execute_function() {
796 _python_check_python_pkg_setup_execution
797
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 798 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" 799 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 800 fi
703 801
704 _python_set_color_variables 802 _python_set_color_variables
705 803
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= 804 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 805
708 while (($#)); do 806 while (($#)); do
709 case "$1" in 807 case "$1" in
710 --action-message) 808 --action-message)
711 action_message_template="$2" 809 action_message_template="$2"
798 fi 896 fi
799 function="python_default_function" 897 function="python_default_function"
800 fi 898 fi
801 899
802 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 900 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
803 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 901 if _python_abi-specific_local_scope; then
804 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
805 die "${FUNCNAME}(): Invalid call stack" 902 die "${FUNCNAME}(): Invalid call stack"
806 fi 903 fi
807 done
808 904
809 if [[ "${quiet}" == "0" ]]; then 905 if [[ "${quiet}" == "0" ]]; then
810 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 906 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
811 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 907 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
812 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 908 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
825 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 921 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
826 else 922 else
827 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 923 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
828 fi 924 fi
829 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 925 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
926 _python_prepare_flags
927
830 if [[ "${quiet}" == "0" ]]; then 928 if [[ "${quiet}" == "0" ]]; then
831 if [[ -n "${action_message_template}" ]]; then 929 if [[ -n "${action_message_template}" ]]; then
832 action_message="$(eval echo -n "${action_message_template}")" 930 action_message="$(eval echo -n "${action_message_template}")"
833 else 931 else
834 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 932 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
855 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 953 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
856 else 954 else
857 EPYTHON="$(PYTHON)" "${function}" "$@" 955 EPYTHON="$(PYTHON)" "${function}" "$@"
858 fi 956 fi
859 957
860 if [[ "$?" != "0" ]]; then 958 return_code="$?"
959
960 _python_restore_flags
961
962 if [[ "${return_code}" -ne 0 ]]; then
861 if [[ -n "${failure_message_template}" ]]; then 963 if [[ -n "${failure_message_template}" ]]; then
862 failure_message="$(eval echo -n "${failure_message_template}")" 964 failure_message="$(eval echo -n "${failure_message_template}")"
863 else 965 else
864 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 966 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
865 fi 967 fi
922# @FUNCTION: python_copy_sources 1024# @FUNCTION: python_copy_sources
923# @USAGE: <directory="${S}"> [directory] 1025# @USAGE: <directory="${S}"> [directory]
924# @DESCRIPTION: 1026# @DESCRIPTION:
925# Copy unpacked sources of current package to separate build directory for each Python ABI. 1027# Copy unpacked sources of current package to separate build directory for each Python ABI.
926python_copy_sources() { 1028python_copy_sources() {
1029 _python_check_python_pkg_setup_execution
1030
927 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1031 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" 1032 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
929 fi 1033 fi
930 1034
931 local dir dirs=() PYTHON_ABI 1035 local dir dirs=() PYTHON_ABI
952# @DESCRIPTION: 1056# @DESCRIPTION:
953# Generate wrapper scripts. Existing files are overwritten only with --force option. 1057# Generate wrapper scripts. Existing files are overwritten only with --force option.
954# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1058# If --respect-EPYTHON option is specified, then generated wrapper scripts will
955# respect EPYTHON variable at run time. 1059# respect EPYTHON variable at run time.
956python_generate_wrapper_scripts() { 1060python_generate_wrapper_scripts() {
1061 _python_check_python_pkg_setup_execution
1062
957 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1063 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" 1064 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
959 fi 1065 fi
960 1066
961 _python_initialize_prefix_variables 1067 _python_initialize_prefix_variables
1155 1261
1156# ================================================================================================ 1262# ================================================================================================
1157# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1263# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1158# ================================================================================================ 1264# ================================================================================================
1159 1265
1266unset EPYTHON PYTHON_ABI
1267
1160# @FUNCTION: python_set_active_version 1268# @FUNCTION: python_set_active_version
1161# @USAGE: <CPython_ABI|2|3> 1269# @USAGE: <CPython_ABI|2|3>
1162# @DESCRIPTION: 1270# @DESCRIPTION:
1163# Set specified version of CPython as active version of Python. 1271# Set specified version of CPython as active version of Python.
1272#
1273# This function can be used only in pkg_setup() phase.
1164python_set_active_version() { 1274python_set_active_version() {
1275 # Check if phase is pkg_setup().
1276 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1277
1165 if _python_package_supporting_installation_for_multiple_python_abis; then 1278 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" 1279 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1167 fi 1280 fi
1168 1281
1169 if [[ "$#" -ne 1 ]]; then 1282 if [[ "$#" -ne 1 ]]; then
1170 die "${FUNCNAME}() requires 1 argument" 1283 die "${FUNCNAME}() requires 1 argument"
1171 fi 1284 fi
1172 1285
1173 _python_initial_sanity_checks 1286 _python_initial_sanity_checks
1174 1287
1288 if [[ -z "${PYTHON_ABI}" ]]; then
1175 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1289 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1176 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1290 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
1177 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1291 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
1178 fi 1292 fi
1179 export EPYTHON="$(PYTHON "$1")" 1293 export EPYTHON="$(PYTHON "$1")"
1180 elif [[ "$1" == "2" ]]; then 1294 elif [[ "$1" == "2" ]]; then
1181 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1295 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1182 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1296 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1183 fi 1297 fi
1184 export EPYTHON="$(PYTHON -2)" 1298 export EPYTHON="$(PYTHON -2)"
1185 elif [[ "$1" == "3" ]]; then 1299 elif [[ "$1" == "3" ]]; then
1186 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1300 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1187 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1301 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1188 fi 1302 fi
1189 export EPYTHON="$(PYTHON -3)" 1303 export EPYTHON="$(PYTHON -3)"
1190 else 1304 else
1191 die "${FUNCNAME}(): Unrecognized argument '$1'" 1305 die "${FUNCNAME}(): Unrecognized argument '$1'"
1192 fi 1306 fi
1193 1307
1194 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1308 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1195 # so it does not need to be exported to subprocesses. 1309 # so it does not need to be exported to subprocesses.
1196 PYTHON_ABI="${EPYTHON#python}" 1310 PYTHON_ABI="${EPYTHON#python}"
1197 PYTHON_ABI="${PYTHON_ABI%%-*}" 1311 PYTHON_ABI="${PYTHON_ABI%%-*}"
1312 fi
1198 1313
1199 _python_final_sanity_checks 1314 _python_final_sanity_checks
1200 1315
1201 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1316 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1202 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1317 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1204 1319
1205# @FUNCTION: python_need_rebuild 1320# @FUNCTION: python_need_rebuild
1206# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1321# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1207# switching of active version of Python. 1322# switching of active version of Python.
1208python_need_rebuild() { 1323python_need_rebuild() {
1324 _python_check_python_pkg_setup_execution
1325
1209 if _python_package_supporting_installation_for_multiple_python_abis; then 1326 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" 1327 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1328 fi
1329
1330 if [[ "$#" -ne 0 ]]; then
1331 die "${FUNCNAME}() does not accept arguments"
1211 fi 1332 fi
1212 1333
1213 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1334 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1214} 1335}
1215 1336
1249# If --ABI option is specified, then only specified Python ABI is printed instead of 1370# If --ABI option is specified, then only specified Python ABI is printed instead of
1250# filename of Python interpreter. 1371# filename of Python interpreter.
1251# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1372# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1252# --ABI and --absolute-path options cannot be specified simultaneously. 1373# --ABI and --absolute-path options cannot be specified simultaneously.
1253PYTHON() { 1374PYTHON() {
1375 _python_check_python_pkg_setup_execution
1376
1254 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1377 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1255 1378
1256 while (($#)); do 1379 while (($#)); do
1257 case "$1" in 1380 case "$1" in
1258 -2) 1381 -2)
1283 esac 1406 esac
1284 shift 1407 shift
1285 done 1408 done
1286 1409
1287 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1410 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1288 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1411 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1289 fi 1412 fi
1290 1413
1291 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1414 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1292 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1415 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1293 fi 1416 fi
1311 if [[ -z "${PYTHON_ABI}" ]]; then 1434 if [[ -z "${PYTHON_ABI}" ]]; then
1312 die "${FUNCNAME}(): Active version of Python 3 not set" 1435 die "${FUNCNAME}(): Active version of Python 3 not set"
1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1436 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1437 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1315 fi 1438 fi
1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1439 elif _python_package_supporting_installation_for_multiple_python_abis; then
1440 if ! _python_abi-specific_local_scope; then
1441 die "${FUNCNAME}() should be used in ABI-specific local scope"
1442 fi
1443 else
1317 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1444 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1318 if [[ -z "${PYTHON_ABI}" ]]; then 1445 if [[ -z "${PYTHON_ABI}" ]]; then
1319 die "${FUNCNAME}(): Failure of extraction of locally active version of Python" 1446 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1320 fi 1447 fi
1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1322 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1323 fi 1448 fi
1324 elif [[ "$#" -eq 1 ]]; then 1449 elif [[ "$#" -eq 1 ]]; then
1325 if [[ "${final_ABI}" == "1" ]]; then 1450 if [[ "${final_ABI}" == "1" ]]; then
1326 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1451 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1327 fi 1452 fi
1362# @USAGE: [-f|--final-ABI] 1487# @USAGE: [-f|--final-ABI]
1363# @DESCRIPTION: 1488# @DESCRIPTION:
1364# Print name of Python implementation. 1489# Print name of Python implementation.
1365# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1490# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1366python_get_implementation() { 1491python_get_implementation() {
1492 _python_check_python_pkg_setup_execution
1493
1367 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1494 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1368 1495
1369 while (($#)); do 1496 while (($#)); do
1370 case "$1" in 1497 case "$1" in
1371 -f|--final-ABI) 1498 -f|--final-ABI)
1384 if [[ "${final_ABI}" == "1" ]]; then 1511 if [[ "${final_ABI}" == "1" ]]; then
1385 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1512 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" 1513 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1387 fi 1514 fi
1388 PYTHON_ABI="$(PYTHON -f --ABI)" 1515 PYTHON_ABI="$(PYTHON -f --ABI)"
1389 elif [[ -z "${PYTHON_ABI}" ]]; then 1516 else
1517 if _python_package_supporting_installation_for_multiple_python_abis; then
1518 if ! _python_abi-specific_local_scope; then
1519 die "${FUNCNAME}() should be used in ABI-specific local scope"
1520 fi
1521 else
1390 PYTHON_ABI="$(PYTHON --ABI)" 1522 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1523 fi
1391 fi 1524 fi
1392 1525
1393 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1526 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1394} 1527}
1395 1528
1397# @USAGE: [-f|--final-ABI] 1530# @USAGE: [-f|--final-ABI]
1398# @DESCRIPTION: 1531# @DESCRIPTION:
1399# Print category, name and slot of package providing Python implementation. 1532# 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. 1533# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1401python_get_implementational_package() { 1534python_get_implementational_package() {
1535 _python_check_python_pkg_setup_execution
1536
1402 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1537 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1403 1538
1404 while (($#)); do 1539 while (($#)); do
1405 case "$1" in 1540 case "$1" in
1406 -f|--final-ABI) 1541 -f|--final-ABI)
1419 if [[ "${final_ABI}" == "1" ]]; then 1554 if [[ "${final_ABI}" == "1" ]]; then
1420 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1555 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" 1556 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1422 fi 1557 fi
1423 PYTHON_ABI="$(PYTHON -f --ABI)" 1558 PYTHON_ABI="$(PYTHON -f --ABI)"
1424 elif [[ -z "${PYTHON_ABI}" ]]; then 1559 else
1560 if _python_package_supporting_installation_for_multiple_python_abis; then
1561 if ! _python_abi-specific_local_scope; then
1562 die "${FUNCNAME}() should be used in ABI-specific local scope"
1563 fi
1564 else
1425 PYTHON_ABI="$(PYTHON --ABI)" 1565 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1566 fi
1426 fi 1567 fi
1427 1568
1428 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1569 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1429 echo "dev-lang/python:${PYTHON_ABI}" 1570 echo "dev-lang/python:${PYTHON_ABI}"
1430 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1571 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1431 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1572 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1432 fi 1573 fi
1433} 1574}
1434 1575
1435# @FUNCTION: python_get_includedir 1576# @FUNCTION: python_get_includedir
1436# @USAGE: [-f|--final-ABI] 1577# @USAGE: [-b|--base-path] [-f|--final-ABI]
1437# @DESCRIPTION: 1578# @DESCRIPTION:
1438# Print path to Python include directory. 1579# Print path to Python include directory.
1580# 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. 1581# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1440python_get_includedir() { 1582python_get_includedir() {
1583 _python_check_python_pkg_setup_execution
1584
1441 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1585 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1442 1586
1443 while (($#)); do 1587 while (($#)); do
1444 case "$1" in 1588 case "$1" in
1589 -b|--base-path)
1590 base_path="1"
1591 ;;
1445 -f|--final-ABI) 1592 -f|--final-ABI)
1446 final_ABI="1" 1593 final_ABI="1"
1447 ;; 1594 ;;
1448 -*) 1595 -*)
1449 die "${FUNCNAME}(): Unrecognized option '$1'" 1596 die "${FUNCNAME}(): Unrecognized option '$1'"
1453 ;; 1600 ;;
1454 esac 1601 esac
1455 shift 1602 shift
1456 done 1603 done
1457 1604
1605 if [[ "${base_path}" == "0" ]]; then
1606 prefix="/"
1607 fi
1608
1458 if [[ "${final_ABI}" == "1" ]]; then 1609 if [[ "${final_ABI}" == "1" ]]; then
1459 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1610 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" 1611 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1461 fi 1612 fi
1462 PYTHON_ABI="$(PYTHON -f --ABI)" 1613 PYTHON_ABI="$(PYTHON -f --ABI)"
1463 elif [[ -z "${PYTHON_ABI}" ]]; then 1614 else
1615 if _python_package_supporting_installation_for_multiple_python_abis; then
1616 if ! _python_abi-specific_local_scope; then
1617 die "${FUNCNAME}() should be used in ABI-specific local scope"
1618 fi
1619 else
1464 PYTHON_ABI="$(PYTHON --ABI)" 1620 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1621 fi
1465 fi 1622 fi
1466 1623
1467 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1624 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1468 echo "/usr/include/python${PYTHON_ABI}" 1625 echo "${prefix}usr/include/python${PYTHON_ABI}"
1469 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1626 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1470 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1627 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1471 fi 1628 fi
1472} 1629}
1473 1630
1474# @FUNCTION: python_get_libdir 1631# @FUNCTION: python_get_libdir
1475# @USAGE: [-f|--final-ABI] 1632# @USAGE: [-b|--base-path] [-f|--final-ABI]
1476# @DESCRIPTION: 1633# @DESCRIPTION:
1477# Print path to Python library directory. 1634# Print path to Python library directory.
1635# 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. 1636# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1479python_get_libdir() { 1637python_get_libdir() {
1638 _python_check_python_pkg_setup_execution
1639
1480 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1640 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1481 1641
1482 while (($#)); do 1642 while (($#)); do
1483 case "$1" in 1643 case "$1" in
1644 -b|--base-path)
1645 base_path="1"
1646 ;;
1484 -f|--final-ABI) 1647 -f|--final-ABI)
1485 final_ABI="1" 1648 final_ABI="1"
1486 ;; 1649 ;;
1487 -*) 1650 -*)
1488 die "${FUNCNAME}(): Unrecognized option '$1'" 1651 die "${FUNCNAME}(): Unrecognized option '$1'"
1492 ;; 1655 ;;
1493 esac 1656 esac
1494 shift 1657 shift
1495 done 1658 done
1496 1659
1660 if [[ "${base_path}" == "0" ]]; then
1661 prefix="/"
1662 fi
1663
1497 if [[ "${final_ABI}" == "1" ]]; then 1664 if [[ "${final_ABI}" == "1" ]]; then
1498 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1665 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" 1666 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1500 fi 1667 fi
1501 PYTHON_ABI="$(PYTHON -f --ABI)" 1668 PYTHON_ABI="$(PYTHON -f --ABI)"
1502 elif [[ -z "${PYTHON_ABI}" ]]; then 1669 else
1670 if _python_package_supporting_installation_for_multiple_python_abis; then
1671 if ! _python_abi-specific_local_scope; then
1672 die "${FUNCNAME}() should be used in ABI-specific local scope"
1673 fi
1674 else
1503 PYTHON_ABI="$(PYTHON --ABI)" 1675 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1676 fi
1504 fi 1677 fi
1505 1678
1506 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1679 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1507 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1680 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1508 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1681 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1509 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1682 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1510 fi 1683 fi
1511} 1684}
1512 1685
1513# @FUNCTION: python_get_sitedir 1686# @FUNCTION: python_get_sitedir
1514# @USAGE: [-f|--final-ABI] 1687# @USAGE: [-b|--base-path] [-f|--final-ABI]
1515# @DESCRIPTION: 1688# @DESCRIPTION:
1516# Print path to Python site-packages directory. 1689# Print path to Python site-packages directory.
1690# 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. 1691# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1518python_get_sitedir() { 1692python_get_sitedir() {
1519 local options=() 1693 _python_check_python_pkg_setup_execution
1694
1695 local final_ABI="0" options=()
1520 1696
1521 while (($#)); do 1697 while (($#)); do
1522 case "$1" in 1698 case "$1" in
1699 -b|--base-path)
1700 options+=("$1")
1701 ;;
1523 -f|--final-ABI) 1702 -f|--final-ABI)
1524 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1703 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") 1704 options+=("$1")
1528 ;; 1705 ;;
1529 -*) 1706 -*)
1530 die "${FUNCNAME}(): Unrecognized option '$1'" 1707 die "${FUNCNAME}(): Unrecognized option '$1'"
1531 ;; 1708 ;;
1534 ;; 1711 ;;
1535 esac 1712 esac
1536 shift 1713 shift
1537 done 1714 done
1538 1715
1716 if [[ "${final_ABI}" == "1" ]]; then
1717 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1718 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1719 fi
1720 else
1721 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1722 die "${FUNCNAME}() should be used in ABI-specific local scope"
1723 fi
1724 fi
1725
1539 echo "$(python_get_libdir "${options[@]}")/site-packages" 1726 echo "$(python_get_libdir "${options[@]}")/site-packages"
1540} 1727}
1541 1728
1542# @FUNCTION: python_get_library 1729# @FUNCTION: python_get_library
1543# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1730# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1544# @DESCRIPTION: 1731# @DESCRIPTION:
1545# Print path to Python library. 1732# Print path to Python library.
1733# 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. 1734# 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. 1735# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1548python_get_library() { 1736python_get_library() {
1737 _python_check_python_pkg_setup_execution
1738
1549 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1739 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1550 1740
1551 while (($#)); do 1741 while (($#)); do
1552 case "$1" in 1742 case "$1" in
1743 -b|--base-path)
1744 base_path="1"
1745 ;;
1553 -f|--final-ABI) 1746 -f|--final-ABI)
1554 final_ABI="1" 1747 final_ABI="1"
1555 ;; 1748 ;;
1556 -l|--linker-option) 1749 -l|--linker-option)
1557 linker_option="1" 1750 linker_option="1"
1564 ;; 1757 ;;
1565 esac 1758 esac
1566 shift 1759 shift
1567 done 1760 done
1568 1761
1762 if [[ "${base_path}" == "0" ]]; then
1763 prefix="/"
1764 fi
1765
1766 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1767 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1768 fi
1769
1569 if [[ "${final_ABI}" == "1" ]]; then 1770 if [[ "${final_ABI}" == "1" ]]; then
1570 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1771 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" 1772 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1572 fi 1773 fi
1573 PYTHON_ABI="$(PYTHON -f --ABI)" 1774 PYTHON_ABI="$(PYTHON -f --ABI)"
1574 elif [[ -z "${PYTHON_ABI}" ]]; then 1775 else
1776 if _python_package_supporting_installation_for_multiple_python_abis; then
1777 if ! _python_abi-specific_local_scope; then
1778 die "${FUNCNAME}() should be used in ABI-specific local scope"
1779 fi
1780 else
1575 PYTHON_ABI="$(PYTHON --ABI)" 1781 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1782 fi
1576 fi 1783 fi
1577 1784
1578 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1785 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1579 if [[ "${linker_option}" == "1" ]]; then 1786 if [[ "${linker_option}" == "1" ]]; then
1580 echo "-lpython${PYTHON_ABI}" 1787 echo "-lpython${PYTHON_ABI}"
1581 else 1788 else
1582 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1789 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1583 fi 1790 fi
1584 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1791 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1585 die "${FUNCNAME}(): Jython does not have shared library" 1792 die "${FUNCNAME}(): Jython does not have shared library"
1586 fi 1793 fi
1587} 1794}
1592# Print Python version. 1799# Print Python version.
1593# --full, --major, --minor and --micro options cannot be specified simultaneously. 1800# --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. 1801# 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. 1802# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1596python_get_version() { 1803python_get_version() {
1804 _python_check_python_pkg_setup_execution
1805
1597 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1806 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1598 1807
1599 while (($#)); do 1808 while (($#)); do
1600 case "$1" in 1809 case "$1" in
1601 -f|--final-ABI) 1810 -f|--final-ABI)
1651 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1860 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" 1861 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1653 fi 1862 fi
1654 "$(PYTHON -f)" -c "${python_command}" 1863 "$(PYTHON -f)" -c "${python_command}"
1655 else 1864 else
1865 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1866 die "${FUNCNAME}() should be used in ABI-specific local scope"
1867 fi
1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1868 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1657 fi 1869 fi
1658} 1870}
1659 1871
1660# ================================================================================================ 1872# ================================================================================================
1682# @DESCRIPTION: 1894# @DESCRIPTION:
1683# Execute nosetests for all enabled Python ABIs. 1895# Execute nosetests for all enabled Python ABIs.
1684# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1896# 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. 1897# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1686python_execute_nosetests() { 1898python_execute_nosetests() {
1899 _python_check_python_pkg_setup_execution
1687 _python_set_color_variables 1900 _python_set_color_variables
1688 1901
1689 local PYTHONPATH_template= separate_build_dirs= 1902 local PYTHONPATH_template= separate_build_dirs=
1690 1903
1691 while (($#)); do 1904 while (($#)); do
1710 esac 1923 esac
1711 shift 1924 shift
1712 done 1925 done
1713 1926
1714 python_test_function() { 1927 python_test_function() {
1715 local evaluated_PYTHONPATH= 1928 local evaluated_PYTHONPATH
1716 1929
1717 if [[ -n "${PYTHONPATH_template}" ]]; then
1718 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1930 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1719 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1720 unset evaluated_PYTHONPATH
1721 fi
1722 fi
1723 1931
1724 _python_test_hook pre 1932 _python_test_hook pre
1725 1933
1726 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1934 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1727 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1935 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1750# @DESCRIPTION: 1958# @DESCRIPTION:
1751# Execute py.test for all enabled Python ABIs. 1959# Execute py.test for all enabled Python ABIs.
1752# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1960# 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. 1961# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1754python_execute_py.test() { 1962python_execute_py.test() {
1963 _python_check_python_pkg_setup_execution
1755 _python_set_color_variables 1964 _python_set_color_variables
1756 1965
1757 local PYTHONPATH_template= separate_build_dirs= 1966 local PYTHONPATH_template= separate_build_dirs=
1758 1967
1759 while (($#)); do 1968 while (($#)); do
1778 esac 1987 esac
1779 shift 1988 shift
1780 done 1989 done
1781 1990
1782 python_test_function() { 1991 python_test_function() {
1783 local evaluated_PYTHONPATH= 1992 local evaluated_PYTHONPATH
1784 1993
1785 if [[ -n "${PYTHONPATH_template}" ]]; then
1786 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1994 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1787 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1788 unset evaluated_PYTHONPATH
1789 fi
1790 fi
1791 1995
1792 _python_test_hook pre 1996 _python_test_hook pre
1793 1997
1794 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1998 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1795 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1999 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1818# @DESCRIPTION: 2022# @DESCRIPTION:
1819# Execute trial for all enabled Python ABIs. 2023# Execute trial for all enabled Python ABIs.
1820# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2024# 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. 2025# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1822python_execute_trial() { 2026python_execute_trial() {
2027 _python_check_python_pkg_setup_execution
1823 _python_set_color_variables 2028 _python_set_color_variables
1824 2029
1825 local PYTHONPATH_template= separate_build_dirs= 2030 local PYTHONPATH_template= separate_build_dirs=
1826 2031
1827 while (($#)); do 2032 while (($#)); do
1846 esac 2051 esac
1847 shift 2052 shift
1848 done 2053 done
1849 2054
1850 python_test_function() { 2055 python_test_function() {
1851 local evaluated_PYTHONPATH= 2056 local evaluated_PYTHONPATH
1852 2057
1853 if [[ -n "${PYTHONPATH_template}" ]]; then
1854 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2058 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1855 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1856 unset evaluated_PYTHONPATH
1857 fi
1858 fi
1859 2059
1860 _python_test_hook pre 2060 _python_test_hook pre
1861 2061
1862 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2062 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1863 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2063 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1888# @FUNCTION: python_enable_pyc 2088# @FUNCTION: python_enable_pyc
1889# @DESCRIPTION: 2089# @DESCRIPTION:
1890# Tell Python to automatically recompile modules to .pyc/.pyo if the 2090# Tell Python to automatically recompile modules to .pyc/.pyo if the
1891# timestamps/version stamps have changed. 2091# timestamps/version stamps have changed.
1892python_enable_pyc() { 2092python_enable_pyc() {
2093 _python_check_python_pkg_setup_execution
2094
2095 if [[ "$#" -ne 0 ]]; then
2096 die "${FUNCNAME}() does not accept arguments"
2097 fi
2098
1893 unset PYTHONDONTWRITEBYTECODE 2099 unset PYTHONDONTWRITEBYTECODE
1894} 2100}
1895 2101
1896# @FUNCTION: python_disable_pyc 2102# @FUNCTION: python_disable_pyc
1897# @DESCRIPTION: 2103# @DESCRIPTION:
1898# Tell Python not to automatically recompile modules to .pyc/.pyo 2104# Tell Python not to automatically recompile modules to .pyc/.pyo
1899# even if the timestamps/version stamps do not match. This is done 2105# even if the timestamps/version stamps do not match. This is done
1900# to protect sandbox. 2106# to protect sandbox.
1901python_disable_pyc() { 2107python_disable_pyc() {
2108 _python_check_python_pkg_setup_execution
2109
2110 if [[ "$#" -ne 0 ]]; then
2111 die "${FUNCNAME}() does not accept arguments"
2112 fi
2113
1902 export PYTHONDONTWRITEBYTECODE="1" 2114 export PYTHONDONTWRITEBYTECODE="1"
1903} 2115}
1904 2116
1905_python_clean_compiled_modules() { 2117_python_clean_compiled_modules() {
1906 _python_initialize_prefix_variables 2118 _python_initialize_prefix_variables
1921 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) 2133 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1922 2134
1923 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2135 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1924 # Delete empty child directories. 2136 # Delete empty child directories.
1925 find "${path}" -type d | sort -r | while read -r dir; do 2137 find "${path}" -type d | sort -r | while read -r dir; do
1926 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" 2138 if rmdir "${dir}" 2> /dev/null; then
2139 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2140 fi
1927 done 2141 done
1928 fi 2142 fi
1929 elif [[ "${path}" == *.py ]]; then 2143 elif [[ "${path}" == *.py ]]; then
1930 base_module_name="${path##*/}" 2144 base_module_name="${path##*/}"
1931 base_module_name="${base_module_name%.py}" 2145 base_module_name="${base_module_name%.py}"
1977 fi 2191 fi
1978 2192
1979 # Delete empty parent directories. 2193 # Delete empty parent directories.
1980 dir="${compiled_file%/*}" 2194 dir="${compiled_file%/*}"
1981 while [[ "${dir}" != "${root}" ]]; do 2195 while [[ "${dir}" != "${root}" ]]; do
1982 if rmdir "${compiled_file%/*}" 2> /dev/null; then 2196 if rmdir "${dir}" 2> /dev/null; then
1983 echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}" 2197 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1984 else 2198 else
1985 break 2199 break
1986 fi 2200 fi
1987 dir="${dir%/*}" 2201 dir="${dir%/*}"
1988 done 2202 done
2001# 2215#
2002# Options passed to this function are passed to compileall.py. 2216# Options passed to this function are passed to compileall.py.
2003# 2217#
2004# This function can be used only in pkg_postinst() phase. 2218# This function can be used only in pkg_postinst() phase.
2005python_mod_optimize() { 2219python_mod_optimize() {
2220 _python_check_python_pkg_setup_execution
2006 _python_initialize_prefix_variables 2221 _python_initialize_prefix_variables
2007 2222
2008 # Check if phase is pkg_postinst(). 2223 # Check if phase is pkg_postinst().
2009 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2224 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2010 2225
2011 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2226 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2012 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2227 # 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=() 2228 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=()
2014 2229
2015 if _python_package_supporting_installation_for_multiple_python_abis; then 2230 if _python_package_supporting_installation_for_multiple_python_abis; then
2016 if [[ -z "${PYTHON_ABIS}" ]]; then 2231 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2017 die "${FUNCNAME}(): Environment not initialized" 2232 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2018 fi 2233 fi
2019 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2234 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2020 else 2235 else
2236 if has "${EAPI:-0}" 0 1 2 3; then
2021 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}" 2237 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2238 else
2239 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2240 fi
2022 fi 2241 fi
2023 2242
2024 # Strip trailing slash from EROOT. 2243 # Strip trailing slash from EROOT.
2025 root="${EROOT%/}" 2244 root="${EROOT%/}"
2026 2245
2031 ;; 2250 ;;
2032 -d|-x) 2251 -d|-x)
2033 options+=("$1" "$2") 2252 options+=("$1" "$2")
2034 shift 2253 shift
2035 ;; 2254 ;;
2255 --)
2256 shift
2257 break
2258 ;;
2036 -*) 2259 -*)
2037 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2260 die "${FUNCNAME}(): Unrecognized option '$1'"
2038 ;; 2261 ;;
2039 *) 2262 *)
2040 break 2263 break
2041 ;; 2264 ;;
2042 esac 2265 esac
2058 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2281 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2059 einfo &> /dev/null 2282 einfo &> /dev/null
2060 fi 2283 fi
2061 2284
2062 while (($#)); do 2285 while (($#)); do
2286 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2287 die "${FUNCNAME}(): Invalid argument '$1'"
2063 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2288 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" 2289 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2065 elif [[ "$1" =~ ^/ ]]; then 2290 elif [[ "$1" =~ ^/ ]]; then
2066 if _python_package_supporting_installation_for_multiple_python_abis; then 2291 if _python_package_supporting_installation_for_multiple_python_abis; then
2067 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2292 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2068 fi 2293 fi
2069 if [[ -d "${root}$1" ]]; then 2294 if [[ -d "${root}$1" ]]; then
2070 other_dirs+=("${root}$1") 2295 other_dirs+=("${root}$1")
2071 elif [[ -f "${root}$1" ]]; then 2296 elif [[ -f "${root}$1" ]]; then
2072 other_files+=("${root}$1") 2297 other_files+=("${root}$1")
2073 elif [[ -e "${root}$1" ]]; then 2298 elif [[ -e "${root}$1" ]]; then
2074 eerror "'${root}$1' is not a file or a directory!" 2299 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2075 else 2300 else
2076 eerror "'${root}$1' does not exist!" 2301 eerror "${FUNCNAME}(): '${root}$1' does not exist"
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
2169 ;; 2394 ;;
2170 -d|-x) 2395 -d|-x)
2171 myopts+=("$1" "$2") 2396 myopts+=("$1" "$2")
2172 shift 2397 shift
2173 ;; 2398 ;;
2399 --)
2400 shift
2401 break
2402 ;;
2174 -*) 2403 -*)
2175 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2404 die "${FUNCNAME}(): Unrecognized option '$1'"
2176 ;; 2405 ;;
2177 *) 2406 *)
2178 break 2407 break
2179 ;; 2408 ;;
2180 esac 2409 esac
2196 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2425 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2197 einfo &> /dev/null 2426 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 # Files are passed to python_mod_compile which is EROOT-aware
2205 myfiles+=("$1") 2436 myfiles+=("$1")
2206 elif [[ -e "${myroot}/${1#/}" ]]; then 2437 elif [[ -e "${myroot}/${1#/}" ]]; then
2207 eerror "${myroot}/${1#/} is not a file or directory!" 2438 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2208 else 2439 else
2209 eerror "${myroot}/${1#/} does not exist!" 2440 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2210 fi 2441 fi
2211 shift 2442 shift
2212 done 2443 done
2213 2444
2214 # set additional opts 2445 # set additional opts
2241# determine if they are orphaned (i.e. their corresponding .py files are missing.) 2472# 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. 2473# If they are, then it will remove their corresponding .pyc and .pyo files.
2243# 2474#
2244# This function can be used only in pkg_postrm() phase. 2475# This function can be used only in pkg_postrm() phase.
2245python_mod_cleanup() { 2476python_mod_cleanup() {
2477 _python_check_python_pkg_setup_execution
2246 _python_initialize_prefix_variables 2478 _python_initialize_prefix_variables
2247 2479
2248 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2480 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2249 2481
2250 # Check if phase is pkg_postrm(). 2482 # Check if phase is pkg_postrm().
2251 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2483 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2252 2484
2253 if _python_package_supporting_installation_for_multiple_python_abis; then 2485 if _python_package_supporting_installation_for_multiple_python_abis; then
2254 if [[ -z "${PYTHON_ABIS}" ]]; then 2486 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2255 die "${FUNCNAME}(): Environment not initialized" 2487 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2256 fi 2488 fi
2257 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2489 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2258 else 2490 else
2491 if has "${EAPI:-0}" 0 1 2 3; then
2259 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}" 2492 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2493 else
2494 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2495 fi
2260 fi 2496 fi
2261 2497
2262 # Strip trailing slash from EROOT. 2498 # Strip trailing slash from EROOT.
2263 root="${EROOT%/}" 2499 root="${EROOT%/}"
2264 2500
2265 if [[ "$#" -gt 0 ]]; then 2501 if [[ "$#" -gt 0 ]]; then
2266 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2502 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2267 while (($#)); do 2503 while (($#)); do
2504 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2505 die "${FUNCNAME}(): Invalid argument '$1'"
2268 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2506 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" 2507 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2270 elif [[ "$1" =~ ^/ ]]; then 2508 elif [[ "$1" =~ ^/ ]]; then
2271 if _python_package_supporting_installation_for_multiple_python_abis; then 2509 if _python_package_supporting_installation_for_multiple_python_abis; then
2272 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2510 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2273 fi 2511 fi
2321 2559
2322# ================================================================================================ 2560# ================================================================================================
2323# ===================================== DEPRECATED FUNCTIONS ===================================== 2561# ===================================== DEPRECATED FUNCTIONS =====================================
2324# ================================================================================================ 2562# ================================================================================================
2325 2563
2326# @FUNCTION: python_version 2564# 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() { 2565python_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 2566 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 2567 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} 2568}
2364 2569
2365# @FUNCTION: python_mod_exists 2570# 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() { 2571python_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}()." 2572 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2380 die "${FUNCNAME}() cannot be used in this EAPI" 2573 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} 2574}
2402 2575
2403# @FUNCTION: python_tkinter_exists 2576# 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() { 2577python_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}()." 2578 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2410 die "${FUNCNAME}() cannot be used in this EAPI" 2579 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} 2580}
2440 2581
2441# @FUNCTION: python_mod_compile 2582# @FUNCTION: python_mod_compile
2442# @USAGE: <file> [more files ...] 2583# @USAGE: <file> [more files ...]
2443# @DESCRIPTION: 2584# @DESCRIPTION:

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

  ViewVC Help
Powered by ViewVC 1.1.20