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

Diff of /eclass/python.eclass

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

Revision 1.95 Revision 1.101
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.101 2010/07/17 23:02:14 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" 159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 160elif [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 161 _parse_PYTHON_DEPEND
162elif [[ -n "${NEED_PYTHON}" ]]; then 162elif [[ -n "${NEED_PYTHON}" ]]; then
163 if ! has "${EAPI:-0}" 0 1 2; then 163 if ! has "${EAPI:-0}" 0 1 2; then
164 eerror "Use PYTHON_DEPEND instead of NEED_PYTHON." 164 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
165 die "NEED_PYTHON cannot be used in this EAPI" 165 die "NEED_PYTHON variable cannot be used in this EAPI"
166 fi 166 fi
167
168 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
169 _RED=$'\e[1;31m'
170 _NORMAL=$'\e[0m'
171 else
172 _RED=
173 _NORMAL=
174 fi
175
176 echo
177 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01.${_NORMAL}"
178 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_DEPEND variable instead of NEED_PYTHON variable.${_NORMAL}"
179 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
180 echo
181
182 unset _BOLD _NORMAL
183
167 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}") 184 _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}")
168 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}" 185 DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}"
169 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}" 186 RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}"
170else 187else
171 _PYTHON_ATOMS=("dev-lang/python") 188 _PYTHON_ATOMS=("dev-lang/python")
182# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT 199# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
183# @DESCRIPTION: 200# @DESCRIPTION:
184# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or 201# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
185# PYTHON_USE_WITH_OR atoms conditional under a USE flag. 202# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
186 203
187# @FUNCTION: python_pkg_setup
188# @DESCRIPTION:
189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
190# are respected. Only exported if one of those variables is set.
191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 204if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
192 python_pkg_setup() {
193 # Check if phase is pkg_setup().
194 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
195
196 python_pkg_setup_fail() {
197 eerror "${1}"
198 die "${1}"
199 }
200
201 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
202 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
203 use ${PYTHON_USE_WITH_OPT#!} && return
204 else
205 use !${PYTHON_USE_WITH_OPT} && return
206 fi
207 fi
208
209 python_pkg_setup_check_USE_flags() {
210 local pyatom use
211 pyatom="$(python_get_implementational_package)"
212
213 for use in ${PYTHON_USE_WITH}; do
214 if ! has_version "${pyatom}[${use}]"; then
215 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
216 fi
217 done
218
219 for use in ${PYTHON_USE_WITH_OR}; do
220 if has_version "${pyatom}[${use}]"; then
221 return
222 fi
223 done
224
225 if [[ ${PYTHON_USE_WITH_OR} ]]; then
226 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
227 fi
228 }
229
230 if _python_package_supporting_installation_for_multiple_python_abis; then
231 python_execute_function -q python_pkg_setup_check_USE_flags
232 else
233 python_pkg_setup_check_USE_flags
234 fi
235
236 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
237 }
238
239 EXPORT_FUNCTIONS pkg_setup
240
241 _PYTHON_USE_WITH_ATOMS_ARRAY=() 205 _PYTHON_USE_WITH_ATOMS_ARRAY=()
242 if [[ -n "${PYTHON_USE_WITH}" ]]; then 206 if [[ -n "${PYTHON_USE_WITH}" ]]; then
243 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 207 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
244 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]") 208 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
245 done 209 done
246 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 210 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
247 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 211 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
248 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 212 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
249 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") 213 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
265fi 229fi
266 230
267unset _PYTHON_ATOMS 231unset _PYTHON_ATOMS
268 232
269# ================================================================================================ 233# ================================================================================================
234# =================================== MISCELLANEOUS FUNCTIONS ====================================
235# ================================================================================================
236
237_python_implementation() {
238 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
239 return 0
240 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
241 return 0
242 else
243 return 1
244 fi
245}
246
247_python_package_supporting_installation_for_multiple_python_abis() {
248 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
249 die "${FUNCNAME}() cannot be used in global scope"
250 fi
251
252 if has "${EAPI:-0}" 0 1 2 3 4; then
253 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
254 return 0
255 else
256 return 1
257 fi
258 else
259 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
260 fi
261}
262
263_python_abi-specific_local_scope() {
264 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
265}
266
267_python_initialize_prefix_variables() {
268 if has "${EAPI:-0}" 0 1 2; then
269 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
270 EROOT="${ROOT%/}${EPREFIX}/"
271 fi
272 if [[ -n "${D}" && -z "${ED}" ]]; then
273 ED="${D%/}${EPREFIX}/"
274 fi
275 fi
276}
277
278unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
279
280_python_initial_sanity_checks() {
281 if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
282 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
283 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
284 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
285 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
286 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
287 fi
288 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
289 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
290 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
291 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
292 fi
293 fi
294}
295
296_python_final_sanity_checks() {
297 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
298 local PYTHON_ABI="${PYTHON_ABI}"
299 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
300 # Ensure that appropriate version of Python is installed.
301 if ! has_version "$(python_get_implementational_package)"; then
302 die "$(python_get_implementational_package) is not installed"
303 fi
304
305 # Ensure that EPYTHON variable is respected.
306 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
307 eerror "Path to 'python': '$(type -p python)'"
308 eerror "ABI: '${ABI}'"
309 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
310 eerror "EPYTHON: '$(PYTHON)'"
311 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
312 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
313 die "'python' does not respect EPYTHON variable"
314 fi
315 done
316 fi
317 PYTHON_SANITY_CHECKS_EXECUTED="1"
318}
319
320_python_set_color_variables() {
321 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
322 _BOLD=$'\e[1m'
323 _RED=$'\e[1;31m'
324 _GREEN=$'\e[1;32m'
325 _BLUE=$'\e[1;34m'
326 _CYAN=$'\e[1;36m'
327 _NORMAL=$'\e[0m'
328 else
329 _BOLD=
330 _RED=
331 _GREEN=
332 _BLUE=
333 _CYAN=
334 _NORMAL=
335 fi
336}
337
338unset PYTHON_PKG_SETUP_EXECUTED
339
340_python_check_python_pkg_setup_execution() {
341 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
342
343 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
344 die "python_pkg_setup() not called"
345 fi
346}
347
348# @FUNCTION: python_pkg_setup
349# @DESCRIPTION:
350# Perform sanity checks and initialize environment.
351#
352# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
353# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
354#
355# This function can be used only in pkg_setup() phase.
356python_pkg_setup() {
357 # Check if phase is pkg_setup().
358 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
359
360 if [[ "$#" -ne 0 ]]; then
361 die "${FUNCNAME}() does not accept arguments"
362 fi
363
364 if _python_package_supporting_installation_for_multiple_python_abis; then
365 _python_calculate_PYTHON_ABIS
366 export EPYTHON="$(PYTHON -f)"
367 else
368 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
369 fi
370
371 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
372 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
373 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
374 use ${PYTHON_USE_WITH_OPT#!} && return
375 else
376 use !${PYTHON_USE_WITH_OPT} && return
377 fi
378 fi
379
380 python_pkg_setup_check_USE_flags() {
381 local python_atom USE_flag
382 python_atom="$(python_get_implementational_package)"
383
384 for USE_flag in ${PYTHON_USE_WITH}; do
385 if ! has_version "${python_atom}[${USE_flag}]"; then
386 eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
387 die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
388 fi
389 done
390
391 for USE_flag in ${PYTHON_USE_WITH_OR}; do
392 if has_version "${python_atom}[${USE_flag}]"; then
393 return
394 fi
395 done
396
397 if [[ ${PYTHON_USE_WITH_OR} ]]; then
398 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
399 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
400 fi
401 }
402
403 if _python_package_supporting_installation_for_multiple_python_abis; then
404 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
405 else
406 python_pkg_setup_check_USE_flags
407 fi
408
409 unset -f python_pkg_setup_check_USE_flags
410 fi
411
412 PYTHON_PKG_SETUP_EXECUTED="1"
413}
414
415if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
416 EXPORT_FUNCTIONS pkg_setup
417fi
418
419# @FUNCTION: python_convert_shebangs
420# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
421# @DESCRIPTION:
422# Convert shebangs in specified files. Directories can be specified only with --recursive option.
423python_convert_shebangs() {
424 _python_check_python_pkg_setup_execution
425
426 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
427
428 while (($#)); do
429 case "$1" in
430 -r|--recursive)
431 recursive="1"
432 ;;
433 -q|--quiet)
434 quiet="1"
435 ;;
436 -x|--only-executables)
437 only_executables="1"
438 ;;
439 --)
440 shift
441 break
442 ;;
443 -*)
444 die "${FUNCNAME}(): Unrecognized option '$1'"
445 ;;
446 *)
447 break
448 ;;
449 esac
450 shift
451 done
452
453 if [[ "$#" -eq 0 ]]; then
454 die "${FUNCNAME}(): Missing Python version and files or directories"
455 elif [[ "$#" -eq 1 ]]; then
456 die "${FUNCNAME}(): Missing files or directories"
457 fi
458
459 python_version="$1"
460 shift
461
462 for argument in "$@"; do
463 if [[ ! -e "${argument}" ]]; then
464 die "${FUNCNAME}(): '${argument}' does not exist"
465 elif [[ -f "${argument}" ]]; then
466 files+=("${argument}")
467 elif [[ -d "${argument}" ]]; then
468 if [[ "${recursive}" == "1" ]]; then
469 while read -d $'\0' -r file; do
470 files+=("${file}")
471 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
472 else
473 die "${FUNCNAME}(): '${argument}' is not a regular file"
474 fi
475 else
476 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
477 fi
478 done
479
480 for file in "${files[@]}"; do
481 file="${file#./}"
482 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
483
484 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
485 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
486
487 if [[ "${quiet}" == "0" ]]; then
488 einfo "Converting shebang in '${file}'"
489 fi
490
491 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
492
493 # Delete potential whitespace after "#!".
494 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
495 fi
496 done
497}
498
499# @FUNCTION: python_clean_installation_image
500# @USAGE: [-q|--quiet]
501# @DESCRIPTION:
502# Delete needless files in installation image.
503python_clean_installation_image() {
504 _python_check_python_pkg_setup_execution
505 _python_initialize_prefix_variables
506
507 local file files=() quiet="0"
508
509 # Check if phase is src_install().
510 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
511
512 while (($#)); do
513 case "$1" in
514 -q|--quiet)
515 quiet="1"
516 ;;
517 -*)
518 die "${FUNCNAME}(): Unrecognized option '$1'"
519 ;;
520 *)
521 die "${FUNCNAME}(): Invalid usage"
522 ;;
523 esac
524 shift
525 done
526
527 while read -d $'\0' -r file; do
528 files+=("${file}")
529 done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
530
531 if [[ "${#files[@]}" -gt 0 ]]; then
532 if [[ "${quiet}" == "0" ]]; then
533 ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
534 fi
535 for file in "${files[@]}"; do
536 if [[ "${quiet}" == "0" ]]; then
537 ewarn " ${file}"
538 fi
539 rm -f "${file}"
540
541 # Delete empty __pycache__ directories.
542 if [[ "${file%/*}" == *"/__pycache__" ]]; then
543 rmdir "${file%/*}" 2> /dev/null
544 fi
545 done
546 fi
547
548 python_clean_sitedirs() {
549 if [[ -d "${ED}$(python_get_sitedir)" ]]; then
550 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
551 fi
552 }
553 if _python_package_supporting_installation_for_multiple_python_abis; then
554 python_execute_function -q python_clean_sitedirs
555 else
556 python_clean_sitedirs
557 fi
558
559 unset -f python_clean_sitedirs
560}
561
562# ================================================================================================
270# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ 563# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
271# ================================================================================================ 564# ================================================================================================
272 565
273# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 566# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
274# @DESCRIPTION: 567# @DESCRIPTION:
279# @DESCRIPTION: 572# @DESCRIPTION:
280# Set this to export phase functions for the following ebuild phases: 573# Set this to export phase functions for the following ebuild phases:
281# src_prepare, src_configure, src_compile, src_test, src_install. 574# src_prepare, src_configure, src_compile, src_test, src_install.
282if ! has "${EAPI:-0}" 0 1; then 575if ! has "${EAPI:-0}" 0 1; then
283 python_src_prepare() { 576 python_src_prepare() {
577 _python_check_python_pkg_setup_execution
578
284 if ! _python_package_supporting_installation_for_multiple_python_abis; then 579 if ! _python_package_supporting_installation_for_multiple_python_abis; then
285 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 580 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
286 fi 581 fi
287 582
583 if [[ "$#" -ne 0 ]]; then
584 die "${FUNCNAME}() does not accept arguments"
585 fi
586
288 python_copy_sources 587 python_copy_sources
289 } 588 }
290 589
291 for python_default_function in src_configure src_compile src_test src_install; do 590 for python_default_function in src_configure src_compile src_test src_install; do
292 eval "python_${python_default_function}() { 591 eval "python_${python_default_function}() {
592 _python_check_python_pkg_setup_execution
593
293 if ! _python_package_supporting_installation_for_multiple_python_abis; then 594 if ! _python_package_supporting_installation_for_multiple_python_abis; then
294 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 595 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
295 fi 596 fi
296 597
297 python_execute_function -d -s \"\$@\" 598 python_execute_function -d -s -- \"\$@\"
298 }" 599 }"
299 done 600 done
300 unset python_default_function 601 unset python_default_function
301 602
302 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 603 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
304 fi 605 fi
305fi 606fi
306 607
307unset PYTHON_ABIS 608unset PYTHON_ABIS
308 609
309# @FUNCTION: validate_PYTHON_ABIS 610_python_calculate_PYTHON_ABIS() {
310# @DESCRIPTION:
311# Ensure that PYTHON_ABIS variable has valid value.
312# This function usually should not be directly called in ebuilds.
313validate_PYTHON_ABIS() {
314 if ! _python_package_supporting_installation_for_multiple_python_abis; then 611 if ! _python_package_supporting_installation_for_multiple_python_abis; then
315 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 612 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
316 fi 613 fi
317 614
318 _python_initial_sanity_checks 615 _python_initial_sanity_checks
355 if [[ "${cpython_enabled}" == "0" ]]; then 652 if [[ "${cpython_enabled}" == "0" ]]; then
356 die "USE_PYTHON variable does not enable any CPython ABI" 653 die "USE_PYTHON variable does not enable any CPython ABI"
357 fi 654 fi
358 else 655 else
359 local python_version python2_version= python3_version= support_python_major_version 656 local python_version python2_version= python3_version= support_python_major_version
657
658 if ! has_version "dev-lang/python"; then
659 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
660 fi
360 661
361 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 662 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
362 663
363 if has_version "=dev-lang/python-2*"; then 664 if has_version "=dev-lang/python-2*"; then
364 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then 665 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
432 fi 733 fi
433 734
434 _python_final_sanity_checks 735 _python_final_sanity_checks
435} 736}
436 737
738_python_prepare_flags() {
739 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
740
741 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
742 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
743 for prefix in PYTHON_USER_ PYTHON_; do
744 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
745 eval "array=(\"\${${prefix}${variable}[@]}\")"
746 for element in "${array[@]}"; do
747 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
748 pattern="${element%% *}"
749 element="${element#* }"
750 operator="${element%% *}"
751 flags="${element#* }"
752 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
753 if [[ "${operator}" == "+" ]]; then
754 eval "export ${variable}+=\"\${variable:+ }${flags}\""
755 elif [[ "${operator}" == "-" ]]; then
756 flags="${flags// /$'\n'}"
757 old_value="${!variable// /$'\n'}"
758 new_value=""
759 while read old_flag; do
760 while read deleted_flag; do
761 if [[ "${old_flag}" == ${deleted_flag} ]]; then
762 continue 2
763 fi
764 done <<< "${flags}"
765 new_value+="${new_value:+ }${old_flag}"
766 done <<< "${old_value}"
767 eval "export ${variable}=\"\${new_value}\""
768 fi
769 fi
770 else
771 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
772 fi
773 done
774 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
775 die "${prefix}${variable} should be indexed array"
776 fi
777 done
778 done
779}
780
781_python_restore_flags() {
782 local variable
783
784 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
785 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
786 unset _PYTHON_SAVED_${variable}
787 done
788}
789
437# @FUNCTION: python_execute_function 790# @FUNCTION: python_execute_function
438# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] 791# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments]
439# @DESCRIPTION: 792# @DESCRIPTION:
440# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 793# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
441# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 794# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
442python_execute_function() { 795python_execute_function() {
796 _python_check_python_pkg_setup_execution
797
443 if ! _python_package_supporting_installation_for_multiple_python_abis; then 798 if ! _python_package_supporting_installation_for_multiple_python_abis; then
444 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 799 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
445 fi 800 fi
446 801
447 _python_set_color_variables 802 _python_set_color_variables
448 803
449 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= 804 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir=
450 805
451 while (($#)); do 806 while (($#)); do
452 case "$1" in 807 case "$1" in
453 --action-message) 808 --action-message)
454 action_message_template="$2" 809 action_message_template="$2"
541 fi 896 fi
542 function="python_default_function" 897 function="python_default_function"
543 fi 898 fi
544 899
545 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). 900 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
546 for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do 901 if _python_abi-specific_local_scope; then
547 if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then
548 die "${FUNCNAME}(): Invalid call stack" 902 die "${FUNCNAME}(): Invalid call stack"
549 fi 903 fi
550 done
551 904
552 if [[ "${quiet}" == "0" ]]; then 905 if [[ "${quiet}" == "0" ]]; then
553 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 906 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
554 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 907 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
555 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" 908 [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
561 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 914 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
562 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 915 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
563 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 916 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
564 fi 917 fi
565 918
566 validate_PYTHON_ABIS 919 _python_calculate_PYTHON_ABIS
567 if [[ "${final_ABI}" == "1" ]]; then 920 if [[ "${final_ABI}" == "1" ]]; then
568 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 921 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
569 else 922 else
570 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 923 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
571 fi 924 fi
572 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 925 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
926 _python_prepare_flags
927
573 if [[ "${quiet}" == "0" ]]; then 928 if [[ "${quiet}" == "0" ]]; then
574 if [[ -n "${action_message_template}" ]]; then 929 if [[ -n "${action_message_template}" ]]; then
575 action_message="$(eval echo -n "${action_message_template}")" 930 action_message="$(eval echo -n "${action_message_template}")"
576 else 931 else
577 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." 932 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
598 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 953 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
599 else 954 else
600 EPYTHON="$(PYTHON)" "${function}" "$@" 955 EPYTHON="$(PYTHON)" "${function}" "$@"
601 fi 956 fi
602 957
603 if [[ "$?" != "0" ]]; then 958 return_code="$?"
959
960 _python_restore_flags
961
962 if [[ "${return_code}" -ne 0 ]]; then
604 if [[ -n "${failure_message_template}" ]]; then 963 if [[ -n "${failure_message_template}" ]]; then
605 failure_message="$(eval echo -n "${failure_message_template}")" 964 failure_message="$(eval echo -n "${failure_message_template}")"
606 else 965 else
607 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" 966 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
608 fi 967 fi
665# @FUNCTION: python_copy_sources 1024# @FUNCTION: python_copy_sources
666# @USAGE: <directory="${S}"> [directory] 1025# @USAGE: <directory="${S}"> [directory]
667# @DESCRIPTION: 1026# @DESCRIPTION:
668# Copy unpacked sources of current package to separate build directory for each Python ABI. 1027# Copy unpacked sources of current package to separate build directory for each Python ABI.
669python_copy_sources() { 1028python_copy_sources() {
1029 _python_check_python_pkg_setup_execution
1030
670 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1031 if ! _python_package_supporting_installation_for_multiple_python_abis; then
671 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1032 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
672 fi 1033 fi
673 1034
674 local dir dirs=() PYTHON_ABI 1035 local dir dirs=() PYTHON_ABI
675 1036
676 if [[ "$#" -eq 0 ]]; then 1037 if [[ "$#" -eq 0 ]]; then
677 if [[ "${WORKDIR}" == "${S}" ]]; then 1038 if [[ "${WORKDIR}" == "${S}" ]]; then
678 die "${FUNCNAME}() cannot be used" 1039 die "${FUNCNAME}() cannot be used with current value of S variable"
679 fi 1040 fi
680 dirs=("${S%/}") 1041 dirs=("${S%/}")
681 else 1042 else
682 dirs=("$@") 1043 dirs=("$@")
683 fi 1044 fi
684 1045
685 validate_PYTHON_ABIS 1046 _python_calculate_PYTHON_ABIS
686 for PYTHON_ABI in ${PYTHON_ABIS}; do 1047 for PYTHON_ABI in ${PYTHON_ABIS}; do
687 for dir in "${dirs[@]}"; do 1048 for dir in "${dirs[@]}"; do
688 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 1049 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
689 done 1050 done
690 done 1051 done
695# @DESCRIPTION: 1056# @DESCRIPTION:
696# Generate wrapper scripts. Existing files are overwritten only with --force option. 1057# Generate wrapper scripts. Existing files are overwritten only with --force option.
697# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1058# If --respect-EPYTHON option is specified, then generated wrapper scripts will
698# respect EPYTHON variable at run time. 1059# respect EPYTHON variable at run time.
699python_generate_wrapper_scripts() { 1060python_generate_wrapper_scripts() {
1061 _python_check_python_pkg_setup_execution
1062
700 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1063 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" 1064 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
702 fi 1065 fi
703 1066
704 _python_initialize_prefix_variables 1067 _python_initialize_prefix_variables
732 1095
733 if [[ "$#" -eq 0 ]]; then 1096 if [[ "$#" -eq 0 ]]; then
734 die "${FUNCNAME}(): Missing arguments" 1097 die "${FUNCNAME}(): Missing arguments"
735 fi 1098 fi
736 1099
737 validate_PYTHON_ABIS 1100 _python_calculate_PYTHON_ABIS
738 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 1101 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
739 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1102 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
740 python2_enabled="1" 1103 python2_enabled="1"
741 fi 1104 fi
742 done 1105 done
846 fi 1209 fi
847 cat << EOF >> "${file}" 1210 cat << EOF >> "${file}"
848 1211
849wrapper_script_path = os.path.realpath(sys.argv[0]) 1212wrapper_script_path = os.path.realpath(sys.argv[0])
850target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1213target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1214os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
851os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1215os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
852os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1216os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
853if not os.path.exists(target_executable_path): 1217if not os.path.exists(target_executable_path):
854 sys.stderr.write("'%s' does not exist\n" % target_executable_path) 1218 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
855 sys.exit(1) 1219 sys.exit(1)
897 1261
898# ================================================================================================ 1262# ================================================================================================
899# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== 1263# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
900# ================================================================================================ 1264# ================================================================================================
901 1265
1266unset EPYTHON PYTHON_ABI
1267
902# @FUNCTION: python_set_active_version 1268# @FUNCTION: python_set_active_version
903# @USAGE: <CPython_ABI|2|3> 1269# @USAGE: <CPython_ABI|2|3>
904# @DESCRIPTION: 1270# @DESCRIPTION:
905# Set specified version of CPython as active version of Python. 1271# Set specified version of CPython as active version of Python.
1272#
1273# This function can be used only in pkg_setup() phase.
906python_set_active_version() { 1274python_set_active_version() {
1275 # Check if phase is pkg_setup().
1276 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
1277
907 if _python_package_supporting_installation_for_multiple_python_abis; then 1278 if _python_package_supporting_installation_for_multiple_python_abis; then
908 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1279 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
909 fi 1280 fi
910 1281
911 if [[ "$#" -ne 1 ]]; then 1282 if [[ "$#" -ne 1 ]]; then
912 die "${FUNCNAME}() requires 1 argument" 1283 die "${FUNCNAME}() requires 1 argument"
913 fi 1284 fi
914 1285
915 _python_initial_sanity_checks 1286 _python_initial_sanity_checks
916 1287
1288 if [[ -z "${PYTHON_ABI}" ]]; then
917 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 1289 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
918 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then 1290 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
919 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" 1291 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
920 fi 1292 fi
921 export EPYTHON="$(PYTHON "$1")" 1293 export EPYTHON="$(PYTHON "$1")"
922 elif [[ "$1" == "2" ]]; then 1294 elif [[ "$1" == "2" ]]; then
923 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 1295 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
924 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 1296 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
925 fi 1297 fi
926 export EPYTHON="$(PYTHON -2)" 1298 export EPYTHON="$(PYTHON -2)"
927 elif [[ "$1" == "3" ]]; then 1299 elif [[ "$1" == "3" ]]; then
928 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then 1300 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
929 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" 1301 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
930 fi 1302 fi
931 export EPYTHON="$(PYTHON -3)" 1303 export EPYTHON="$(PYTHON -3)"
932 else 1304 else
933 die "${FUNCNAME}(): Unrecognized argument '$1'" 1305 die "${FUNCNAME}(): Unrecognized argument '$1'"
934 fi 1306 fi
935 1307
936 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 1308 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
937 # so it does not need to be exported to subprocesses. 1309 # so it does not need to be exported to subprocesses.
938 PYTHON_ABI="${EPYTHON#python}" 1310 PYTHON_ABI="${EPYTHON#python}"
939 PYTHON_ABI="${PYTHON_ABI%%-*}" 1311 PYTHON_ABI="${PYTHON_ABI%%-*}"
1312 fi
940 1313
941 _python_final_sanity_checks 1314 _python_final_sanity_checks
942 1315
943 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1316 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
944 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1317 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
946 1319
947# @FUNCTION: python_need_rebuild 1320# @FUNCTION: python_need_rebuild
948# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1321# @DESCRIPTION: Mark current package for rebuilding by python-updater after
949# switching of active version of Python. 1322# switching of active version of Python.
950python_need_rebuild() { 1323python_need_rebuild() {
1324 _python_check_python_pkg_setup_execution
1325
951 if _python_package_supporting_installation_for_multiple_python_abis; then 1326 if _python_package_supporting_installation_for_multiple_python_abis; then
952 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1327 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1328 fi
1329
1330 if [[ "$#" -ne 0 ]]; then
1331 die "${FUNCNAME}() does not accept arguments"
953 fi 1332 fi
954 1333
955 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" 1334 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
956} 1335}
957 1336
991# If --ABI option is specified, then only specified Python ABI is printed instead of 1370# If --ABI option is specified, then only specified Python ABI is printed instead of
992# filename of Python interpreter. 1371# filename of Python interpreter.
993# If --absolute-path option is specified, then absolute path to Python interpreter is printed. 1372# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
994# --ABI and --absolute-path options cannot be specified simultaneously. 1373# --ABI and --absolute-path options cannot be specified simultaneously.
995PYTHON() { 1374PYTHON() {
1375 _python_check_python_pkg_setup_execution
1376
996 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" 1377 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
997 1378
998 while (($#)); do 1379 while (($#)); do
999 case "$1" in 1380 case "$1" in
1000 -2) 1381 -2)
1025 esac 1406 esac
1026 shift 1407 shift
1027 done 1408 done
1028 1409
1029 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 1410 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1030 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 1411 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1031 fi 1412 fi
1032 1413
1033 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then 1414 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1034 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 1415 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1035 fi 1416 fi
1037 if [[ "$#" -eq 0 ]]; then 1418 if [[ "$#" -eq 0 ]]; then
1038 if [[ "${final_ABI}" == "1" ]]; then 1419 if [[ "${final_ABI}" == "1" ]]; then
1039 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1420 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1040 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1421 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1041 fi 1422 fi
1042 validate_PYTHON_ABIS 1423 _python_calculate_PYTHON_ABIS
1043 PYTHON_ABI="${PYTHON_ABIS##* }" 1424 PYTHON_ABI="${PYTHON_ABIS##* }"
1044 elif [[ "${python2}" == "1" ]]; then 1425 elif [[ "${python2}" == "1" ]]; then
1045 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1426 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1046 if [[ -z "${PYTHON_ABI}" ]]; then 1427 if [[ -z "${PYTHON_ABI}" ]]; then
1047 die "${FUNCNAME}(): Active Python 2 interpreter not set" 1428 die "${FUNCNAME}(): Active version of Python 2 not set"
1048 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1429 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1049 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1430 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1050 fi 1431 fi
1051 elif [[ "${python3}" == "1" ]]; then 1432 elif [[ "${python3}" == "1" ]]; then
1052 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1433 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1053 if [[ -z "${PYTHON_ABI}" ]]; then 1434 if [[ -z "${PYTHON_ABI}" ]]; then
1054 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1435 die "${FUNCNAME}(): Active version of Python 3 not set"
1055 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1436 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1056 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1437 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1057 fi 1438 fi
1058 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1439 elif _python_package_supporting_installation_for_multiple_python_abis; then
1440 if ! _python_abi-specific_local_scope; then
1441 die "${FUNCNAME}() should be used in ABI-specific local scope"
1442 fi
1443 else
1059 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1444 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1060 elif [[ -z "${PYTHON_ABI}" ]]; then 1445 if [[ -z "${PYTHON_ABI}" ]]; then
1061 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" 1446 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1447 fi
1062 fi 1448 fi
1063 elif [[ "$#" -eq 1 ]]; then 1449 elif [[ "$#" -eq 1 ]]; then
1064 if [[ "${final_ABI}" == "1" ]]; then 1450 if [[ "${final_ABI}" == "1" ]]; then
1065 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 1451 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1066 fi 1452 fi
1101# @USAGE: [-f|--final-ABI] 1487# @USAGE: [-f|--final-ABI]
1102# @DESCRIPTION: 1488# @DESCRIPTION:
1103# Print name of Python implementation. 1489# Print name of Python implementation.
1104# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1490# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1105python_get_implementation() { 1491python_get_implementation() {
1492 _python_check_python_pkg_setup_execution
1493
1106 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1494 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1107 1495
1108 while (($#)); do 1496 while (($#)); do
1109 case "$1" in 1497 case "$1" in
1110 -f|--final-ABI) 1498 -f|--final-ABI)
1123 if [[ "${final_ABI}" == "1" ]]; then 1511 if [[ "${final_ABI}" == "1" ]]; then
1124 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1512 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1125 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1513 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1126 fi 1514 fi
1127 PYTHON_ABI="$(PYTHON -f --ABI)" 1515 PYTHON_ABI="$(PYTHON -f --ABI)"
1128 elif [[ -z "${PYTHON_ABI}" ]]; then 1516 else
1517 if _python_package_supporting_installation_for_multiple_python_abis; then
1518 if ! _python_abi-specific_local_scope; then
1519 die "${FUNCNAME}() should be used in ABI-specific local scope"
1520 fi
1521 else
1129 PYTHON_ABI="$(PYTHON --ABI)" 1522 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1523 fi
1130 fi 1524 fi
1131 1525
1132 echo "$(_python_get_implementation "${PYTHON_ABI}")" 1526 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1133} 1527}
1134 1528
1136# @USAGE: [-f|--final-ABI] 1530# @USAGE: [-f|--final-ABI]
1137# @DESCRIPTION: 1531# @DESCRIPTION:
1138# Print category, name and slot of package providing Python implementation. 1532# Print category, name and slot of package providing Python implementation.
1139# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1533# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1140python_get_implementational_package() { 1534python_get_implementational_package() {
1535 _python_check_python_pkg_setup_execution
1536
1141 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1537 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1142 1538
1143 while (($#)); do 1539 while (($#)); do
1144 case "$1" in 1540 case "$1" in
1145 -f|--final-ABI) 1541 -f|--final-ABI)
1158 if [[ "${final_ABI}" == "1" ]]; then 1554 if [[ "${final_ABI}" == "1" ]]; then
1159 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1555 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1160 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1556 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1161 fi 1557 fi
1162 PYTHON_ABI="$(PYTHON -f --ABI)" 1558 PYTHON_ABI="$(PYTHON -f --ABI)"
1163 elif [[ -z "${PYTHON_ABI}" ]]; then 1559 else
1560 if _python_package_supporting_installation_for_multiple_python_abis; then
1561 if ! _python_abi-specific_local_scope; then
1562 die "${FUNCNAME}() should be used in ABI-specific local scope"
1563 fi
1564 else
1164 PYTHON_ABI="$(PYTHON --ABI)" 1565 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1566 fi
1165 fi 1567 fi
1166 1568
1167 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1569 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1168 echo "dev-lang/python:${PYTHON_ABI}" 1570 echo "dev-lang/python:${PYTHON_ABI}"
1169 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1571 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1170 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1572 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1171 fi 1573 fi
1172} 1574}
1173 1575
1174# @FUNCTION: python_get_includedir 1576# @FUNCTION: python_get_includedir
1175# @USAGE: [-f|--final-ABI] 1577# @USAGE: [-b|--base-path] [-f|--final-ABI]
1176# @DESCRIPTION: 1578# @DESCRIPTION:
1177# Print path to Python include directory. 1579# Print path to Python include directory.
1580# If --base-path option is specified, then path not prefixed with "/" is printed.
1178# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1581# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1179python_get_includedir() { 1582python_get_includedir() {
1583 _python_check_python_pkg_setup_execution
1584
1180 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1585 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1181 1586
1182 while (($#)); do 1587 while (($#)); do
1183 case "$1" in 1588 case "$1" in
1589 -b|--base-path)
1590 base_path="1"
1591 ;;
1184 -f|--final-ABI) 1592 -f|--final-ABI)
1185 final_ABI="1" 1593 final_ABI="1"
1186 ;; 1594 ;;
1187 -*) 1595 -*)
1188 die "${FUNCNAME}(): Unrecognized option '$1'" 1596 die "${FUNCNAME}(): Unrecognized option '$1'"
1192 ;; 1600 ;;
1193 esac 1601 esac
1194 shift 1602 shift
1195 done 1603 done
1196 1604
1605 if [[ "${base_path}" == "0" ]]; then
1606 prefix="/"
1607 fi
1608
1197 if [[ "${final_ABI}" == "1" ]]; then 1609 if [[ "${final_ABI}" == "1" ]]; then
1198 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1610 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1199 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1611 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1200 fi 1612 fi
1201 PYTHON_ABI="$(PYTHON -f --ABI)" 1613 PYTHON_ABI="$(PYTHON -f --ABI)"
1202 elif [[ -z "${PYTHON_ABI}" ]]; then 1614 else
1615 if _python_package_supporting_installation_for_multiple_python_abis; then
1616 if ! _python_abi-specific_local_scope; then
1617 die "${FUNCNAME}() should be used in ABI-specific local scope"
1618 fi
1619 else
1203 PYTHON_ABI="$(PYTHON --ABI)" 1620 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1621 fi
1204 fi 1622 fi
1205 1623
1206 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1624 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1207 echo "/usr/include/python${PYTHON_ABI}" 1625 echo "${prefix}usr/include/python${PYTHON_ABI}"
1208 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1626 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1209 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Include" 1627 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1210 fi 1628 fi
1211} 1629}
1212 1630
1213# @FUNCTION: python_get_libdir 1631# @FUNCTION: python_get_libdir
1214# @USAGE: [-f|--final-ABI] 1632# @USAGE: [-b|--base-path] [-f|--final-ABI]
1215# @DESCRIPTION: 1633# @DESCRIPTION:
1216# Print path to Python library directory. 1634# Print path to Python library directory.
1635# If --base-path option is specified, then path not prefixed with "/" is printed.
1217# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1636# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1218python_get_libdir() { 1637python_get_libdir() {
1638 _python_check_python_pkg_setup_execution
1639
1219 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" 1640 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1220 1641
1221 while (($#)); do 1642 while (($#)); do
1222 case "$1" in 1643 case "$1" in
1644 -b|--base-path)
1645 base_path="1"
1646 ;;
1223 -f|--final-ABI) 1647 -f|--final-ABI)
1224 final_ABI="1" 1648 final_ABI="1"
1225 ;; 1649 ;;
1226 -*) 1650 -*)
1227 die "${FUNCNAME}(): Unrecognized option '$1'" 1651 die "${FUNCNAME}(): Unrecognized option '$1'"
1231 ;; 1655 ;;
1232 esac 1656 esac
1233 shift 1657 shift
1234 done 1658 done
1235 1659
1660 if [[ "${base_path}" == "0" ]]; then
1661 prefix="/"
1662 fi
1663
1236 if [[ "${final_ABI}" == "1" ]]; then 1664 if [[ "${final_ABI}" == "1" ]]; then
1237 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1665 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1238 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1666 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1239 fi 1667 fi
1240 PYTHON_ABI="$(PYTHON -f --ABI)" 1668 PYTHON_ABI="$(PYTHON -f --ABI)"
1241 elif [[ -z "${PYTHON_ABI}" ]]; then 1669 else
1670 if _python_package_supporting_installation_for_multiple_python_abis; then
1671 if ! _python_abi-specific_local_scope; then
1672 die "${FUNCNAME}() should be used in ABI-specific local scope"
1673 fi
1674 else
1242 PYTHON_ABI="$(PYTHON --ABI)" 1675 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1676 fi
1243 fi 1677 fi
1244 1678
1245 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1679 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1246 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1680 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1247 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1681 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1248 echo "/usr/share/jython-${PYTHON_ABI%-jython}/Lib" 1682 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1249 fi 1683 fi
1250} 1684}
1251 1685
1252# @FUNCTION: python_get_sitedir 1686# @FUNCTION: python_get_sitedir
1253# @USAGE: [-f|--final-ABI] 1687# @USAGE: [-b|--base-path] [-f|--final-ABI]
1254# @DESCRIPTION: 1688# @DESCRIPTION:
1255# Print path to Python site-packages directory. 1689# Print path to Python site-packages directory.
1690# If --base-path option is specified, then path not prefixed with "/" is printed.
1256# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1691# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1257python_get_sitedir() { 1692python_get_sitedir() {
1258 local options=() 1693 _python_check_python_pkg_setup_execution
1694
1695 local final_ABI="0" options=()
1259 1696
1260 while (($#)); do 1697 while (($#)); do
1261 case "$1" in 1698 case "$1" in
1699 -b|--base-path)
1700 options+=("$1")
1701 ;;
1262 -f|--final-ABI) 1702 -f|--final-ABI)
1263 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1703 final_ABI="1"
1264 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1265 fi
1266 options+=("$1") 1704 options+=("$1")
1267 ;; 1705 ;;
1268 -*) 1706 -*)
1269 die "${FUNCNAME}(): Unrecognized option '$1'" 1707 die "${FUNCNAME}(): Unrecognized option '$1'"
1270 ;; 1708 ;;
1273 ;; 1711 ;;
1274 esac 1712 esac
1275 shift 1713 shift
1276 done 1714 done
1277 1715
1716 if [[ "${final_ABI}" == "1" ]]; then
1717 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1718 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1719 fi
1720 else
1721 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1722 die "${FUNCNAME}() should be used in ABI-specific local scope"
1723 fi
1724 fi
1725
1278 echo "$(python_get_libdir "${options[@]}")/site-packages" 1726 echo "$(python_get_libdir "${options[@]}")/site-packages"
1279} 1727}
1280 1728
1281# @FUNCTION: python_get_library 1729# @FUNCTION: python_get_library
1282# @USAGE: [-f|--final-ABI] [-l|--linker-option] 1730# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1283# @DESCRIPTION: 1731# @DESCRIPTION:
1284# Print path to Python library. 1732# Print path to Python library.
1733# If --base-path option is specified, then path not prefixed with "/" is printed.
1285# If --linker-option is specified, then "-l${library}" linker option is printed. 1734# If --linker-option is specified, then "-l${library}" linker option is printed.
1286# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1735# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1287python_get_library() { 1736python_get_library() {
1737 _python_check_python_pkg_setup_execution
1738
1288 local final_ABI="0" linker_option="0" PYTHON_ABI="${PYTHON_ABI}" 1739 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1289 1740
1290 while (($#)); do 1741 while (($#)); do
1291 case "$1" in 1742 case "$1" in
1743 -b|--base-path)
1744 base_path="1"
1745 ;;
1292 -f|--final-ABI) 1746 -f|--final-ABI)
1293 final_ABI="1" 1747 final_ABI="1"
1294 ;; 1748 ;;
1295 -l|--linker-option) 1749 -l|--linker-option)
1296 linker_option="1" 1750 linker_option="1"
1303 ;; 1757 ;;
1304 esac 1758 esac
1305 shift 1759 shift
1306 done 1760 done
1307 1761
1762 if [[ "${base_path}" == "0" ]]; then
1763 prefix="/"
1764 fi
1765
1766 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1767 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1768 fi
1769
1308 if [[ "${final_ABI}" == "1" ]]; then 1770 if [[ "${final_ABI}" == "1" ]]; then
1309 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1771 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1310 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1772 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1311 fi 1773 fi
1312 PYTHON_ABI="$(PYTHON -f --ABI)" 1774 PYTHON_ABI="$(PYTHON -f --ABI)"
1313 elif [[ -z "${PYTHON_ABI}" ]]; then 1775 else
1776 if _python_package_supporting_installation_for_multiple_python_abis; then
1777 if ! _python_abi-specific_local_scope; then
1778 die "${FUNCNAME}() should be used in ABI-specific local scope"
1779 fi
1780 else
1314 PYTHON_ABI="$(PYTHON --ABI)" 1781 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1782 fi
1315 fi 1783 fi
1316 1784
1317 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1785 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1318 if [[ "${linker_option}" == "1" ]]; then 1786 if [[ "${linker_option}" == "1" ]]; then
1319 echo "-lpython${PYTHON_ABI}" 1787 echo "-lpython${PYTHON_ABI}"
1320 else 1788 else
1321 echo "/usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)" 1789 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1322 fi 1790 fi
1323 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1791 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1324 die "${FUNCNAME}(): Jython does not have shared library" 1792 die "${FUNCNAME}(): Jython does not have shared library"
1325 fi 1793 fi
1326} 1794}
1331# Print Python version. 1799# Print Python version.
1332# --full, --major, --minor and --micro options cannot be specified simultaneously. 1800# --full, --major, --minor and --micro options cannot be specified simultaneously.
1333# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1801# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1334# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1802# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1335python_get_version() { 1803python_get_version() {
1804 _python_check_python_pkg_setup_execution
1805
1336 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command 1806 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1337 1807
1338 while (($#)); do 1808 while (($#)); do
1339 case "$1" in 1809 case "$1" in
1340 -f|--final-ABI) 1810 -f|--final-ABI)
1390 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1860 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1391 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1861 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1392 fi 1862 fi
1393 "$(PYTHON -f)" -c "${python_command}" 1863 "$(PYTHON -f)" -c "${python_command}"
1394 else 1864 else
1865 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1866 die "${FUNCNAME}() should be used in ABI-specific local scope"
1867 fi
1395 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1868 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1396 fi 1869 fi
1397}
1398
1399# ================================================================================================
1400# =================================== MISCELLANEOUS FUNCTIONS ====================================
1401# ================================================================================================
1402
1403_python_implementation() {
1404 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
1405 return 0
1406 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1407 return 0
1408 else
1409 return 1
1410 fi
1411}
1412
1413_python_package_supporting_installation_for_multiple_python_abis() {
1414 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1415 die "${FUNCNAME}() cannot be used in global scope"
1416 fi
1417
1418 if has "${EAPI:-0}" 0 1 2 3 4; then
1419 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1420 return 0
1421 else
1422 return 1
1423 fi
1424 else
1425 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1426 fi
1427}
1428
1429_python_initialize_prefix_variables() {
1430 if has "${EAPI:-0}" 0 1 2; then
1431 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
1432 EROOT="${ROOT%/}${EPREFIX}/"
1433 fi
1434 if [[ -n "${D}" && -z "${ED}" ]]; then
1435 ED="${D%/}${EPREFIX}/"
1436 fi
1437 fi
1438}
1439
1440unset PYTHON_SANITY_CHECKS
1441
1442_python_initial_sanity_checks() {
1443 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1444 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
1445 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
1446 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
1447 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1448 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
1449 fi
1450 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
1451 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
1452 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1453 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
1454 fi
1455 fi
1456}
1457
1458_python_final_sanity_checks() {
1459 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1460 local PYTHON_ABI="${PYTHON_ABI}"
1461 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
1462 # Ensure that appropriate version of Python is installed.
1463 if ! has_version "$(python_get_implementational_package)"; then
1464 die "$(python_get_implementational_package) is not installed"
1465 fi
1466
1467 # Ensure that EPYTHON variable is respected.
1468 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
1469 eerror "python: '$(type -p python)'"
1470 eerror "ABI: '${ABI}'"
1471 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
1472 eerror "EPYTHON: '$(PYTHON)'"
1473 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
1474 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
1475 die "'python' does not respect EPYTHON variable"
1476 fi
1477 done
1478 fi
1479 PYTHON_SANITY_CHECKS="1"
1480}
1481
1482_python_set_color_variables() {
1483 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1484 _BOLD=$'\e[1m'
1485 _RED=$'\e[1;31m'
1486 _GREEN=$'\e[1;32m'
1487 _BLUE=$'\e[1;34m'
1488 _CYAN=$'\e[1;36m'
1489 _NORMAL=$'\e[0m'
1490 else
1491 _BOLD=
1492 _RED=
1493 _GREEN=
1494 _BLUE=
1495 _CYAN=
1496 _NORMAL=
1497 fi
1498}
1499
1500# @FUNCTION: python_convert_shebangs
1501# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
1502# @DESCRIPTION:
1503# Convert shebangs in specified files. Directories can be specified only with --recursive option.
1504python_convert_shebangs() {
1505 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
1506
1507 while (($#)); do
1508 case "$1" in
1509 -r|--recursive)
1510 recursive="1"
1511 ;;
1512 -q|--quiet)
1513 quiet="1"
1514 ;;
1515 -x|--only-executables)
1516 only_executables="1"
1517 ;;
1518 --)
1519 shift
1520 break
1521 ;;
1522 -*)
1523 die "${FUNCNAME}(): Unrecognized option '$1'"
1524 ;;
1525 *)
1526 break
1527 ;;
1528 esac
1529 shift
1530 done
1531
1532 if [[ "$#" -eq 0 ]]; then
1533 die "${FUNCNAME}(): Missing Python version and files or directories"
1534 elif [[ "$#" -eq 1 ]]; then
1535 die "${FUNCNAME}(): Missing files or directories"
1536 fi
1537
1538 python_version="$1"
1539 shift
1540
1541 for argument in "$@"; do
1542 if [[ ! -e "${argument}" ]]; then
1543 die "${FUNCNAME}(): '${argument}' does not exist"
1544 elif [[ -f "${argument}" ]]; then
1545 files+=("${argument}")
1546 elif [[ -d "${argument}" ]]; then
1547 if [[ "${recursive}" == "1" ]]; then
1548 while read -d $'\0' -r file; do
1549 files+=("${file}")
1550 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1551 else
1552 die "${FUNCNAME}(): '${argument}' is not a regular file"
1553 fi
1554 else
1555 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1556 fi
1557 done
1558
1559 for file in "${files[@]}"; do
1560 file="${file#./}"
1561 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1562
1563 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1564 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1565
1566 if [[ "${quiet}" == "0" ]]; then
1567 einfo "Converting shebang in '${file}'"
1568 fi
1569
1570 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1571
1572 # Delete potential whitespace after "#!".
1573 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1574 fi
1575 done
1576}
1577
1578# @FUNCTION: python_clean_sitedirs
1579# @DESCRIPTION:
1580# Delete needless files in site-packages directories in ${ED}.
1581python_clean_sitedirs() {
1582 _python_initialize_prefix_variables
1583
1584 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1585} 1870}
1586 1871
1587# ================================================================================================ 1872# ================================================================================================
1588# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1873# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1589# ================================================================================================ 1874# ================================================================================================
1609# @DESCRIPTION: 1894# @DESCRIPTION:
1610# Execute nosetests for all enabled Python ABIs. 1895# Execute nosetests for all enabled Python ABIs.
1611# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1896# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1612# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 1897# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1613python_execute_nosetests() { 1898python_execute_nosetests() {
1899 _python_check_python_pkg_setup_execution
1614 _python_set_color_variables 1900 _python_set_color_variables
1615 1901
1616 local PYTHONPATH_template= separate_build_dirs= 1902 local PYTHONPATH_template= separate_build_dirs=
1617 1903
1618 while (($#)); do 1904 while (($#)); do
1637 esac 1923 esac
1638 shift 1924 shift
1639 done 1925 done
1640 1926
1641 python_test_function() { 1927 python_test_function() {
1642 local evaluated_PYTHONPATH= 1928 local evaluated_PYTHONPATH
1643 1929
1644 if [[ -n "${PYTHONPATH_template}" ]]; then
1645 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1930 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1646 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1647 unset evaluated_PYTHONPATH
1648 fi
1649 fi
1650 1931
1651 _python_test_hook pre 1932 _python_test_hook pre
1652 1933
1653 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1934 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1654 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1935 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1677# @DESCRIPTION: 1958# @DESCRIPTION:
1678# Execute py.test for all enabled Python ABIs. 1959# Execute py.test for all enabled Python ABIs.
1679# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls 1960# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
1680# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 1961# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1681python_execute_py.test() { 1962python_execute_py.test() {
1963 _python_check_python_pkg_setup_execution
1682 _python_set_color_variables 1964 _python_set_color_variables
1683 1965
1684 local PYTHONPATH_template= separate_build_dirs= 1966 local PYTHONPATH_template= separate_build_dirs=
1685 1967
1686 while (($#)); do 1968 while (($#)); do
1705 esac 1987 esac
1706 shift 1988 shift
1707 done 1989 done
1708 1990
1709 python_test_function() { 1991 python_test_function() {
1710 local evaluated_PYTHONPATH= 1992 local evaluated_PYTHONPATH
1711 1993
1712 if [[ -n "${PYTHONPATH_template}" ]]; then
1713 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 1994 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1714 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1715 unset evaluated_PYTHONPATH
1716 fi
1717 fi
1718 1995
1719 _python_test_hook pre 1996 _python_test_hook pre
1720 1997
1721 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1998 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1722 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1999 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1745# @DESCRIPTION: 2022# @DESCRIPTION:
1746# Execute trial for all enabled Python ABIs. 2023# Execute trial for all enabled Python ABIs.
1747# In ebuilds of packages supporting installation for multiple Python ABIs, this function 2024# In ebuilds of packages supporting installation for multiple Python ABIs, this function
1748# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2025# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1749python_execute_trial() { 2026python_execute_trial() {
2027 _python_check_python_pkg_setup_execution
1750 _python_set_color_variables 2028 _python_set_color_variables
1751 2029
1752 local PYTHONPATH_template= separate_build_dirs= 2030 local PYTHONPATH_template= separate_build_dirs=
1753 2031
1754 while (($#)); do 2032 while (($#)); do
1773 esac 2051 esac
1774 shift 2052 shift
1775 done 2053 done
1776 2054
1777 python_test_function() { 2055 python_test_function() {
1778 local evaluated_PYTHONPATH= 2056 local evaluated_PYTHONPATH
1779 2057
1780 if [[ -n "${PYTHONPATH_template}" ]]; then
1781 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")" 2058 evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
1782 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1783 unset evaluated_PYTHONPATH
1784 fi
1785 fi
1786 2059
1787 _python_test_hook pre 2060 _python_test_hook pre
1788 2061
1789 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2062 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1790 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2063 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1815# @FUNCTION: python_enable_pyc 2088# @FUNCTION: python_enable_pyc
1816# @DESCRIPTION: 2089# @DESCRIPTION:
1817# Tell Python to automatically recompile modules to .pyc/.pyo if the 2090# Tell Python to automatically recompile modules to .pyc/.pyo if the
1818# timestamps/version stamps have changed. 2091# timestamps/version stamps have changed.
1819python_enable_pyc() { 2092python_enable_pyc() {
2093 _python_check_python_pkg_setup_execution
2094
2095 if [[ "$#" -ne 0 ]]; then
2096 die "${FUNCNAME}() does not accept arguments"
2097 fi
2098
1820 unset PYTHONDONTWRITEBYTECODE 2099 unset PYTHONDONTWRITEBYTECODE
1821} 2100}
1822 2101
1823# @FUNCTION: python_disable_pyc 2102# @FUNCTION: python_disable_pyc
1824# @DESCRIPTION: 2103# @DESCRIPTION:
1825# Tell Python not to automatically recompile modules to .pyc/.pyo 2104# Tell Python not to automatically recompile modules to .pyc/.pyo
1826# even if the timestamps/version stamps do not match. This is done 2105# even if the timestamps/version stamps do not match. This is done
1827# to protect sandbox. 2106# to protect sandbox.
1828python_disable_pyc() { 2107python_disable_pyc() {
2108 _python_check_python_pkg_setup_execution
2109
2110 if [[ "$#" -ne 0 ]]; then
2111 die "${FUNCNAME}() does not accept arguments"
2112 fi
2113
1829 export PYTHONDONTWRITEBYTECODE="1" 2114 export PYTHONDONTWRITEBYTECODE="1"
2115}
2116
2117_python_clean_compiled_modules() {
2118 _python_initialize_prefix_variables
2119 _python_set_color_variables
2120
2121 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2122
2123 local base_module_name compiled_file compiled_files=() dir path py_file root
2124
2125 # Strip trailing slash from EROOT.
2126 root="${EROOT%/}"
2127
2128 for path in "$@"; do
2129 compiled_files=()
2130 if [[ -d "${path}" ]]; then
2131 while read -d $'\0' -r compiled_file; do
2132 compiled_files+=("${compiled_file}")
2133 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
2134
2135 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2136 # Delete empty child directories.
2137 find "${path}" -type d | sort -r | while read -r dir; do
2138 if rmdir "${dir}" 2> /dev/null; then
2139 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2140 fi
2141 done
2142 fi
2143 elif [[ "${path}" == *.py ]]; then
2144 base_module_name="${path##*/}"
2145 base_module_name="${base_module_name%.py}"
2146 if [[ -d "${path%/*}/__pycache__" ]]; then
2147 while read -d $'\0' -r compiled_file; do
2148 compiled_files+=("${compiled_file}")
2149 done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
2150 fi
2151 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
2152 fi
2153
2154 for compiled_file in "${compiled_files[@]}"; do
2155 [[ ! -f "${compiled_file}" ]] && continue
2156 dir="${compiled_file%/*}"
2157 dir="${dir##*/}"
2158 if [[ "${compiled_file}" == *.py[co] ]]; then
2159 if [[ "${dir}" == "__pycache__" ]]; then
2160 base_module_name="${compiled_file##*/}"
2161 base_module_name="${base_module_name%.*py[co]}"
2162 base_module_name="${base_module_name%.*}"
2163 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2164 else
2165 py_file="${compiled_file%[co]}"
2166 fi
2167 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2168 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2169 else
2170 [[ -f "${py_file}" ]] && continue
2171 fi
2172 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
2173 rm -f "${compiled_file%[co]}"[co]
2174 elif [[ "${compiled_file}" == *\$py.class ]]; then
2175 if [[ "${dir}" == "__pycache__" ]]; then
2176 base_module_name="${compiled_file##*/}"
2177 base_module_name="${base_module_name%\$py.class}"
2178 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2179 else
2180 py_file="${compiled_file%\$py.class}"
2181 fi
2182 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2183 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2184 else
2185 [[ -f "${py_file}" ]] && continue
2186 fi
2187 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
2188 rm -f "${compiled_file}"
2189 else
2190 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
2191 fi
2192
2193 # Delete empty parent directories.
2194 dir="${compiled_file%/*}"
2195 while [[ "${dir}" != "${root}" ]]; do
2196 if rmdir "${dir}" 2> /dev/null; then
2197 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2198 else
2199 break
2200 fi
2201 dir="${dir%/*}"
2202 done
2203 done
2204 done
1830} 2205}
1831 2206
1832# @FUNCTION: python_mod_optimize 2207# @FUNCTION: python_mod_optimize
1833# @USAGE: [options] [directory|file] 2208# @USAGE: [options] [directory|file]
1834# @DESCRIPTION: 2209# @DESCRIPTION:
1840# 2215#
1841# Options passed to this function are passed to compileall.py. 2216# Options passed to this function are passed to compileall.py.
1842# 2217#
1843# This function can be used only in pkg_postinst() phase. 2218# This function can be used only in pkg_postinst() phase.
1844python_mod_optimize() { 2219python_mod_optimize() {
2220 _python_check_python_pkg_setup_execution
1845 _python_initialize_prefix_variables 2221 _python_initialize_prefix_variables
1846 2222
1847 # Check if phase is pkg_postinst(). 2223 # Check if phase is pkg_postinst().
1848 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2224 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1849 2225
1850 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2226 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2227 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
1851 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 2228 local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1852 2229
2230 if _python_package_supporting_installation_for_multiple_python_abis; then
2231 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2232 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2233 fi
2234 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2235 else
2236 if has "${EAPI:-0}" 0 1 2 3; then
2237 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2238 else
2239 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2240 fi
2241 fi
2242
1853 # Strip trailing slash from ROOT. 2243 # Strip trailing slash from EROOT.
1854 root="${EROOT%/}" 2244 root="${EROOT%/}"
1855 2245
1856 # Respect ROOT and options passed to compileall.py.
1857 while (($#)); do 2246 while (($#)); do
1858 case "$1" in 2247 case "$1" in
1859 -l|-f|-q) 2248 -l|-f|-q)
1860 options+=("$1") 2249 options+=("$1")
1861 ;; 2250 ;;
1862 -d|-x) 2251 -d|-x)
1863 options+=("$1" "$2") 2252 options+=("$1" "$2")
1864 shift 2253 shift
1865 ;; 2254 ;;
2255 --)
2256 shift
2257 break
2258 ;;
1866 -*) 2259 -*)
1867 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2260 die "${FUNCNAME}(): Unrecognized option '$1'"
1868 ;; 2261 ;;
1869 *) 2262 *)
1870 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1871 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1872 elif [[ "$1" =~ ^/ ]]; then
1873 if [[ -d "${root}/$1" ]]; then
1874 other_dirs+=("${root}/$1")
1875 elif [[ -f "${root}/$1" ]]; then
1876 other_files+=("${root}/$1")
1877 elif [[ -e "${root}/$1" ]]; then
1878 ewarn "'${root}/$1' is not a file or a directory!"
1879 else
1880 ewarn "'${root}/$1' does not exist!"
1881 fi
1882 else
1883 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1884 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1885 site_packages_dirs+=("$1")
1886 break 2263 break
1887 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1888 site_packages_files+=("$1")
1889 break
1890 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
1891 ewarn "'$1' is not a file or a directory!"
1892 else
1893 ewarn "'$1' does not exist!"
1894 fi
1895 done
1896 fi
1897 ;; 2264 ;;
1898 esac 2265 esac
1899 shift 2266 shift
1900 done 2267 done
1901 2268
2269 if [[ "$#" -eq 0 ]]; then
2270 _python_set_color_variables
2271
2272 echo
2273 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2274 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2275 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2276 echo
2277
2278 einfo &> /dev/null
2279 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2280 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2281 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2282 einfo &> /dev/null
2283 fi
2284
2285 while (($#)); do
2286 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2287 die "${FUNCNAME}(): Invalid argument '$1'"
2288 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2289 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2290 elif [[ "$1" =~ ^/ ]]; then
2291 if _python_package_supporting_installation_for_multiple_python_abis; then
2292 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2293 fi
2294 if [[ -d "${root}$1" ]]; then
2295 other_dirs+=("${root}$1")
2296 elif [[ -f "${root}$1" ]]; then
2297 other_files+=("${root}$1")
2298 elif [[ -e "${root}$1" ]]; then
2299 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2300 else
2301 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2302 fi
2303 else
2304 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2305 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2306 site_packages_dirs+=("$1")
2307 break
2308 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2309 site_packages_files+=("$1")
2310 break
2311 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2312 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2313 else
2314 eerror "${FUNCNAME}(): '$1' does not exist"
2315 fi
2316 done
2317 fi
2318 shift
2319 done
2320
1902 # Set additional options. 2321 # Set additional options.
1903 options+=("-q") 2322 options+=("-q")
1904 2323
1905 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2324 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1906 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2325 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
1907 return_code="0" 2326 return_code="0"
1908 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2327 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1909 if ((${#site_packages_dirs[@]})); then 2328 if ((${#site_packages_dirs[@]})); then
1910 for dir in "${site_packages_dirs[@]}"; do 2329 for dir in "${site_packages_dirs[@]}"; do
1912 done 2331 done
1913 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2332 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
1914 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2333 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1915 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2334 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
1916 fi 2335 fi
2336 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}"
1917 fi 2337 fi
1918 if ((${#site_packages_files[@]})); then 2338 if ((${#site_packages_files[@]})); then
1919 for file in "${site_packages_files[@]}"; do 2339 for file in "${site_packages_files[@]}"; do
1920 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2340 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
1921 done 2341 done
1922 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2342 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
1923 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2343 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1924 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2344 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
1925 fi 2345 fi
2346 _python_clean_compiled_modules "${site_packages_absolute_files[@]}"
1926 fi 2347 fi
1927 eend "${return_code}" 2348 eend "${return_code}"
1928 fi 2349 fi
1929 unset site_packages_absolute_dirs site_packages_absolute_files 2350 unset site_packages_absolute_dirs site_packages_absolute_files
1930 done 2351 done
1931 2352
2353 if _python_package_supporting_installation_for_multiple_python_abis; then
1932 # Restore previous value of PYTHON_ABI. 2354 # Restore previous value of PYTHON_ABI.
1933 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2355 if [[ -n "${previous_PYTHON_ABI}" ]]; then
1934 PYTHON_ABI="${previous_PYTHON_ABI}" 2356 PYTHON_ABI="${previous_PYTHON_ABI}"
1935 else 2357 else
1936 unset PYTHON_ABI 2358 unset PYTHON_ABI
2359 fi
1937 fi 2360 fi
1938 2361
1939 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2362 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1940 return_code="0" 2363 return_code="0"
1941 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2364 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
1942 if ((${#other_dirs[@]})); then 2365 if ((${#other_dirs[@]})); then
1943 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2366 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1944 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2367 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1945 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2368 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1946 fi 2369 fi
2370 _python_clean_compiled_modules "${other_dirs[@]}"
1947 fi 2371 fi
1948 if ((${#other_files[@]})); then 2372 if ((${#other_files[@]})); then
1949 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2373 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1950 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2374 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1951 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2375 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1952 fi 2376 fi
2377 _python_clean_compiled_modules "${other_dirs[@]}"
1953 fi 2378 fi
1954 eend "${return_code}" 2379 eend "${return_code}"
1955 fi 2380 fi
1956 else 2381 else
2382 # Deprecated part of python_mod_optimize()
2383
1957 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2384 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1958 2385
1959 # strip trailing slash 2386 # strip trailing slash
1960 myroot="${EROOT%/}" 2387 myroot="${EROOT%/}"
1961 2388
1962 # respect ROOT and options passed to compileall.py 2389 # respect EROOT and options passed to compileall.py
1963 while (($#)); do 2390 while (($#)); do
1964 case "$1" in 2391 case "$1" in
1965 -l|-f|-q) 2392 -l|-f|-q)
1966 myopts+=("$1") 2393 myopts+=("$1")
1967 ;; 2394 ;;
1968 -d|-x) 2395 -d|-x)
1969 myopts+=("$1" "$2") 2396 myopts+=("$1" "$2")
1970 shift 2397 shift
1971 ;; 2398 ;;
2399 --)
2400 shift
2401 break
2402 ;;
1972 -*) 2403 -*)
1973 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2404 die "${FUNCNAME}(): Unrecognized option '$1'"
1974 ;; 2405 ;;
1975 *) 2406 *)
1976 if [[ -d "${myroot}"/$1 ]]; then 2407 break
1977 mydirs+=("${myroot}/$1")
1978 elif [[ -f "${myroot}"/$1 ]]; then
1979 # Files are passed to python_mod_compile which is ROOT-aware
1980 myfiles+=("$1")
1981 elif [[ -e "${myroot}/$1" ]]; then
1982 ewarn "${myroot}/$1 is not a file or directory!"
1983 else
1984 ewarn "${myroot}/$1 does not exist!"
1985 fi
1986 ;; 2408 ;;
1987 esac 2409 esac
1988 shift 2410 shift
1989 done 2411 done
1990 2412
2413 if [[ "$#" -eq 0 ]]; then
2414 _python_set_color_variables
2415
2416 echo
2417 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2418 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_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 einfo &> /dev/null
2423 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2424 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2425 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2426 einfo &> /dev/null
2427 fi
2428
2429 while (($#)); do
2430 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2431 die "${FUNCNAME}(): Invalid argument '$1'"
2432 elif [[ -d "${myroot}/${1#/}" ]]; then
2433 mydirs+=("${myroot}/${1#/}")
2434 elif [[ -f "${myroot}/${1#/}" ]]; then
2435 # Files are passed to python_mod_compile which is EROOT-aware
2436 myfiles+=("$1")
2437 elif [[ -e "${myroot}/${1#/}" ]]; then
2438 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2439 else
2440 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2441 fi
2442 shift
2443 done
2444
1991 # set additional opts 2445 # set additional opts
1992 myopts+=(-q) 2446 myopts+=(-q)
2447
2448 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1993 2449
1994 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2450 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1995 if ((${#mydirs[@]})); then 2451 if ((${#mydirs[@]})); then
1996 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2452 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1997 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2453 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2454 _python_clean_compiled_modules "${mydirs[@]}"
1998 fi 2455 fi
1999 2456
2000 if ((${#myfiles[@]})); then 2457 if ((${#myfiles[@]})); then
2001 python_mod_compile "${myfiles[@]}" 2458 python_mod_compile "${myfiles[@]}"
2002 fi 2459 fi
2015# determine if they are orphaned (i.e. their corresponding .py files are missing.) 2472# determine if they are orphaned (i.e. their corresponding .py files are missing.)
2016# If they are, then it will remove their corresponding .pyc and .pyo files. 2473# If they are, then it will remove their corresponding .pyc and .pyo files.
2017# 2474#
2018# This function can be used only in pkg_postrm() phase. 2475# This function can be used only in pkg_postrm() phase.
2019python_mod_cleanup() { 2476python_mod_cleanup() {
2477 _python_check_python_pkg_setup_execution
2020 _python_initialize_prefix_variables 2478 _python_initialize_prefix_variables
2021 _python_set_color_variables
2022 2479
2023 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2480 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2024 2481
2025 # Check if phase is pkg_postrm(). 2482 # Check if phase is pkg_postrm().
2026 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2483 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2027 2484
2485 if _python_package_supporting_installation_for_multiple_python_abis; then
2486 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2487 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2488 fi
2489 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2490 else
2491 if has "${EAPI:-0}" 0 1 2 3; then
2492 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2493 else
2494 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2495 fi
2496 fi
2497
2028 # Strip trailing slash from ROOT. 2498 # Strip trailing slash from EROOT.
2029 root="${EROOT%/}" 2499 root="${EROOT%/}"
2030 2500
2031 if (($#)); then 2501 if [[ "$#" -gt 0 ]]; then
2032 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2502 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2033 while (($#)); do 2503 while (($#)); do
2504 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2505 die "${FUNCNAME}(): Invalid argument '$1'"
2034 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2506 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2035 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 2507 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2036 elif [[ "$1" =~ ^/ ]]; then 2508 elif [[ "$1" =~ ^/ ]]; then
2037 SEARCH_PATH+=("${root}/${1#/}") 2509 if _python_package_supporting_installation_for_multiple_python_abis; then
2510 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2511 fi
2512 search_paths+=("${root}$1")
2038 else 2513 else
2039 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2514 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2040 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") 2515 search_paths+=("${root}$(python_get_sitedir)/$1")
2041 done 2516 done
2042 fi 2517 fi
2043 shift 2518 shift
2044 done 2519 done
2045 else 2520 else
2046 SEARCH_PATH=("${@#/}") 2521 # Deprecated part of python_mod_cleanup()
2047 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") 2522
2523 search_paths=("${@#/}")
2524 search_paths=("${search_paths[@]/#/${root}/}")
2048 fi 2525 fi
2049 else 2526 else
2050 local dir sitedir 2527 _python_set_color_variables
2528
2529 echo
2530 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2531 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2532 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2533 echo
2534
2535 einfo &> /dev/null
2536 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2537 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2538 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2539 einfo &> /dev/null
2540
2051 for dir in "${root}"/usr/lib*; do 2541 for dir in "${root}"/usr/lib*; do
2052 if [[ -d "${dir}" && ! -L "${dir}" ]]; then 2542 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2053 for sitedir in "${dir}"/python*/site-packages; do 2543 for sitedir in "${dir}"/python*/site-packages; do
2054 if [[ -d "${sitedir}" ]]; then 2544 if [[ -d "${sitedir}" ]]; then
2055 SEARCH_PATH+=("${sitedir}") 2545 search_paths+=("${sitedir}")
2056 fi 2546 fi
2057 done 2547 done
2058 fi 2548 fi
2059 done 2549 done
2060 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2550 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do
2061 if [[ -d "${sitedir}" ]]; then 2551 if [[ -d "${sitedir}" ]]; then
2062 SEARCH_PATH+=("${sitedir}") 2552 search_paths+=("${sitedir}")
2063 fi 2553 fi
2064 done 2554 done
2065 fi 2555 fi
2066 2556
2067 for path in "${SEARCH_PATH[@]}"; do 2557 _python_clean_compiled_modules "${search_paths[@]}"
2068 if [[ -d "${path}" ]]; then
2069 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
2070 if [[ "${REPLY}" == *[co] ]]; then
2071 py_file="${REPLY%[co]}"
2072 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
2073 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
2074 rm -f "${py_file}"[co]
2075 elif [[ "${REPLY}" == *\$py.class ]]; then
2076 py_file="${REPLY%\$py.class}.py"
2077 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
2078 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
2079 rm -f "${py_file%.py}\$py.class"
2080 fi
2081 done
2082
2083 # Attempt to delete directories, which may be empty.
2084 find "${path}" -type d | sort -r | while read -r dir; do
2085 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
2086 done
2087 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
2088 if [[ (-f "${path}c" || -f "${path}o") ]]; then
2089 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
2090 rm -f "${path}"[co]
2091 fi
2092 if [[ -f "${path%.py}\$py.class" ]]; then
2093 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2094 rm -f "${path%.py}\$py.class"
2095 fi
2096 fi
2097 done
2098} 2558}
2099 2559
2100# ================================================================================================ 2560# ================================================================================================
2101# ===================================== DEPRECATED FUNCTIONS ===================================== 2561# ===================================== DEPRECATED FUNCTIONS =====================================
2102# ================================================================================================ 2562# ================================================================================================
2103 2563
2104# @FUNCTION: python_version 2564# Scheduled for deletion on 2011-01-01.
2105# @DESCRIPTION:
2106# Run without arguments and it will export the version of python
2107# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
2108python_version() { 2565python_version() {
2109 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2110 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
2111 die "${FUNCNAME}() cannot be used in this EAPI"
2112 fi
2113
2114 _python_set_color_variables
2115
2116 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2117 echo
2118 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2119 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}"
2120 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2121 echo
2122
2123 einfo &> /dev/null
2124 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2125 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null 2566 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2126 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2567 die "${FUNCNAME}() is banned"
2127 einfo &> /dev/null
2128 fi
2129
2130 [[ -n "${PYVER}" ]] && return 0
2131 local tmpstr
2132 python="${python:-${EPREFIX}/usr/bin/python}"
2133 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2134 export PYVER_ALL="${tmpstr#Python }"
2135 export PYVER_MAJOR="${PYVER_ALL:0:1}"
2136 export PYVER_MINOR="${PYVER_ALL:2:1}"
2137 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
2138 export PYVER_MICRO="${PYVER_ALL:4}"
2139 fi
2140 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2141} 2568}
2142 2569
2143# @FUNCTION: python_mod_exists 2570# Scheduled for deletion on 2011-01-01.
2144# @USAGE: <module>
2145# @DESCRIPTION:
2146# Run with the module name as an argument. It will check if a
2147# Python module is installed and loadable. It will return
2148# TRUE(0) if the module exists, and FALSE(1) if the module does
2149# not exist.
2150#
2151# Example:
2152# if python_mod_exists gtk; then
2153# echo "gtk support enabled"
2154# fi
2155python_mod_exists() { 2571python_mod_exists() {
2156 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2157 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2572 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2158 die "${FUNCNAME}() cannot be used in this EAPI" 2573 die "${FUNCNAME}() is banned"
2159 fi
2160
2161 echo
2162 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2163 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2165 echo
2166
2167 einfo &> /dev/null
2168 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2169 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2170 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2171 einfo &> /dev/null
2172
2173 if [[ "$#" -ne 1 ]]; then
2174 die "${FUNCNAME}() requires 1 argument"
2175 fi
2176 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2177} 2574}
2178 2575
2179# @FUNCTION: python_tkinter_exists 2576# Scheduled for deletion on 2011-01-01.
2180# @DESCRIPTION:
2181# Run without arguments, checks if Python was compiled with Tkinter
2182# support. If not, prints an error message and dies.
2183python_tkinter_exists() { 2577python_tkinter_exists() {
2184 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2185 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2578 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2186 die "${FUNCNAME}() cannot be used in this EAPI" 2579 die "${FUNCNAME}() is banned"
2187 fi
2188
2189 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2190 echo
2191 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2192 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2194 echo
2195
2196 einfo &> /dev/null
2197 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2198 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2199 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2200 einfo &> /dev/null
2201 fi
2202
2203 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2204if version_info[0] == 3:
2205 import tkinter
2206else:
2207 import Tkinter" &> /dev/null; then
2208 eerror "Python needs to be rebuilt with tkinter support enabled."
2209 eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python"
2210 eerror "dev-lang/python tk"
2211 die "Python installed without support for tkinter"
2212 fi
2213} 2580}
2214 2581
2215# @FUNCTION: python_mod_compile 2582# @FUNCTION: python_mod_compile
2216# @USAGE: <file> [more files ...] 2583# @USAGE: <file> [more files ...]
2217# @DESCRIPTION: 2584# @DESCRIPTION:
2226 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2593 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2227 die "${FUNCNAME}() cannot be used in this EAPI" 2594 die "${FUNCNAME}() cannot be used in this EAPI"
2228 fi 2595 fi
2229 2596
2230 _python_initialize_prefix_variables 2597 _python_initialize_prefix_variables
2598 _python_set_color_variables
2599
2600 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2601 echo
2602 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2603 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2604 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2605 echo
2606
2607 einfo &> /dev/null
2608 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2609 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2610 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2611 einfo &> /dev/null
2612 fi
2231 2613
2232 local f myroot myfiles=() 2614 local f myroot myfiles=()
2233 2615
2234 # Check if phase is pkg_postinst() 2616 # Check if phase is pkg_postinst()
2235 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2617 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2236 2618
2237 # strip trailing slash 2619 # strip trailing slash
2238 myroot="${EROOT%/}" 2620 myroot="${EROOT%/}"
2239 2621
2240 # respect ROOT 2622 # respect EROOT
2241 for f in "$@"; do 2623 for f in "$@"; do
2242 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 2624 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2243 done 2625 done
2244 2626
2627 PYTHON_ABI="$(PYTHON --ABI)"
2628
2245 if ((${#myfiles[@]})); then 2629 if ((${#myfiles[@]})); then
2246 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" 2630 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2247 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null 2631 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2632 _python_clean_compiled_modules "${myfiles[@]}"
2248 else 2633 else
2249 ewarn "No files to compile!" 2634 ewarn "No files to compile!"
2250 fi 2635 fi
2251} 2636}

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

  ViewVC Help
Powered by ViewVC 1.1.20