/[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.104
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.104 2010/10/25 11:54:19 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) 19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_SUPPORTED_ABIS=(${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
26
27_python_set_IUSE() {
28 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI
29
30 _PYTHON_ABIS_USE_FLAGS=""
31 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
32
33 for PYTHON_ABI in "${_PYTHON_SUPPORTED_ABIS[@]}"; do
34 support_ABI="1"
35 while read restricted_ABI; do
36 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
37 support_ABI="0"
38 break
39 fi
40 done <<< "${restricted_ABIs}"
41 [[ "${support_ABI}" == "1" ]] && _PYTHON_ABIS_USE_FLAGS+="${_PYTHON_ABIS_USE_FLAGS:+ }python_abis_${PYTHON_ABI}"
42 done
43
44 IUSE="${_PYTHON_ABIS_USE_FLAGS}"
45}
46
47if ! has "${EAPI:-0}" 0 1 2 3 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
48 _python_set_IUSE
49fi
50unset -f _python_set_IUSE
21 51
22# @ECLASS-VARIABLE: PYTHON_DEPEND 52# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 53# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 54# Specification of dependency on dev-lang/python.
25# Syntax: 55# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 57# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 58# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 59# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 60# maximal_version: <maximal_major_version.maximal_minor_version>
31 61
32_parse_PYTHON_DEPEND() { 62_python_parse_PYTHON_DEPEND() {
33 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups 63 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
34 64
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 65 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 66 version_components_groups="${PYTHON_DEPEND}"
37 67
153} 183}
154 184
155DEPEND=">=app-admin/eselect-python-20091230" 185DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 186RDEPEND="${DEPEND}"
157 187
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 188if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 189 _python_parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON."
165 die "NEED_PYTHON cannot be used in this EAPI"
166 fi
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 190else
171 _PYTHON_ATOMS=("dev-lang/python") 191 _PYTHON_ATOMS=("dev-lang/python")
192fi
193unset -f _python_parse_PYTHON_DEPEND
194
195if [[ -n "${NEED_PYTHON}" ]]; then
196 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
197 die "NEED_PYTHON variable is banned"
172fi 198fi
173 199
174# @ECLASS-VARIABLE: PYTHON_USE_WITH 200# @ECLASS-VARIABLE: PYTHON_USE_WITH
175# @DESCRIPTION: 201# @DESCRIPTION:
176# Set this to a space separated list of USE flags the Python slot in use must be built with. 202# Set this to a space separated list of USE flags the Python slot in use must be built with.
211 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY 237 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
212fi 238fi
213 239
214unset _PYTHON_ATOMS 240unset _PYTHON_ATOMS
215 241
242# @FUNCTION: python_abi_depend
243# @USAGE: [-e|--exclude-ABIs Python_ABIs] [-i|--include-ABIs Python_ABIs] [--] <dependency_atom> [dependency_atoms]
244# @DESCRIPTION:
245# Print dependency atoms with USE dependencies for Python ABIs added.
246# If --exclude-ABIs option is specified, then Python ABIs matching its argument are not used.
247# If --include-ABIs option is specified, then only Python ABIs matching its argument are used.
248# --exclude-ABIs and --include-ABIs options cannot be specified simultaneously.
249python_abi_depend() {
250 local atom atom_index atoms=() exclude_ABIs="0" excluded_ABI excluded_ABIs include_ABIs="0" included_ABI included_ABIs support_ABI USE_dependencies USE_flag USE_flag_index USE_flags=()
251
252 if has "${EAPI:-0}" 0 1 2 3; then
253 die "${FUNCNAME}() cannot be used in this EAPI"
254 fi
255
256 if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
257 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
258 fi
259
260 while (($#)); do
261 case "$1" in
262 -e|--exclude-ABIs)
263 exclude_ABIs="1"
264 excluded_ABIs="${2// /$'\n'}"
265 shift
266 ;;
267 -i|--include-ABIs)
268 include_ABIs="1"
269 included_ABIs="${2// /$'\n'}"
270 shift
271 ;;
272 --)
273 shift
274 break
275 ;;
276 -*)
277 die "${FUNCNAME}(): Unrecognized option '$1'"
278 ;;
279 *)
280 break
281 ;;
282 esac
283 shift
284 done
285
286 if [[ "${exclude_ABIs}" == "1" && "${include_ABIs}" == "1" ]]; then
287 die "${FUNCNAME}(): '--exclude-ABIs' and '--include-ABIs' options cannot be specified simultaneously"
288 fi
289
290 if [[ "$#" -eq 0 ]]; then
291 die "${FUNCNAME}(): Missing dependency atoms"
292 fi
293
294 atoms=("$@")
295
296 if [[ "${exclude_ABIs}" == "0" && "${include_ABIs}" == "0" ]]; then
297 USE_dependencies="$(printf ",%s?" ${_PYTHON_ABIS_USE_FLAGS})"
298 USE_dependencies="${USE_dependencies#,}"
299
300 for atom_index in "${!atoms[@]}"; do
301 atom="${atoms[${atom_index}]}"
302
303 if [[ "${atom}" == *"["*"]" ]]; then
304 echo -n "${atom%]},"
305 else
306 echo -n "${atom}["
307 fi
308 echo -n "${USE_dependencies}]"
309
310 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
311 echo -n " "
312 fi
313 done
314 else
315 if [[ "${exclude_ABIs}" == "1" ]]; then
316 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
317 while read excluded_ABI; do
318 support_ABI="1"
319 if [[ "${USE_flag}" == python_abis_${excluded_ABI} ]]; then
320 support_ABI="0"
321 break
322 fi
323 done <<< "${excluded_ABIs}"
324 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
325 done
326 elif [[ "${include_ABIs}" == "1" ]]; then
327 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
328 while read included_ABI; do
329 support_ABI="0"
330 if [[ "${USE_flag}" == python_abis_${included_ABI} ]]; then
331 support_ABI="1"
332 break
333 fi
334 done <<< "${included_ABIs}"
335 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
336 done
337 else
338 die "${FUNCNAME}(): Internal error"
339 fi
340
341 for USE_flag_index in "${!USE_flags[@]}"; do
342 USE_flag="${USE_flags[${USE_flag_index}]}"
343 USE_dependencies="${USE_flag}"
344
345 echo -n "${USE_flag}? ( "
346
347 for atom_index in "${!atoms[@]}"; do
348 atom="${atoms[${atom_index}]}"
349
350 if [[ "${atom}" == *"["*"]" ]]; then
351 echo -n "${atom%]},"
352 else
353 echo -n "${atom}["
354 fi
355 echo -n "${USE_dependencies}]"
356
357 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
358 echo -n " "
359 fi
360 done
361
362 echo -n " )"
363
364 if [[ "${USE_flag_index}" -ne $((${#USE_flags[@]} - 1)) ]]; then
365 echo -n " "
366 fi
367 done
368 fi
369}
370
216# ================================================================================================ 371# ================================================================================================
217# =================================== MISCELLANEOUS FUNCTIONS ==================================== 372# =================================== MISCELLANEOUS FUNCTIONS ====================================
218# ================================================================================================ 373# ================================================================================================
219 374
220_python_implementation() { 375_python_implementation() {
241 else 396 else
242 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" 397 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
243 fi 398 fi
244} 399}
245 400
401_python_abi-specific_local_scope() {
402 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
403}
404
246_python_initialize_prefix_variables() { 405_python_initialize_prefix_variables() {
247 if has "${EAPI:-0}" 0 1 2; then 406 if has "${EAPI:-0}" 0 1 2; then
248 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then 407 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
249 EROOT="${ROOT%/}${EPREFIX}/" 408 EROOT="${ROOT%/}${EPREFIX}/"
250 fi 409 fi
252 ED="${D%/}${EPREFIX}/" 411 ED="${D%/}${EPREFIX}/"
253 fi 412 fi
254 fi 413 fi
255} 414}
256 415
257unset PYTHON_SANITY_CHECKS 416unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
258 417
259_python_initial_sanity_checks() { 418_python_initial_sanity_checks() {
260 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 419 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. 420 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
262 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then 421 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
263 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." 422 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
264 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 423 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
265 die "'${EPREFIX}/usr/bin/python' is not valid symlink" 424 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
271 fi 430 fi
272 fi 431 fi
273} 432}
274 433
275_python_final_sanity_checks() { 434_python_final_sanity_checks() {
276 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then 435 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}" 436 local PYTHON_ABI="${PYTHON_ABI}"
278 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do 437 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
279 # Ensure that appropriate version of Python is installed. 438 # Ensure that appropriate version of Python is installed.
280 if ! has_version "$(python_get_implementational_package)"; then 439 if ! has_version "$(python_get_implementational_package)"; then
281 die "$(python_get_implementational_package) is not installed" 440 die "$(python_get_implementational_package) is not installed"
291 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" 450 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
292 die "'python' does not respect EPYTHON variable" 451 die "'python' does not respect EPYTHON variable"
293 fi 452 fi
294 done 453 done
295 fi 454 fi
296 PYTHON_SANITY_CHECKS="1" 455 PYTHON_SANITY_CHECKS_EXECUTED="1"
297} 456}
457
458# @ECLASS-VARIABLE: PYTHON_COLORS
459# @DESCRIPTION:
460# User-configurable colored output.
461PYTHON_COLORS="${PYTHON_COLORS:-0}"
298 462
299_python_set_color_variables() { 463_python_set_color_variables() {
300 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 464 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
301 _BOLD=$'\e[1m' 465 _BOLD=$'\e[1m'
302 _RED=$'\e[1;31m' 466 _RED=$'\e[1;31m'
303 _GREEN=$'\e[1;32m' 467 _GREEN=$'\e[1;32m'
304 _BLUE=$'\e[1;34m' 468 _BLUE=$'\e[1;34m'
305 _CYAN=$'\e[1;36m' 469 _CYAN=$'\e[1;36m'
313 _NORMAL= 477 _NORMAL=
314 fi 478 fi
315} 479}
316 480
317unset PYTHON_PKG_SETUP_EXECUTED 481unset PYTHON_PKG_SETUP_EXECUTED
482
483_python_check_python_pkg_setup_execution() {
484 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
485
486 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
487 die "python_pkg_setup() not called"
488 fi
489}
318 490
319# @FUNCTION: python_pkg_setup 491# @FUNCTION: python_pkg_setup
320# @DESCRIPTION: 492# @DESCRIPTION:
321# Perform sanity checks and initialize environment. 493# Perform sanity checks and initialize environment.
322# 494#
326# This function can be used only in pkg_setup() phase. 498# This function can be used only in pkg_setup() phase.
327python_pkg_setup() { 499python_pkg_setup() {
328 # Check if phase is pkg_setup(). 500 # Check if phase is pkg_setup().
329 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 501 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
330 502
503 if [[ "$#" -ne 0 ]]; then
504 die "${FUNCNAME}() does not accept arguments"
505 fi
506
331 if _python_package_supporting_installation_for_multiple_python_abis; then 507 if _python_package_supporting_installation_for_multiple_python_abis; then
332 _python_calculate_PYTHON_ABIS 508 _python_calculate_PYTHON_ABIS
333 export EPYTHON="$(PYTHON -f)" 509 export EPYTHON="$(PYTHON -f)"
334 else 510 else
335 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 511 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}" 542 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
367 fi 543 fi
368 } 544 }
369 545
370 if _python_package_supporting_installation_for_multiple_python_abis; then 546 if _python_package_supporting_installation_for_multiple_python_abis; then
371 python_execute_function -q python_pkg_setup_check_USE_flags 547 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
372 else 548 else
373 python_pkg_setup_check_USE_flags 549 python_pkg_setup_check_USE_flags
374 fi 550 fi
375 551
376 unset -f python_pkg_setup_check_USE_flags 552 unset -f python_pkg_setup_check_USE_flags
377 fi 553 fi
378 554
379 PYTHON_PKG_SETUP_EXECUTED="1" 555 PYTHON_PKG_SETUP_EXECUTED="1"
380} 556}
381 557
382if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 558if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
383 EXPORT_FUNCTIONS pkg_setup 559 EXPORT_FUNCTIONS pkg_setup
384fi 560fi
385 561
386# @FUNCTION: python_convert_shebangs 562# @FUNCTION: python_convert_shebangs
387# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 563# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
388# @DESCRIPTION: 564# @DESCRIPTION:
389# Convert shebangs in specified files. Directories can be specified only with --recursive option. 565# Convert shebangs in specified files. Directories can be specified only with --recursive option.
390python_convert_shebangs() { 566python_convert_shebangs() {
567 _python_check_python_pkg_setup_execution
568
391 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 569 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
392 570
393 while (($#)); do 571 while (($#)); do
394 case "$1" in 572 case "$1" in
395 -r|--recursive) 573 -r|--recursive)
464# @FUNCTION: python_clean_installation_image 642# @FUNCTION: python_clean_installation_image
465# @USAGE: [-q|--quiet] 643# @USAGE: [-q|--quiet]
466# @DESCRIPTION: 644# @DESCRIPTION:
467# Delete needless files in installation image. 645# Delete needless files in installation image.
468python_clean_installation_image() { 646python_clean_installation_image() {
647 _python_check_python_pkg_setup_execution
469 _python_initialize_prefix_variables 648 _python_initialize_prefix_variables
470 649
471 local file files=() quiet="0" 650 local file files=() quiet="0"
472 651
473 # Check if phase is src_install(). 652 # Check if phase is src_install().
536# @DESCRIPTION: 715# @DESCRIPTION:
537# Set this to export phase functions for the following ebuild phases: 716# Set this to export phase functions for the following ebuild phases:
538# src_prepare, src_configure, src_compile, src_test, src_install. 717# src_prepare, src_configure, src_compile, src_test, src_install.
539if ! has "${EAPI:-0}" 0 1; then 718if ! has "${EAPI:-0}" 0 1; then
540 python_src_prepare() { 719 python_src_prepare() {
720 _python_check_python_pkg_setup_execution
721
541 if ! _python_package_supporting_installation_for_multiple_python_abis; then 722 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" 723 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
543 fi 724 fi
544 725
726 if [[ "$#" -ne 0 ]]; then
727 die "${FUNCNAME}() does not accept arguments"
728 fi
729
545 python_copy_sources 730 python_copy_sources
546 } 731 }
547 732
548 for python_default_function in src_configure src_compile src_test src_install; do 733 for python_default_function in src_configure src_compile src_test src_install; do
549 eval "python_${python_default_function}() { 734 eval "python_${python_default_function}() {
735 _python_check_python_pkg_setup_execution
736
550 if ! _python_package_supporting_installation_for_multiple_python_abis; then 737 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\" 738 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
552 fi 739 fi
553 740
554 python_execute_function -d -s -- \"\$@\" 741 python_execute_function -d -s -- \"\$@\"
559 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
560 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 747 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
561 fi 748 fi
562fi 749fi
563 750
751if has "${EAPI:-0}" 0 1 2 3; then
564unset PYTHON_ABIS 752 unset PYTHON_ABIS
753fi
565 754
566_python_calculate_PYTHON_ABIS() { 755_python_calculate_PYTHON_ABIS() {
567 if ! _python_package_supporting_installation_for_multiple_python_abis; then 756 if ! _python_package_supporting_installation_for_multiple_python_abis; then
568 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 757 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
569 fi 758 fi
570 759
571 _python_initial_sanity_checks 760 _python_initial_sanity_checks
572 761
573 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
574 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 762 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
575 local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= 763 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
576 PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" 764
765 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
577 766
578 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 767 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
579 local cpython_enabled="0" 768 local cpython_enabled="0"
580 769
581 if [[ -z "${USE_PYTHON}" ]]; then 770 if [[ -z "${USE_PYTHON}" ]]; then
582 die "USE_PYTHON variable is empty" 771 die "USE_PYTHON variable is empty"
583 fi 772 fi
584 773
585 for PYTHON_ABI in ${USE_PYTHON}; do 774 for PYTHON_ABI in ${USE_PYTHON}; do
586 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 775 if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then
587 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 776 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
588 fi 777 fi
589 778
590 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 779 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
591 cpython_enabled="1" 780 cpython_enabled="1"
592 fi 781 fi
593 782
594 support_ABI="1" 783 support_ABI="1"
595 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 784 while read restricted_ABI; do
596 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 785 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
597 support_ABI="0" 786 support_ABI="0"
598 break 787 break
599 fi 788 fi
600 done 789 done <<< "${restricted_ABIs}"
601 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 790 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
602 done 791 done
603 792
604 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 793 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
605 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 794 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
624 813
625 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 814 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
626 815
627 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 816 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
628 support_python_major_version="1" 817 support_python_major_version="1"
629 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 818 while read restricted_ABI; do
630 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 819 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
631 support_python_major_version="0" 820 support_python_major_version="0"
632 fi 821 fi
633 done 822 done <<< "${restricted_ABIs}"
634 [[ "${support_python_major_version}" == "1" ]] && break 823 [[ "${support_python_major_version}" == "1" ]] && break
635 done 824 done
636 if [[ "${support_python_major_version}" == "1" ]]; then 825 if [[ "${support_python_major_version}" == "1" ]]; then
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 826 while read restricted_ABI; do
638 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 827 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
639 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 828 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
640 fi 829 fi
641 done 830 done <<< "${restricted_ABIs}"
642 else 831 else
643 python2_version="" 832 python2_version=""
644 fi 833 fi
645 fi 834 fi
646 835
651 840
652 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 841 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
653 842
654 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 843 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
655 support_python_major_version="1" 844 support_python_major_version="1"
656 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 845 while read restricted_ABI; do
657 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 846 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
658 support_python_major_version="0" 847 support_python_major_version="0"
659 fi 848 fi
660 done 849 done <<< "${restricted_ABIs}"
661 [[ "${support_python_major_version}" == "1" ]] && break 850 [[ "${support_python_major_version}" == "1" ]] && break
662 done 851 done
663 if [[ "${support_python_major_version}" == "1" ]]; then 852 if [[ "${support_python_major_version}" == "1" ]]; then
664 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 853 while read restricted_ABI; do
665 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 854 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
666 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 855 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
667 fi 856 fi
668 done 857 done <<< "${restricted_ABIs}"
669 else 858 else
670 python3_version="" 859 python3_version=""
671 fi 860 fi
672 fi 861 fi
673 862
689 fi 878 fi
690 879
691 _python_final_sanity_checks 880 _python_final_sanity_checks
692} 881}
693 882
883_python_prepare_flags() {
884 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
885
886 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
887 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
888 for prefix in PYTHON_USER_ PYTHON_; do
889 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
890 eval "array=(\"\${${prefix}${variable}[@]}\")"
891 for element in "${array[@]}"; do
892 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
893 pattern="${element%% *}"
894 element="${element#* }"
895 operator="${element%% *}"
896 flags="${element#* }"
897 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
898 if [[ "${operator}" == "+" ]]; then
899 eval "export ${variable}+=\"\${variable:+ }${flags}\""
900 elif [[ "${operator}" == "-" ]]; then
901 flags="${flags// /$'\n'}"
902 old_value="${!variable// /$'\n'}"
903 new_value=""
904 while read old_flag; do
905 while read deleted_flag; do
906 if [[ "${old_flag}" == ${deleted_flag} ]]; then
907 continue 2
908 fi
909 done <<< "${flags}"
910 new_value+="${new_value:+ }${old_flag}"
911 done <<< "${old_value}"
912 eval "export ${variable}=\"\${new_value}\""
913 fi
914 fi
915 else
916 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
917 fi
918 done
919 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
920 die "${prefix}${variable} should be indexed array"
921 fi
922 done
923 done
924}
925
926_python_restore_flags() {
927 local variable
928
929 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
930 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
931 unset _PYTHON_SAVED_${variable}
932 done
933}
934
694# @FUNCTION: python_execute_function 935# @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] 936# @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: 937# @DESCRIPTION:
697# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 938# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
698# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 939# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
699python_execute_function() { 940python_execute_function() {
941 _python_check_python_pkg_setup_execution
942
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 943 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" 944 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 945 fi
703 946
704 _python_set_color_variables 947 _python_set_color_variables
705 948
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= 949 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 950
708 while (($#)); do 951 while (($#)); do
709 case "$1" in 952 case "$1" in
710 --action-message) 953 --action-message)
711 action_message_template="$2" 954 action_message_template="$2"
798 fi 1041 fi
799 function="python_default_function" 1042 function="python_default_function"
800 fi 1043 fi
801 1044
802 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 1045 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
803 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 1046 if _python_abi-specific_local_scope; then
804 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
805 die "${FUNCNAME}(): Invalid call stack" 1047 die "${FUNCNAME}(): Invalid call stack"
806 fi 1048 fi
807 done
808 1049
809 if [[ "${quiet}" == "0" ]]; then 1050 if [[ "${quiet}" == "0" ]]; then
810 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 1051 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
811 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 1052 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
812 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 1053 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
825 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 1066 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
826 else 1067 else
827 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 1068 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
828 fi 1069 fi
829 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 1070 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1071 _python_prepare_flags
1072
830 if [[ "${quiet}" == "0" ]]; then 1073 if [[ "${quiet}" == "0" ]]; then
831 if [[ -n "${action_message_template}" ]]; then 1074 if [[ -n "${action_message_template}" ]]; then
832 action_message="$(eval echo -n "${action_message_template}")" 1075 eval "action_message=\"${action_message_template}\""
833 else 1076 else
834 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 1077 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
835 fi 1078 fi
836 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" 1079 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
837 fi 1080 fi
855 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 1098 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
856 else 1099 else
857 EPYTHON="$(PYTHON)" "${function}" "$@" 1100 EPYTHON="$(PYTHON)" "${function}" "$@"
858 fi 1101 fi
859 1102
860 if [[ "$?" != "0" ]]; then 1103 return_code="$?"
1104
1105 _python_restore_flags
1106
1107 if [[ "${return_code}" -ne 0 ]]; then
861 if [[ -n "${failure_message_template}" ]]; then 1108 if [[ -n "${failure_message_template}" ]]; then
862 failure_message="$(eval echo -n "${failure_message_template}")" 1109 eval "failure_message=\"${failure_message_template}\""
863 else 1110 else
864 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 1111 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
865 fi 1112 fi
866 1113
867 if [[ "${nonfatal}" == "1" ]]; then 1114 if [[ "${nonfatal}" == "1" ]]; then
868 if [[ "${quiet}" == "0" ]]; then 1115 if [[ "${quiet}" == "0" ]]; then
869 ewarn "${_RED}${failure_message}${_NORMAL}" 1116 ewarn "${failure_message}"
870 fi 1117 fi
871 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 1118 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
872 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 1119 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
873 local enabled_PYTHON_ABIS= other_PYTHON_ABI 1120 local enabled_PYTHON_ABIS= other_PYTHON_ABI
874 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 1121 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
875 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 1122 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
876 done 1123 done
877 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 1124 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
878 fi 1125 fi
879 if [[ "${quiet}" == "0" ]]; then 1126 if [[ "${quiet}" == "0" ]]; then
880 ewarn "${_RED}${failure_message}${_NORMAL}" 1127 ewarn "${failure_message}"
881 fi 1128 fi
882 if [[ -z "${PYTHON_ABIS}" ]]; then 1129 if [[ -z "${PYTHON_ABIS}" ]]; then
883 die "${function}() function failed with all enabled Python ABIs" 1130 die "${function}() function failed with all enabled Python ABIs"
884 fi 1131 fi
885 else 1132 else
922# @FUNCTION: python_copy_sources 1169# @FUNCTION: python_copy_sources
923# @USAGE: <directory="${S}"> [directory] 1170# @USAGE: <directory="${S}"> [directory]
924# @DESCRIPTION: 1171# @DESCRIPTION:
925# Copy unpacked sources of current package to separate build directory for each Python ABI. 1172# Copy unpacked sources of current package to separate build directory for each Python ABI.
926python_copy_sources() { 1173python_copy_sources() {
1174 _python_check_python_pkg_setup_execution
1175
927 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1176 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" 1177 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
929 fi 1178 fi
930 1179
931 local dir dirs=() PYTHON_ABI 1180 local dir dirs=() PYTHON_ABI
952# @DESCRIPTION: 1201# @DESCRIPTION:
953# Generate wrapper scripts. Existing files are overwritten only with --force option. 1202# Generate wrapper scripts. Existing files are overwritten only with --force option.
954# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1203# If --respect-EPYTHON option is specified, then generated wrapper scripts will
955# respect EPYTHON variable at run time. 1204# respect EPYTHON variable at run time.
956python_generate_wrapper_scripts() { 1205python_generate_wrapper_scripts() {
1206 _python_check_python_pkg_setup_execution
1207
957 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1208 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" 1209 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
959 fi 1210 fi
960 1211
961 _python_initialize_prefix_variables 1212 _python_initialize_prefix_variables
1155 1406
1156# ================================================================================================ 1407# ================================================================================================
1157# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1408# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
1158# ================================================================================================ 1409# ================================================================================================
1159 1410
1411unset EPYTHON PYTHON_ABI
1412
1160# @FUNCTION: python_set_active_version 1413# @FUNCTION: python_set_active_version
1161# @USAGE: <CPython_ABI|2|3> 1414# @USAGE: <CPython_ABI|2|3>
1162# @DESCRIPTION: 1415# @DESCRIPTION:
1163# Set specified version of CPython as active version of Python. 1416# Set specified version of CPython as active version of Python.
1417#
1418# This function can be used only in pkg_setup() phase.
1164python_set_active_version() { 1419python_set_active_version() {
1420 # Check if phase is pkg_setup().
1421 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1422
1165 if _python_package_supporting_installation_for_multiple_python_abis; then 1423 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" 1424 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1167 fi 1425 fi
1168 1426
1169 if [[ "$#" -ne 1 ]]; then 1427 if [[ "$#" -ne 1 ]]; then
1170 die "${FUNCNAME}() requires 1 argument" 1428 die "${FUNCNAME}() requires 1 argument"
1171 fi 1429 fi
1172 1430
1173 _python_initial_sanity_checks 1431 _python_initial_sanity_checks
1174 1432
1433 if [[ -z "${PYTHON_ABI}" ]]; then
1175 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1434 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1176 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1435 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
1177 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1436 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
1178 fi 1437 fi
1179 export EPYTHON="$(PYTHON "$1")" 1438 export EPYTHON="$(PYTHON "$1")"
1180 elif [[ "$1" == "2" ]]; then 1439 elif [[ "$1" == "2" ]]; then
1181 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1440 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
1182 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1441 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
1183 fi 1442 fi
1184 export EPYTHON="$(PYTHON -2)" 1443 export EPYTHON="$(PYTHON -2)"
1185 elif [[ "$1" == "3" ]]; then 1444 elif [[ "$1" == "3" ]]; then
1186 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1445 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
1187 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1446 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
1188 fi 1447 fi
1189 export EPYTHON="$(PYTHON -3)" 1448 export EPYTHON="$(PYTHON -3)"
1190 else 1449 else
1191 die "${FUNCNAME}(): Unrecognized argument '$1'" 1450 die "${FUNCNAME}(): Unrecognized argument '$1'"
1192 fi 1451 fi
1193 1452
1194 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1453 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1195 # so it does not need to be exported to subprocesses. 1454 # so it does not need to be exported to subprocesses.
1196 PYTHON_ABI="${EPYTHON#python}" 1455 PYTHON_ABI="${EPYTHON#python}"
1197 PYTHON_ABI="${PYTHON_ABI%%-*}" 1456 PYTHON_ABI="${PYTHON_ABI%%-*}"
1457 fi
1198 1458
1199 _python_final_sanity_checks 1459 _python_final_sanity_checks
1200 1460
1201 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1461 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1202 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1462 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1204 1464
1205# @FUNCTION: python_need_rebuild 1465# @FUNCTION: python_need_rebuild
1206# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1466# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1207# switching of active version of Python. 1467# switching of active version of Python.
1208python_need_rebuild() { 1468python_need_rebuild() {
1469 _python_check_python_pkg_setup_execution
1470
1209 if _python_package_supporting_installation_for_multiple_python_abis; then 1471 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" 1472 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1473 fi
1474
1475 if [[ "$#" -ne 0 ]]; then
1476 die "${FUNCNAME}() does not accept arguments"
1211 fi 1477 fi
1212 1478
1213 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1479 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1214} 1480}
1215 1481
1249# If --ABI option is specified, then only specified Python ABI is printed instead of 1515# If --ABI option is specified, then only specified Python ABI is printed instead of
1250# filename of Python interpreter. 1516# filename of Python interpreter.
1251# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1517# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1252# --ABI and --absolute-path options cannot be specified simultaneously. 1518# --ABI and --absolute-path options cannot be specified simultaneously.
1253PYTHON() { 1519PYTHON() {
1520 _python_check_python_pkg_setup_execution
1521
1254 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1522 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1255 1523
1256 while (($#)); do 1524 while (($#)); do
1257 case "$1" in 1525 case "$1" in
1258 -2) 1526 -2)
1283 esac 1551 esac
1284 shift 1552 shift
1285 done 1553 done
1286 1554
1287 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1555 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1288 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1556 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1289 fi 1557 fi
1290 1558
1291 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1559 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1292 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1560 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1293 fi 1561 fi
1311 if [[ -z "${PYTHON_ABI}" ]]; then 1579 if [[ -z "${PYTHON_ABI}" ]]; then
1312 die "${FUNCNAME}(): Active version of Python 3 not set" 1580 die "${FUNCNAME}(): Active version of Python 3 not set"
1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1581 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1582 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1315 fi 1583 fi
1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1584 elif _python_package_supporting_installation_for_multiple_python_abis; then
1585 if ! _python_abi-specific_local_scope; then
1586 die "${FUNCNAME}() should be used in ABI-specific local scope"
1587 fi
1588 else
1317 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1589 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1318 if [[ -z "${PYTHON_ABI}" ]]; then 1590 if [[ -z "${PYTHON_ABI}" ]]; then
1319 die "${FUNCNAME}(): Failure of extraction of locally active version of Python" 1591 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1320 fi 1592 fi
1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1322 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1323 fi 1593 fi
1324 elif [[ "$#" -eq 1 ]]; then 1594 elif [[ "$#" -eq 1 ]]; then
1325 if [[ "${final_ABI}" == "1" ]]; then 1595 if [[ "${final_ABI}" == "1" ]]; then
1326 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1596 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1327 fi 1597 fi
1362# @USAGE: [-f|--final-ABI] 1632# @USAGE: [-f|--final-ABI]
1363# @DESCRIPTION: 1633# @DESCRIPTION:
1364# Print name of Python implementation. 1634# Print name of Python implementation.
1365# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1635# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1366python_get_implementation() { 1636python_get_implementation() {
1637 _python_check_python_pkg_setup_execution
1638
1367 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1639 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1368 1640
1369 while (($#)); do 1641 while (($#)); do
1370 case "$1" in 1642 case "$1" in
1371 -f|--final-ABI) 1643 -f|--final-ABI)
1384 if [[ "${final_ABI}" == "1" ]]; then 1656 if [[ "${final_ABI}" == "1" ]]; then
1385 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1657 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" 1658 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1387 fi 1659 fi
1388 PYTHON_ABI="$(PYTHON -f --ABI)" 1660 PYTHON_ABI="$(PYTHON -f --ABI)"
1389 elif [[ -z "${PYTHON_ABI}" ]]; then 1661 else
1662 if _python_package_supporting_installation_for_multiple_python_abis; then
1663 if ! _python_abi-specific_local_scope; then
1664 die "${FUNCNAME}() should be used in ABI-specific local scope"
1665 fi
1666 else
1390 PYTHON_ABI="$(PYTHON --ABI)" 1667 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1668 fi
1391 fi 1669 fi
1392 1670
1393 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1671 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1394} 1672}
1395 1673
1397# @USAGE: [-f|--final-ABI] 1675# @USAGE: [-f|--final-ABI]
1398# @DESCRIPTION: 1676# @DESCRIPTION:
1399# Print category, name and slot of package providing Python implementation. 1677# 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. 1678# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1401python_get_implementational_package() { 1679python_get_implementational_package() {
1680 _python_check_python_pkg_setup_execution
1681
1402 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1682 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1403 1683
1404 while (($#)); do 1684 while (($#)); do
1405 case "$1" in 1685 case "$1" in
1406 -f|--final-ABI) 1686 -f|--final-ABI)
1419 if [[ "${final_ABI}" == "1" ]]; then 1699 if [[ "${final_ABI}" == "1" ]]; then
1420 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1700 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" 1701 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1422 fi 1702 fi
1423 PYTHON_ABI="$(PYTHON -f --ABI)" 1703 PYTHON_ABI="$(PYTHON -f --ABI)"
1424 elif [[ -z "${PYTHON_ABI}" ]]; then 1704 else
1705 if _python_package_supporting_installation_for_multiple_python_abis; then
1706 if ! _python_abi-specific_local_scope; then
1707 die "${FUNCNAME}() should be used in ABI-specific local scope"
1708 fi
1709 else
1425 PYTHON_ABI="$(PYTHON --ABI)" 1710 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1426 fi 1711 fi
1712 fi
1427 1713
1714 if [[ "${EAPI:-0}" == "0" ]]; then
1428 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1715 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1429 echo "dev-lang/python:${PYTHON_ABI}" 1716 echo "=dev-lang/python-${PYTHON_ABI}*"
1430 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1717 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1718 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1719 fi
1720 else
1721 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1722 echo "dev-lang/python:${PYTHON_ABI}"
1723 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1431 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1724 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1725 fi
1432 fi 1726 fi
1433} 1727}
1434 1728
1435# @FUNCTION: python_get_includedir 1729# @FUNCTION: python_get_includedir
1436# @USAGE: [-f|--final-ABI] 1730# @USAGE: [-b|--base-path] [-f|--final-ABI]
1437# @DESCRIPTION: 1731# @DESCRIPTION:
1438# Print path to Python include directory. 1732# Print path to Python include directory.
1733# 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. 1734# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1440python_get_includedir() { 1735python_get_includedir() {
1736 _python_check_python_pkg_setup_execution
1737
1441 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1738 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1442 1739
1443 while (($#)); do 1740 while (($#)); do
1444 case "$1" in 1741 case "$1" in
1742 -b|--base-path)
1743 base_path="1"
1744 ;;
1445 -f|--final-ABI) 1745 -f|--final-ABI)
1446 final_ABI="1" 1746 final_ABI="1"
1447 ;; 1747 ;;
1448 -*) 1748 -*)
1449 die "${FUNCNAME}(): Unrecognized option '$1'" 1749 die "${FUNCNAME}(): Unrecognized option '$1'"
1452 die "${FUNCNAME}(): Invalid usage" 1752 die "${FUNCNAME}(): Invalid usage"
1453 ;; 1753 ;;
1454 esac 1754 esac
1455 shift 1755 shift
1456 done 1756 done
1757
1758 if [[ "${base_path}" == "0" ]]; then
1759 prefix="/"
1760 fi
1457 1761
1458 if [[ "${final_ABI}" == "1" ]]; then 1762 if [[ "${final_ABI}" == "1" ]]; then
1459 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1763 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" 1764 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1461 fi 1765 fi
1462 PYTHON_ABI="$(PYTHON -f --ABI)" 1766 PYTHON_ABI="$(PYTHON -f --ABI)"
1463 elif [[ -z "${PYTHON_ABI}" ]]; then 1767 else
1768 if _python_package_supporting_installation_for_multiple_python_abis; then
1769 if ! _python_abi-specific_local_scope; then
1770 die "${FUNCNAME}() should be used in ABI-specific local scope"
1771 fi
1772 else
1464 PYTHON_ABI="$(PYTHON --ABI)" 1773 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1774 fi
1465 fi 1775 fi
1466 1776
1467 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1777 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1468 echo "/usr/include/python${PYTHON_ABI}" 1778 echo "${prefix}usr/include/python${PYTHON_ABI}"
1469 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1779 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1470 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1780 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1471 fi 1781 fi
1472} 1782}
1473 1783
1474# @FUNCTION: python_get_libdir 1784# @FUNCTION: python_get_libdir
1475# @USAGE: [-f|--final-ABI] 1785# @USAGE: [-b|--base-path] [-f|--final-ABI]
1476# @DESCRIPTION: 1786# @DESCRIPTION:
1477# Print path to Python library directory. 1787# Print path to Python library directory.
1788# 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. 1789# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1479python_get_libdir() { 1790python_get_libdir() {
1791 _python_check_python_pkg_setup_execution
1792
1480 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1793 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1481 1794
1482 while (($#)); do 1795 while (($#)); do
1483 case "$1" in 1796 case "$1" in
1797 -b|--base-path)
1798 base_path="1"
1799 ;;
1484 -f|--final-ABI) 1800 -f|--final-ABI)
1485 final_ABI="1" 1801 final_ABI="1"
1486 ;; 1802 ;;
1487 -*) 1803 -*)
1488 die "${FUNCNAME}(): Unrecognized option '$1'" 1804 die "${FUNCNAME}(): Unrecognized option '$1'"
1491 die "${FUNCNAME}(): Invalid usage" 1807 die "${FUNCNAME}(): Invalid usage"
1492 ;; 1808 ;;
1493 esac 1809 esac
1494 shift 1810 shift
1495 done 1811 done
1812
1813 if [[ "${base_path}" == "0" ]]; then
1814 prefix="/"
1815 fi
1496 1816
1497 if [[ "${final_ABI}" == "1" ]]; then 1817 if [[ "${final_ABI}" == "1" ]]; then
1498 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1818 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" 1819 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1500 fi 1820 fi
1501 PYTHON_ABI="$(PYTHON -f --ABI)" 1821 PYTHON_ABI="$(PYTHON -f --ABI)"
1502 elif [[ -z "${PYTHON_ABI}" ]]; then 1822 else
1823 if _python_package_supporting_installation_for_multiple_python_abis; then
1824 if ! _python_abi-specific_local_scope; then
1825 die "${FUNCNAME}() should be used in ABI-specific local scope"
1826 fi
1827 else
1503 PYTHON_ABI="$(PYTHON --ABI)" 1828 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1829 fi
1504 fi 1830 fi
1505 1831
1506 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1832 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1507 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1833 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1508 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1834 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1509 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1835 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1510 fi 1836 fi
1511} 1837}
1512 1838
1513# @FUNCTION: python_get_sitedir 1839# @FUNCTION: python_get_sitedir
1514# @USAGE: [-f|--final-ABI] 1840# @USAGE: [-b|--base-path] [-f|--final-ABI]
1515# @DESCRIPTION: 1841# @DESCRIPTION:
1516# Print path to Python site-packages directory. 1842# Print path to Python site-packages directory.
1843# 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. 1844# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1518python_get_sitedir() { 1845python_get_sitedir() {
1519 local options=() 1846 _python_check_python_pkg_setup_execution
1847
1848 local final_ABI="0" options=()
1520 1849
1521 while (($#)); do 1850 while (($#)); do
1522 case "$1" in 1851 case "$1" in
1852 -b|--base-path)
1853 options+=("$1")
1854 ;;
1523 -f|--final-ABI) 1855 -f|--final-ABI)
1524 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1856 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") 1857 options+=("$1")
1528 ;; 1858 ;;
1529 -*) 1859 -*)
1530 die "${FUNCNAME}(): Unrecognized option '$1'" 1860 die "${FUNCNAME}(): Unrecognized option '$1'"
1531 ;; 1861 ;;
1534 ;; 1864 ;;
1535 esac 1865 esac
1536 shift 1866 shift
1537 done 1867 done
1538 1868
1869 if [[ "${final_ABI}" == "1" ]]; then
1870 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1871 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1872 fi
1873 else
1874 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1875 die "${FUNCNAME}() should be used in ABI-specific local scope"
1876 fi
1877 fi
1878
1539 echo "$(python_get_libdir "${options[@]}")/site-packages" 1879 echo "$(python_get_libdir "${options[@]}")/site-packages"
1540} 1880}
1541 1881
1542# @FUNCTION: python_get_library 1882# @FUNCTION: python_get_library
1543# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1883# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1544# @DESCRIPTION: 1884# @DESCRIPTION:
1545# Print path to Python library. 1885# Print path to Python library.
1886# 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. 1887# 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. 1888# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1548python_get_library() { 1889python_get_library() {
1890 _python_check_python_pkg_setup_execution
1891
1549 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1892 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1550 1893
1551 while (($#)); do 1894 while (($#)); do
1552 case "$1" in 1895 case "$1" in
1896 -b|--base-path)
1897 base_path="1"
1898 ;;
1553 -f|--final-ABI) 1899 -f|--final-ABI)
1554 final_ABI="1" 1900 final_ABI="1"
1555 ;; 1901 ;;
1556 -l|--linker-option) 1902 -l|--linker-option)
1557 linker_option="1" 1903 linker_option="1"
1563 die "${FUNCNAME}(): Invalid usage" 1909 die "${FUNCNAME}(): Invalid usage"
1564 ;; 1910 ;;
1565 esac 1911 esac
1566 shift 1912 shift
1567 done 1913 done
1914
1915 if [[ "${base_path}" == "0" ]]; then
1916 prefix="/"
1917 fi
1918
1919 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1920 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1921 fi
1568 1922
1569 if [[ "${final_ABI}" == "1" ]]; then 1923 if [[ "${final_ABI}" == "1" ]]; then
1570 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1924 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" 1925 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1572 fi 1926 fi
1573 PYTHON_ABI="$(PYTHON -f --ABI)" 1927 PYTHON_ABI="$(PYTHON -f --ABI)"
1574 elif [[ -z "${PYTHON_ABI}" ]]; then 1928 else
1929 if _python_package_supporting_installation_for_multiple_python_abis; then
1930 if ! _python_abi-specific_local_scope; then
1931 die "${FUNCNAME}() should be used in ABI-specific local scope"
1932 fi
1933 else
1575 PYTHON_ABI="$(PYTHON --ABI)" 1934 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1935 fi
1576 fi 1936 fi
1577 1937
1578 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1938 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1579 if [[ "${linker_option}" == "1" ]]; then 1939 if [[ "${linker_option}" == "1" ]]; then
1580 echo "-lpython${PYTHON_ABI}" 1940 echo "-lpython${PYTHON_ABI}"
1581 else 1941 else
1582 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1942 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1583 fi 1943 fi
1584 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1944 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1585 die "${FUNCNAME}(): Jython does not have shared library" 1945 die "${FUNCNAME}(): Jython does not have shared library"
1586 fi 1946 fi
1587} 1947}
1592# Print Python version. 1952# Print Python version.
1593# --full, --major, --minor and --micro options cannot be specified simultaneously. 1953# --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. 1954# 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. 1955# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1596python_get_version() { 1956python_get_version() {
1957 _python_check_python_pkg_setup_execution
1958
1597 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1959 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1598 1960
1599 while (($#)); do 1961 while (($#)); do
1600 case "$1" in 1962 case "$1" in
1601 -f|--final-ABI) 1963 -f|--final-ABI)
1651 if ! _python_package_supporting_installation_for_multiple_python_abis; then 2013 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" 2014 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1653 fi 2015 fi
1654 "$(PYTHON -f)" -c "${python_command}" 2016 "$(PYTHON -f)" -c "${python_command}"
1655 else 2017 else
2018 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
2019 die "${FUNCNAME}() should be used in ABI-specific local scope"
2020 fi
1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 2021 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1657 fi 2022 fi
1658} 2023}
1659 2024
1660# ================================================================================================ 2025# ================================================================================================
1682# @DESCRIPTION: 2047# @DESCRIPTION:
1683# Execute nosetests for all enabled Python ABIs. 2048# Execute nosetests for all enabled Python ABIs.
1684# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 2049# 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. 2050# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1686python_execute_nosetests() { 2051python_execute_nosetests() {
2052 _python_check_python_pkg_setup_execution
1687 _python_set_color_variables 2053 _python_set_color_variables
1688 2054
1689 local PYTHONPATH_template= separate_build_dirs= 2055 local PYTHONPATH_template= separate_build_dirs=
1690 2056
1691 while (($#)); do 2057 while (($#)); do
1710 esac 2076 esac
1711 shift 2077 shift
1712 done 2078 done
1713 2079
1714 python_test_function() { 2080 python_test_function() {
1715 local evaluated_PYTHONPATH= 2081 local evaluated_PYTHONPATH
1716 2082
1717 if [[ -n "${PYTHONPATH_template}" ]]; then
1718 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2083 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1719 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1720 unset evaluated_PYTHONPATH
1721 fi
1722 fi
1723 2084
1724 _python_test_hook pre 2085 _python_test_hook pre
1725 2086
1726 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2087 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1727 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2088 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1750# @DESCRIPTION: 2111# @DESCRIPTION:
1751# Execute py.test for all enabled Python ABIs. 2112# Execute py.test for all enabled Python ABIs.
1752# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 2113# 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. 2114# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1754python_execute_py.test() { 2115python_execute_py.test() {
2116 _python_check_python_pkg_setup_execution
1755 _python_set_color_variables 2117 _python_set_color_variables
1756 2118
1757 local PYTHONPATH_template= separate_build_dirs= 2119 local PYTHONPATH_template= separate_build_dirs=
1758 2120
1759 while (($#)); do 2121 while (($#)); do
1778 esac 2140 esac
1779 shift 2141 shift
1780 done 2142 done
1781 2143
1782 python_test_function() { 2144 python_test_function() {
1783 local evaluated_PYTHONPATH= 2145 local evaluated_PYTHONPATH
1784 2146
1785 if [[ -n "${PYTHONPATH_template}" ]]; then
1786 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2147 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1787 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1788 unset evaluated_PYTHONPATH
1789 fi
1790 fi
1791 2148
1792 _python_test_hook pre 2149 _python_test_hook pre
1793 2150
1794 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2151 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1795 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 2152 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1818# @DESCRIPTION: 2175# @DESCRIPTION:
1819# Execute trial for all enabled Python ABIs. 2176# Execute trial for all enabled Python ABIs.
1820# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2177# 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. 2178# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1822python_execute_trial() { 2179python_execute_trial() {
2180 _python_check_python_pkg_setup_execution
1823 _python_set_color_variables 2181 _python_set_color_variables
1824 2182
1825 local PYTHONPATH_template= separate_build_dirs= 2183 local PYTHONPATH_template= separate_build_dirs=
1826 2184
1827 while (($#)); do 2185 while (($#)); do
1846 esac 2204 esac
1847 shift 2205 shift
1848 done 2206 done
1849 2207
1850 python_test_function() { 2208 python_test_function() {
1851 local evaluated_PYTHONPATH= 2209 local evaluated_PYTHONPATH
1852 2210
1853 if [[ -n "${PYTHONPATH_template}" ]]; then
1854 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2211 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
1855 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1856 unset evaluated_PYTHONPATH
1857 fi
1858 fi
1859 2212
1860 _python_test_hook pre 2213 _python_test_hook pre
1861 2214
1862 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2215 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1863 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2216 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1888# @FUNCTION: python_enable_pyc 2241# @FUNCTION: python_enable_pyc
1889# @DESCRIPTION: 2242# @DESCRIPTION:
1890# Tell Python to automatically recompile modules to .pyc/.pyo if the 2243# Tell Python to automatically recompile modules to .pyc/.pyo if the
1891# timestamps/version stamps have changed. 2244# timestamps/version stamps have changed.
1892python_enable_pyc() { 2245python_enable_pyc() {
2246 _python_check_python_pkg_setup_execution
2247
2248 if [[ "$#" -ne 0 ]]; then
2249 die "${FUNCNAME}() does not accept arguments"
2250 fi
2251
1893 unset PYTHONDONTWRITEBYTECODE 2252 unset PYTHONDONTWRITEBYTECODE
1894} 2253}
1895 2254
1896# @FUNCTION: python_disable_pyc 2255# @FUNCTION: python_disable_pyc
1897# @DESCRIPTION: 2256# @DESCRIPTION:
1898# Tell Python not to automatically recompile modules to .pyc/.pyo 2257# Tell Python not to automatically recompile modules to .pyc/.pyo
1899# even if the timestamps/version stamps do not match. This is done 2258# even if the timestamps/version stamps do not match. This is done
1900# to protect sandbox. 2259# to protect sandbox.
1901python_disable_pyc() { 2260python_disable_pyc() {
2261 _python_check_python_pkg_setup_execution
2262
2263 if [[ "$#" -ne 0 ]]; then
2264 die "${FUNCNAME}() does not accept arguments"
2265 fi
2266
1902 export PYTHONDONTWRITEBYTECODE="1" 2267 export PYTHONDONTWRITEBYTECODE="1"
1903} 2268}
1904 2269
1905_python_clean_compiled_modules() { 2270_python_clean_compiled_modules() {
1906 _python_initialize_prefix_variables 2271 _python_initialize_prefix_variables
1907 _python_set_color_variables 2272 _python_set_color_variables
1908 2273
1909 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2274 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
1910 2275
1911 local base_module_name compiled_file compiled_files=() dir path py_file root 2276 local base_module_name compiled_file compiled_files=() dir path py_file root
1912 2277
1913 # Strip trailing slash from EROOT. 2278 # Strip trailing slash from EROOT.
1914 root="${EROOT%/}" 2279 root="${EROOT%/}"
1921 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) 2286 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1922 2287
1923 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then 2288 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1924 # Delete empty child directories. 2289 # Delete empty child directories.
1925 find "${path}" -type d | sort -r | while read -r dir; do 2290 find "${path}" -type d | sort -r | while read -r dir; do
1926 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" 2291 if rmdir "${dir}" 2> /dev/null; then
2292 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2293 fi
1927 done 2294 done
1928 fi 2295 fi
1929 elif [[ "${path}" == *.py ]]; then 2296 elif [[ "${path}" == *.py ]]; then
1930 base_module_name="${path##*/}" 2297 base_module_name="${path##*/}"
1931 base_module_name="${base_module_name%.py}" 2298 base_module_name="${base_module_name%.py}"
1977 fi 2344 fi
1978 2345
1979 # Delete empty parent directories. 2346 # Delete empty parent directories.
1980 dir="${compiled_file%/*}" 2347 dir="${compiled_file%/*}"
1981 while [[ "${dir}" != "${root}" ]]; do 2348 while [[ "${dir}" != "${root}" ]]; do
1982 if rmdir "${compiled_file%/*}" 2> /dev/null; then 2349 if rmdir "${dir}" 2> /dev/null; then
1983 echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}" 2350 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1984 else 2351 else
1985 break 2352 break
1986 fi 2353 fi
1987 dir="${dir%/*}" 2354 dir="${dir%/*}"
1988 done 2355 done
1989 done 2356 done
1990 done 2357 done
1991} 2358}
1992 2359
1993# @FUNCTION: python_mod_optimize 2360# @FUNCTION: python_mod_optimize
1994# @USAGE: [options] [directory|file] 2361# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
1995# @DESCRIPTION: 2362# @DESCRIPTION:
1996# If no arguments supplied, it will recompile not recursively all modules 2363# Byte-compile specified Python modules.
1997# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1998#
1999# If supplied with arguments, it will recompile all modules recursively
2000# in the supplied directory.
2001#
2002# Options passed to this function are passed to compileall.py. 2364# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2003# 2365#
2004# This function can be used only in pkg_postinst() phase. 2366# This function can be used only in pkg_postinst() phase.
2005python_mod_optimize() { 2367python_mod_optimize() {
2368 _python_check_python_pkg_setup_execution
2006 _python_initialize_prefix_variables 2369 _python_initialize_prefix_variables
2007 2370
2008 # Check if phase is pkg_postinst(). 2371 # Check if phase is pkg_postinst().
2009 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2372 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2010 2373
2011 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2374 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2012 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2375 # 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=() 2376 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
2014 2377
2015 if _python_package_supporting_installation_for_multiple_python_abis; then 2378 if _python_package_supporting_installation_for_multiple_python_abis; then
2016 if [[ -z "${PYTHON_ABIS}" ]]; then 2379 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2017 die "${FUNCNAME}(): Environment not initialized" 2380 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2018 fi 2381 fi
2019 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2382 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2020 else 2383 else
2384 if has "${EAPI:-0}" 0 1 2 3; then
2021 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}" 2385 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2386 else
2387 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2388 fi
2022 fi 2389 fi
2023 2390
2024 # Strip trailing slash from EROOT. 2391 # Strip trailing slash from EROOT.
2025 root="${EROOT%/}" 2392 root="${EROOT%/}"
2026 2393
2027 while (($#)); do 2394 while (($#)); do
2028 case "$1" in 2395 case "$1" in
2396 --allow-evaluated-non-sitedir-paths)
2397 allow_evaluated_non_sitedir_paths="1"
2398 ;;
2029 -l|-f|-q) 2399 -l|-f|-q)
2030 options+=("$1") 2400 options+=("$1")
2031 ;; 2401 ;;
2032 -d|-x) 2402 -d|-x)
2033 options+=("$1" "$2") 2403 options+=("$1" "$2")
2034 shift 2404 shift
2035 ;; 2405 ;;
2406 --)
2407 shift
2408 break
2409 ;;
2036 -*) 2410 -*)
2037 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2411 die "${FUNCNAME}(): Unrecognized option '$1'"
2038 ;; 2412 ;;
2039 *) 2413 *)
2040 break 2414 break
2041 ;; 2415 ;;
2042 esac 2416 esac
2043 shift 2417 shift
2044 done 2418 done
2045 2419
2420 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2421 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2422 fi
2423
2046 if [[ "$#" -eq 0 ]]; then 2424 if [[ "$#" -eq 0 ]]; then
2047 _python_set_color_variables 2425 die "${FUNCNAME}(): Missing files or directories"
2048
2049 echo
2050 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2051 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2052 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2053 echo
2054
2055 einfo &> /dev/null
2056 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2057 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2058 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2059 einfo &> /dev/null
2060 fi 2426 fi
2061 2427
2062 while (($#)); do 2428 while (($#)); do
2429 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2430 die "${FUNCNAME}(): Invalid argument '$1'"
2063 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2431 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" 2432 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2065 elif [[ "$1" =~ ^/ ]]; then 2433 elif [[ "$1" =~ ^/ ]]; then
2066 if _python_package_supporting_installation_for_multiple_python_abis; then 2434 if _python_package_supporting_installation_for_multiple_python_abis; then
2435 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2067 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2436 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2068 fi 2437 fi
2069 if [[ -d "${root}$1" ]]; then 2438 if [[ "$1" != *\$* ]]; then
2070 other_dirs+=("${root}$1") 2439 die "${FUNCNAME}(): '$1' has invalid syntax"
2071 elif [[ -f "${root}$1" ]]; then 2440 fi
2072 other_files+=("${root}$1") 2441 if [[ "$1" == *.py ]]; then
2073 elif [[ -e "${root}$1" ]]; then 2442 evaluated_files+=("$1")
2074 eerror "'${root}$1' is not a file or a directory!" 2443 else
2444 evaluated_dirs+=("$1")
2445 fi
2075 else 2446 else
2447 if [[ -d "${root}$1" ]]; then
2448 other_dirs+=("${root}$1")
2449 elif [[ -f "${root}$1" ]]; then
2450 other_files+=("${root}$1")
2451 elif [[ -e "${root}$1" ]]; then
2452 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2453 else
2076 eerror "'${root}$1' does not exist!" 2454 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2455 fi
2077 fi 2456 fi
2078 else 2457 else
2079 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2458 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2080 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 2459 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2081 site_packages_dirs+=("$1") 2460 site_packages_dirs+=("$1")
2082 break 2461 break
2083 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then 2462 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2084 site_packages_files+=("$1") 2463 site_packages_files+=("$1")
2085 break 2464 break
2086 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then 2465 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2087 eerror "'$1' is not a file or a directory!" 2466 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2088 else 2467 else
2089 eerror "'$1' does not exist!" 2468 eerror "${FUNCNAME}(): '$1' does not exist"
2090 fi 2469 fi
2091 done 2470 done
2092 fi 2471 fi
2093 shift 2472 shift
2094 done 2473 done
2095 2474
2096 # Set additional options. 2475 # Set additional options.
2097 options+=("-q") 2476 options+=("-q")
2098 2477
2099 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2478 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2100 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2479 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
2101 return_code="0" 2480 return_code="0"
2102 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2481 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
2103 if ((${#site_packages_dirs[@]})); then 2482 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
2104 for dir in "${site_packages_dirs[@]}"; do 2483 for dir in "${site_packages_dirs[@]}"; do
2105 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2484 dirs+=("${root}$(python_get_sitedir)/${dir}")
2106 done 2485 done
2486 for dir in "${evaluated_dirs[@]}"; do
2487 eval "dirs+=(\"\${root}${dir}\")"
2488 done
2107 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2489 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
2108 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2490 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2109 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2491 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2110 fi 2492 fi
2111 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" 2493 _python_clean_compiled_modules "${dirs[@]}"
2112 fi 2494 fi
2113 if ((${#site_packages_files[@]})); then 2495 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2114 for file in "${site_packages_files[@]}"; do 2496 for file in "${site_packages_files[@]}"; do
2115 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2497 files+=("${root}$(python_get_sitedir)/${file}")
2116 done 2498 done
2499 for file in "${evaluated_files[@]}"; do
2500 eval "files+=(\"\${root}${file}\")"
2501 done
2117 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2502 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
2118 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2503 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2119 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2504 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2120 fi 2505 fi
2121 _python_clean_compiled_modules "${site_packages_absolute_files[@]}" 2506 _python_clean_compiled_modules "${files[@]}"
2122 fi 2507 fi
2123 eend "${return_code}" 2508 eend "${return_code}"
2124 fi 2509 fi
2125 unset site_packages_absolute_dirs site_packages_absolute_files 2510 unset dirs files
2126 done 2511 done
2127 2512
2128 if _python_package_supporting_installation_for_multiple_python_abis; then 2513 if _python_package_supporting_installation_for_multiple_python_abis; then
2129 # Restore previous value of PYTHON_ABI. 2514 # Restore previous value of PYTHON_ABI.
2130 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2515 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2147 if ((${#other_files[@]})); then 2532 if ((${#other_files[@]})); then
2148 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2533 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2149 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2534 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
2150 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2535 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2151 fi 2536 fi
2152 _python_clean_compiled_modules "${other_dirs[@]}" 2537 _python_clean_compiled_modules "${other_files[@]}"
2153 fi 2538 fi
2154 eend "${return_code}" 2539 eend "${return_code}"
2155 fi 2540 fi
2156 else 2541 else
2157 # Deprecated part of python_mod_optimize() 2542 # Deprecated part of python_mod_optimize()
2543 # ewarn
2544 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2545 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2546 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2547 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2548 # ewarn
2158 2549
2159 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2550 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2160 2551
2161 # strip trailing slash 2552 # strip trailing slash
2162 myroot="${EROOT%/}" 2553 myroot="${EROOT%/}"
2169 ;; 2560 ;;
2170 -d|-x) 2561 -d|-x)
2171 myopts+=("$1" "$2") 2562 myopts+=("$1" "$2")
2172 shift 2563 shift
2173 ;; 2564 ;;
2565 --)
2566 shift
2567 break
2568 ;;
2174 -*) 2569 -*)
2175 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2570 die "${FUNCNAME}(): Unrecognized option '$1'"
2176 ;; 2571 ;;
2177 *) 2572 *)
2178 break 2573 break
2179 ;; 2574 ;;
2180 esac 2575 esac
2181 shift 2576 shift
2182 done 2577 done
2183 2578
2184 if [[ "$#" -eq 0 ]]; then 2579 if [[ "$#" -eq 0 ]]; then
2185 _python_set_color_variables 2580 die "${FUNCNAME}(): Missing files or directories"
2186
2187 echo
2188 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2189 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2190 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2191 echo
2192
2193 einfo &> /dev/null
2194 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2195 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2196 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2197 einfo &> /dev/null
2198 fi 2581 fi
2199 2582
2200 while (($#)); do 2583 while (($#)); do
2584 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2585 die "${FUNCNAME}(): Invalid argument '$1'"
2201 if [[ -d "${myroot}/${1#/}" ]]; then 2586 elif [[ -d "${myroot}/${1#/}" ]]; then
2202 mydirs+=("${myroot}/${1#/}") 2587 mydirs+=("${myroot}/${1#/}")
2203 elif [[ -f "${myroot}/${1#/}" ]]; then 2588 elif [[ -f "${myroot}/${1#/}" ]]; then
2204 # Files are passed to python_mod_compile which is EROOT-aware 2589 myfiles+=("${myroot}/${1#/}")
2205 myfiles+=("$1")
2206 elif [[ -e "${myroot}/${1#/}" ]]; then 2590 elif [[ -e "${myroot}/${1#/}" ]]; then
2207 eerror "${myroot}/${1#/} is not a file or directory!" 2591 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2208 else 2592 else
2209 eerror "${myroot}/${1#/} does not exist!" 2593 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2210 fi 2594 fi
2211 shift 2595 shift
2212 done 2596 done
2213 2597
2214 # set additional opts 2598 # set additional opts
2222 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2606 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2223 _python_clean_compiled_modules "${mydirs[@]}" 2607 _python_clean_compiled_modules "${mydirs[@]}"
2224 fi 2608 fi
2225 2609
2226 if ((${#myfiles[@]})); then 2610 if ((${#myfiles[@]})); then
2611 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2612 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2227 python_mod_compile "${myfiles[@]}" 2613 _python_clean_compiled_modules "${myfiles[@]}"
2228 fi 2614 fi
2229 2615
2230 eend "${return_code}" 2616 eend "${return_code}"
2231 fi 2617 fi
2232} 2618}
2233 2619
2234# @FUNCTION: python_mod_cleanup 2620# @FUNCTION: python_mod_cleanup
2235# @USAGE: [directory|file] 2621# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2236# @DESCRIPTION: 2622# @DESCRIPTION:
2237# Run with optional arguments, where arguments are Python modules. If none given, 2623# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2238# it will look in /usr/lib/python[0-9].[0-9].
2239#
2240# It will recursively scan all compiled Python modules in the directories and
2241# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2242# If they are, then it will remove their corresponding .pyc and .pyo files.
2243# 2624#
2244# This function can be used only in pkg_postrm() phase. 2625# This function can be used only in pkg_postrm() phase.
2245python_mod_cleanup() { 2626python_mod_cleanup() {
2627 _python_check_python_pkg_setup_execution
2246 _python_initialize_prefix_variables 2628 _python_initialize_prefix_variables
2247 2629
2248 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2630 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2249 2631
2250 # Check if phase is pkg_postrm(). 2632 # Check if phase is pkg_postrm().
2251 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2633 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2252 2634
2253 if _python_package_supporting_installation_for_multiple_python_abis; then 2635 if _python_package_supporting_installation_for_multiple_python_abis; then
2254 if [[ -z "${PYTHON_ABIS}" ]]; then 2636 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2255 die "${FUNCNAME}(): Environment not initialized" 2637 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2256 fi 2638 fi
2257 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 2639 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2258 else 2640 else
2641 if has "${EAPI:-0}" 0 1 2 3; then
2259 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}" 2642 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2643 else
2644 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2645 fi
2260 fi 2646 fi
2261 2647
2262 # Strip trailing slash from EROOT. 2648 # Strip trailing slash from EROOT.
2263 root="${EROOT%/}" 2649 root="${EROOT%/}"
2264 2650
2651 while (($#)); do
2652 case "$1" in
2653 --allow-evaluated-non-sitedir-paths)
2654 allow_evaluated_non_sitedir_paths="1"
2655 ;;
2656 --)
2657 shift
2658 break
2659 ;;
2660 -*)
2661 die "${FUNCNAME}(): Unrecognized option '$1'"
2662 ;;
2663 *)
2664 break
2665 ;;
2666 esac
2667 shift
2668 done
2669
2670 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2671 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2672 fi
2673
2265 if [[ "$#" -gt 0 ]]; then 2674 if [[ "$#" -eq 0 ]]; then
2266 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2675 die "${FUNCNAME}(): Missing files or directories"
2676 fi
2677
2678 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2267 while (($#)); do 2679 while (($#)); do
2680 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2681 die "${FUNCNAME}(): Invalid argument '$1'"
2268 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2682 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" 2683 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2270 elif [[ "$1" =~ ^/ ]]; then 2684 elif [[ "$1" =~ ^/ ]]; then
2271 if _python_package_supporting_installation_for_multiple_python_abis; then 2685 if _python_package_supporting_installation_for_multiple_python_abis; then
2686 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2272 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 2687 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2273 fi 2688 fi
2689 if [[ "$1" != *\$* ]]; then
2690 die "${FUNCNAME}(): '$1' has invalid syntax"
2691 fi
2692 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2693 eval "search_paths+=(\"\${root}$1\")"
2694 done
2695 else
2274 search_paths+=("${root}$1") 2696 search_paths+=("${root}$1")
2697 fi
2275 else 2698 else
2276 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2699 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2277 search_paths+=("${root}$(python_get_sitedir)/$1") 2700 search_paths+=("${root}$(python_get_sitedir)/$1")
2278 done
2279 fi
2280 shift
2281 done
2282 else
2283 # Deprecated part of python_mod_cleanup()
2284
2285 search_paths=("${@#/}")
2286 search_paths=("${search_paths[@]/#/${root}/}")
2287 fi
2288 else
2289 _python_set_color_variables
2290
2291 echo
2292 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2293 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2294 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2295 echo
2296
2297 einfo &> /dev/null
2298 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2299 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2300 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2301 einfo &> /dev/null
2302
2303 for dir in "${root}"/usr/lib*; do
2304 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2305 for sitedir in "${dir}"/python*/site-packages; do
2306 if [[ -d "${sitedir}" ]]; then
2307 search_paths+=("${sitedir}")
2308 fi
2309 done 2701 done
2310 fi 2702 fi
2703 shift
2311 done 2704 done
2312 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2705 else
2313 if [[ -d "${sitedir}" ]]; then 2706 # Deprecated part of python_mod_cleanup()
2707 # ewarn
2708 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2709 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2710 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2711 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2712 # ewarn
2713
2314 search_paths+=("${sitedir}") 2714 search_paths=("${@#/}")
2315 fi 2715 search_paths=("${search_paths[@]/#/${root}/}")
2316 done
2317 fi 2716 fi
2318 2717
2319 _python_clean_compiled_modules "${search_paths[@]}" 2718 _python_clean_compiled_modules "${search_paths[@]}"
2320} 2719}
2321 2720
2322# ================================================================================================ 2721# ================================================================================================
2323# ===================================== DEPRECATED FUNCTIONS ===================================== 2722# ===================================== DEPRECATED FUNCTIONS =====================================
2324# ================================================================================================ 2723# ================================================================================================
2325 2724
2326# @FUNCTION: python_version 2725# 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() { 2726python_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 2727 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 2728 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} 2729}
2364 2730
2365# @FUNCTION: python_mod_exists 2731# 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() { 2732python_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}()." 2733 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2380 die "${FUNCNAME}() cannot be used in this EAPI" 2734 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} 2735}
2402 2736
2403# @FUNCTION: python_tkinter_exists 2737# 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() { 2738python_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}()." 2739 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2410 die "${FUNCNAME}() cannot be used in this EAPI" 2740 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} 2741}
2440 2742
2441# @FUNCTION: python_mod_compile 2743# Scheduled for deletion on 2011-04-01.
2442# @USAGE: <file> [more files ...]
2443# @DESCRIPTION:
2444# Given filenames, it will pre-compile the module's .pyc and .pyo.
2445# This function can be used only in pkg_postinst() phase.
2446#
2447# Example:
2448# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2449#
2450python_mod_compile() { 2744python_mod_compile() {
2451 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2452 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2745 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2453 die "${FUNCNAME}() cannot be used in this EAPI" 2746 die "${FUNCNAME}() is banned"
2454 fi
2455
2456 _python_initialize_prefix_variables
2457 _python_set_color_variables
2458
2459 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2460 echo
2461 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2462 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2463 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2464 echo
2465
2466 einfo &> /dev/null
2467 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2468 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2469 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2470 einfo &> /dev/null
2471 fi
2472
2473 local f myroot myfiles=()
2474
2475 # Check if phase is pkg_postinst()
2476 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2477
2478 # strip trailing slash
2479 myroot="${EROOT%/}"
2480
2481 # respect EROOT
2482 for f in "$@"; do
2483 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2484 done
2485
2486 PYTHON_ABI="$(PYTHON --ABI)"
2487
2488 if ((${#myfiles[@]})); then
2489 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2490 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2491 _python_clean_compiled_modules "${myfiles[@]}"
2492 else
2493 ewarn "No files to compile!"
2494 fi
2495} 2747}

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

  ViewVC Help
Powered by ViewVC 1.1.20