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

Diff of /eclass/python.eclass

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

Revision 1.96 Revision 1.99
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.96 2010/03/26 15:23:17 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.99 2010/05/25 19:49:54 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
182# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT 182# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
183# @DESCRIPTION: 183# @DESCRIPTION:
184# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or 184# 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. 185# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
186 186
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 187if ! 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=() 188 _PYTHON_USE_WITH_ATOMS_ARRAY=()
242 if [[ -n "${PYTHON_USE_WITH}" ]]; then 189 if [[ -n "${PYTHON_USE_WITH}" ]]; then
243 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 190 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
244 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]") 191 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
245 done 192 done
246 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 193 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
247 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 194 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
248 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 195 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
249 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") 196 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
265fi 212fi
266 213
267unset _PYTHON_ATOMS 214unset _PYTHON_ATOMS
268 215
269# ================================================================================================ 216# ================================================================================================
217# =================================== MISCELLANEOUS FUNCTIONS ====================================
218# ================================================================================================
219
220_python_implementation() {
221 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
222 return 0
223 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
224 return 0
225 else
226 return 1
227 fi
228}
229
230_python_package_supporting_installation_for_multiple_python_abis() {
231 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
232 die "${FUNCNAME}() cannot be used in global scope"
233 fi
234
235 if has "${EAPI:-0}" 0 1 2 3 4; then
236 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
237 return 0
238 else
239 return 1
240 fi
241 else
242 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
243 fi
244}
245
246_python_initialize_prefix_variables() {
247 if has "${EAPI:-0}" 0 1 2; then
248 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
249 EROOT="${ROOT%/}${EPREFIX}/"
250 fi
251 if [[ -n "${D}" && -z "${ED}" ]]; then
252 ED="${D%/}${EPREFIX}/"
253 fi
254 fi
255}
256
257unset PYTHON_SANITY_CHECKS
258
259_python_initial_sanity_checks() {
260 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
261 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
262 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
263 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
264 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
265 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
266 fi
267 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
268 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
269 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
270 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
271 fi
272 fi
273}
274
275_python_final_sanity_checks() {
276 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
277 local PYTHON_ABI="${PYTHON_ABI}"
278 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
279 # Ensure that appropriate version of Python is installed.
280 if ! has_version "$(python_get_implementational_package)"; then
281 die "$(python_get_implementational_package) is not installed"
282 fi
283
284 # Ensure that EPYTHON variable is respected.
285 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
286 eerror "Path to 'python': '$(type -p python)'"
287 eerror "ABI: '${ABI}'"
288 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
289 eerror "EPYTHON: '$(PYTHON)'"
290 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
291 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
292 die "'python' does not respect EPYTHON variable"
293 fi
294 done
295 fi
296 PYTHON_SANITY_CHECKS="1"
297}
298
299_python_set_color_variables() {
300 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
301 _BOLD=$'\e[1m'
302 _RED=$'\e[1;31m'
303 _GREEN=$'\e[1;32m'
304 _BLUE=$'\e[1;34m'
305 _CYAN=$'\e[1;36m'
306 _NORMAL=$'\e[0m'
307 else
308 _BOLD=
309 _RED=
310 _GREEN=
311 _BLUE=
312 _CYAN=
313 _NORMAL=
314 fi
315}
316
317unset PYTHON_PKG_SETUP_EXECUTED
318
319# @FUNCTION: python_pkg_setup
320# @DESCRIPTION:
321# Perform sanity checks and initialize environment.
322#
323# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
324# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
325#
326# This function can be used only in pkg_setup() phase.
327python_pkg_setup() {
328 # Check if phase is pkg_setup().
329 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
330
331 if _python_package_supporting_installation_for_multiple_python_abis; then
332 _python_calculate_PYTHON_ABIS
333 export EPYTHON="$(PYTHON -f)"
334 else
335 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
336 fi
337
338 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
339 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
340 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
341 use ${PYTHON_USE_WITH_OPT#!} && return
342 else
343 use !${PYTHON_USE_WITH_OPT} && return
344 fi
345 fi
346
347 python_pkg_setup_check_USE_flags() {
348 local python_atom USE_flag
349 python_atom="$(python_get_implementational_package)"
350
351 for USE_flag in ${PYTHON_USE_WITH}; do
352 if ! has_version "${python_atom}[${USE_flag}]"; then
353 eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
354 die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
355 fi
356 done
357
358 for USE_flag in ${PYTHON_USE_WITH_OR}; do
359 if has_version "${python_atom}[${USE_flag}]"; then
360 return
361 fi
362 done
363
364 if [[ ${PYTHON_USE_WITH_OR} ]]; then
365 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
366 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
367 fi
368 }
369
370 if _python_package_supporting_installation_for_multiple_python_abis; then
371 python_execute_function -q python_pkg_setup_check_USE_flags
372 else
373 python_pkg_setup_check_USE_flags
374 fi
375
376 unset -f python_pkg_setup_check_USE_flags
377 fi
378
379 PYTHON_PKG_SETUP_EXECUTED="1"
380}
381
382if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
383 EXPORT_FUNCTIONS pkg_setup
384fi
385
386# @FUNCTION: python_convert_shebangs
387# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
388# @DESCRIPTION:
389# Convert shebangs in specified files. Directories can be specified only with --recursive option.
390python_convert_shebangs() {
391 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
392
393 while (($#)); do
394 case "$1" in
395 -r|--recursive)
396 recursive="1"
397 ;;
398 -q|--quiet)
399 quiet="1"
400 ;;
401 -x|--only-executables)
402 only_executables="1"
403 ;;
404 --)
405 shift
406 break
407 ;;
408 -*)
409 die "${FUNCNAME}(): Unrecognized option '$1'"
410 ;;
411 *)
412 break
413 ;;
414 esac
415 shift
416 done
417
418 if [[ "$#" -eq 0 ]]; then
419 die "${FUNCNAME}(): Missing Python version and files or directories"
420 elif [[ "$#" -eq 1 ]]; then
421 die "${FUNCNAME}(): Missing files or directories"
422 fi
423
424 python_version="$1"
425 shift
426
427 for argument in "$@"; do
428 if [[ ! -e "${argument}" ]]; then
429 die "${FUNCNAME}(): '${argument}' does not exist"
430 elif [[ -f "${argument}" ]]; then
431 files+=("${argument}")
432 elif [[ -d "${argument}" ]]; then
433 if [[ "${recursive}" == "1" ]]; then
434 while read -d $'\0' -r file; do
435 files+=("${file}")
436 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
437 else
438 die "${FUNCNAME}(): '${argument}' is not a regular file"
439 fi
440 else
441 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
442 fi
443 done
444
445 for file in "${files[@]}"; do
446 file="${file#./}"
447 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
448
449 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
450 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
451
452 if [[ "${quiet}" == "0" ]]; then
453 einfo "Converting shebang in '${file}'"
454 fi
455
456 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
457
458 # Delete potential whitespace after "#!".
459 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
460 fi
461 done
462}
463
464# @FUNCTION: python_clean_installation_image
465# @USAGE: [-q|--quiet]
466# @DESCRIPTION:
467# Delete needless files in installation image.
468python_clean_installation_image() {
469 _python_initialize_prefix_variables
470
471 local file files=() quiet="0"
472
473 # Check if phase is src_install().
474 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
475
476 while (($#)); do
477 case "$1" in
478 -q|--quiet)
479 quiet="1"
480 ;;
481 -*)
482 die "${FUNCNAME}(): Unrecognized option '$1'"
483 ;;
484 *)
485 die "${FUNCNAME}(): Invalid usage"
486 ;;
487 esac
488 shift
489 done
490
491 while read -d $'\0' -r file; do
492 files+=("${file}")
493 done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
494
495 if [[ "${#files[@]}" -gt 0 ]]; then
496 if [[ "${quiet}" == "0" ]]; then
497 ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
498 fi
499 for file in "${files[@]}"; do
500 if [[ "${quiet}" == "0" ]]; then
501 ewarn " ${file}"
502 fi
503 rm -f "${file}"
504
505 # Delete empty __pycache__ directories.
506 if [[ "${file%/*}" == *"/__pycache__" ]]; then
507 rmdir "${file%/*}" 2> /dev/null
508 fi
509 done
510 fi
511
512 python_clean_sitedirs() {
513 if [[ -d "${ED}$(python_get_sitedir)" ]]; then
514 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
515 fi
516 }
517 if _python_package_supporting_installation_for_multiple_python_abis; then
518 python_execute_function -q python_clean_sitedirs
519 else
520 python_clean_sitedirs
521 fi
522
523 unset -f python_clean_sitedirs
524}
525
526# ================================================================================================
270# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ 527# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
271# ================================================================================================ 528# ================================================================================================
272 529
273# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS 530# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
274# @DESCRIPTION: 531# @DESCRIPTION:
292 eval "python_${python_default_function}() { 549 eval "python_${python_default_function}() {
293 if ! _python_package_supporting_installation_for_multiple_python_abis; then 550 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\" 551 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
295 fi 552 fi
296 553
297 python_execute_function -d -s \"\$@\" 554 python_execute_function -d -s -- \"\$@\"
298 }" 555 }"
299 done 556 done
300 unset python_default_function 557 unset python_default_function
301 558
302 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 559 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
304 fi 561 fi
305fi 562fi
306 563
307unset PYTHON_ABIS 564unset PYTHON_ABIS
308 565
309# @FUNCTION: validate_PYTHON_ABIS 566_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 567 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" 568 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
316 fi 569 fi
317 570
318 _python_initial_sanity_checks 571 _python_initial_sanity_checks
355 if [[ "${cpython_enabled}" == "0" ]]; then 608 if [[ "${cpython_enabled}" == "0" ]]; then
356 die "USE_PYTHON variable does not enable any CPython ABI" 609 die "USE_PYTHON variable does not enable any CPython ABI"
357 fi 610 fi
358 else 611 else
359 local python_version python2_version= python3_version= support_python_major_version 612 local python_version python2_version= python3_version= support_python_major_version
613
614 if ! has_version "dev-lang/python"; then
615 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
616 fi
360 617
361 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 618 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
362 619
363 if has_version "=dev-lang/python-2*"; then 620 if has_version "=dev-lang/python-2*"; then
364 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then 621 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
561 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 818 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
562 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 819 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
563 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 820 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
564 fi 821 fi
565 822
566 validate_PYTHON_ABIS 823 _python_calculate_PYTHON_ABIS
567 if [[ "${final_ABI}" == "1" ]]; then 824 if [[ "${final_ABI}" == "1" ]]; then
568 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" 825 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
569 else 826 else
570 iterated_PYTHON_ABIS="${PYTHON_ABIS}" 827 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
571 fi 828 fi
673 930
674 local dir dirs=() PYTHON_ABI 931 local dir dirs=() PYTHON_ABI
675 932
676 if [[ "$#" -eq 0 ]]; then 933 if [[ "$#" -eq 0 ]]; then
677 if [[ "${WORKDIR}" == "${S}" ]]; then 934 if [[ "${WORKDIR}" == "${S}" ]]; then
678 die "${FUNCNAME}() cannot be used" 935 die "${FUNCNAME}() cannot be used with current value of S variable"
679 fi 936 fi
680 dirs=("${S%/}") 937 dirs=("${S%/}")
681 else 938 else
682 dirs=("$@") 939 dirs=("$@")
683 fi 940 fi
684 941
685 validate_PYTHON_ABIS 942 _python_calculate_PYTHON_ABIS
686 for PYTHON_ABI in ${PYTHON_ABIS}; do 943 for PYTHON_ABI in ${PYTHON_ABIS}; do
687 for dir in "${dirs[@]}"; do 944 for dir in "${dirs[@]}"; do
688 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 945 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
689 done 946 done
690 done 947 done
732 989
733 if [[ "$#" -eq 0 ]]; then 990 if [[ "$#" -eq 0 ]]; then
734 die "${FUNCNAME}(): Missing arguments" 991 die "${FUNCNAME}(): Missing arguments"
735 fi 992 fi
736 993
737 validate_PYTHON_ABIS 994 _python_calculate_PYTHON_ABIS
738 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 995 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
739 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 996 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
740 python2_enabled="1" 997 python2_enabled="1"
741 fi 998 fi
742 done 999 done
1038 if [[ "$#" -eq 0 ]]; then 1295 if [[ "$#" -eq 0 ]]; then
1039 if [[ "${final_ABI}" == "1" ]]; then 1296 if [[ "${final_ABI}" == "1" ]]; then
1040 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1297 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1041 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1298 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1042 fi 1299 fi
1043 validate_PYTHON_ABIS 1300 _python_calculate_PYTHON_ABIS
1044 PYTHON_ABI="${PYTHON_ABIS##* }" 1301 PYTHON_ABI="${PYTHON_ABIS##* }"
1045 elif [[ "${python2}" == "1" ]]; then 1302 elif [[ "${python2}" == "1" ]]; then
1046 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1303 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1047 if [[ -z "${PYTHON_ABI}" ]]; then 1304 if [[ -z "${PYTHON_ABI}" ]]; then
1048 die "${FUNCNAME}(): Active Python 2 interpreter not set" 1305 die "${FUNCNAME}(): Active version of Python 2 not set"
1049 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1306 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1050 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1307 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1051 fi 1308 fi
1052 elif [[ "${python3}" == "1" ]]; then 1309 elif [[ "${python3}" == "1" ]]; then
1053 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1310 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1054 if [[ -z "${PYTHON_ABI}" ]]; then 1311 if [[ -z "${PYTHON_ABI}" ]]; then
1055 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1312 die "${FUNCNAME}(): Active version of Python 3 not set"
1056 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1057 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1058 fi 1315 fi
1059 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then
1060 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" 1317 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1318 if [[ -z "${PYTHON_ABI}" ]]; then
1319 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1320 fi
1061 elif [[ -z "${PYTHON_ABI}" ]]; then 1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1062 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" 1322 die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
1063 fi 1323 fi
1064 elif [[ "$#" -eq 1 ]]; then 1324 elif [[ "$#" -eq 1 ]]; then
1065 if [[ "${final_ABI}" == "1" ]]; then 1325 if [[ "${final_ABI}" == "1" ]]; then
1396 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1397 fi 1657 fi
1398} 1658}
1399 1659
1400# ================================================================================================ 1660# ================================================================================================
1401# =================================== MISCELLANEOUS FUNCTIONS ====================================
1402# ================================================================================================
1403
1404_python_implementation() {
1405 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
1406 return 0
1407 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
1408 return 0
1409 else
1410 return 1
1411 fi
1412}
1413
1414_python_package_supporting_installation_for_multiple_python_abis() {
1415 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
1416 die "${FUNCNAME}() cannot be used in global scope"
1417 fi
1418
1419 if has "${EAPI:-0}" 0 1 2 3 4; then
1420 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1421 return 0
1422 else
1423 return 1
1424 fi
1425 else
1426 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
1427 fi
1428}
1429
1430_python_initialize_prefix_variables() {
1431 if has "${EAPI:-0}" 0 1 2; then
1432 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
1433 EROOT="${ROOT%/}${EPREFIX}/"
1434 fi
1435 if [[ -n "${D}" && -z "${ED}" ]]; then
1436 ED="${D%/}${EPREFIX}/"
1437 fi
1438 fi
1439}
1440
1441unset PYTHON_SANITY_CHECKS
1442
1443_python_initial_sanity_checks() {
1444 if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1445 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
1446 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
1447 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
1448 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1449 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
1450 fi
1451 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
1452 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
1453 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
1454 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
1455 fi
1456 fi
1457}
1458
1459_python_final_sanity_checks() {
1460 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
1461 local PYTHON_ABI="${PYTHON_ABI}"
1462 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
1463 # Ensure that appropriate version of Python is installed.
1464 if ! has_version "$(python_get_implementational_package)"; then
1465 die "$(python_get_implementational_package) is not installed"
1466 fi
1467
1468 # Ensure that EPYTHON variable is respected.
1469 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
1470 eerror "python: '$(type -p python)'"
1471 eerror "ABI: '${ABI}'"
1472 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
1473 eerror "EPYTHON: '$(PYTHON)'"
1474 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
1475 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
1476 die "'python' does not respect EPYTHON variable"
1477 fi
1478 done
1479 fi
1480 PYTHON_SANITY_CHECKS="1"
1481}
1482
1483_python_set_color_variables() {
1484 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1485 _BOLD=$'\e[1m'
1486 _RED=$'\e[1;31m'
1487 _GREEN=$'\e[1;32m'
1488 _BLUE=$'\e[1;34m'
1489 _CYAN=$'\e[1;36m'
1490 _NORMAL=$'\e[0m'
1491 else
1492 _BOLD=
1493 _RED=
1494 _GREEN=
1495 _BLUE=
1496 _CYAN=
1497 _NORMAL=
1498 fi
1499}
1500
1501# @FUNCTION: python_convert_shebangs
1502# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
1503# @DESCRIPTION:
1504# Convert shebangs in specified files. Directories can be specified only with --recursive option.
1505python_convert_shebangs() {
1506 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
1507
1508 while (($#)); do
1509 case "$1" in
1510 -r|--recursive)
1511 recursive="1"
1512 ;;
1513 -q|--quiet)
1514 quiet="1"
1515 ;;
1516 -x|--only-executables)
1517 only_executables="1"
1518 ;;
1519 --)
1520 shift
1521 break
1522 ;;
1523 -*)
1524 die "${FUNCNAME}(): Unrecognized option '$1'"
1525 ;;
1526 *)
1527 break
1528 ;;
1529 esac
1530 shift
1531 done
1532
1533 if [[ "$#" -eq 0 ]]; then
1534 die "${FUNCNAME}(): Missing Python version and files or directories"
1535 elif [[ "$#" -eq 1 ]]; then
1536 die "${FUNCNAME}(): Missing files or directories"
1537 fi
1538
1539 python_version="$1"
1540 shift
1541
1542 for argument in "$@"; do
1543 if [[ ! -e "${argument}" ]]; then
1544 die "${FUNCNAME}(): '${argument}' does not exist"
1545 elif [[ -f "${argument}" ]]; then
1546 files+=("${argument}")
1547 elif [[ -d "${argument}" ]]; then
1548 if [[ "${recursive}" == "1" ]]; then
1549 while read -d $'\0' -r file; do
1550 files+=("${file}")
1551 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1552 else
1553 die "${FUNCNAME}(): '${argument}' is not a regular file"
1554 fi
1555 else
1556 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1557 fi
1558 done
1559
1560 for file in "${files[@]}"; do
1561 file="${file#./}"
1562 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1563
1564 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
1565 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1566
1567 if [[ "${quiet}" == "0" ]]; then
1568 einfo "Converting shebang in '${file}'"
1569 fi
1570
1571 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1572
1573 # Delete potential whitespace after "#!".
1574 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1575 fi
1576 done
1577}
1578
1579# @FUNCTION: python_clean_sitedirs
1580# @DESCRIPTION:
1581# Delete needless files in site-packages directories in ${ED}.
1582python_clean_sitedirs() {
1583 _python_initialize_prefix_variables
1584
1585 find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1586}
1587
1588# ================================================================================================
1589# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1661# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1590# ================================================================================================ 1662# ================================================================================================
1591 1663
1592# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY 1664# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
1593# @DESCRIPTION: 1665# @DESCRIPTION:
1826# Tell Python not to automatically recompile modules to .pyc/.pyo 1898# Tell Python not to automatically recompile modules to .pyc/.pyo
1827# even if the timestamps/version stamps do not match. This is done 1899# even if the timestamps/version stamps do not match. This is done
1828# to protect sandbox. 1900# to protect sandbox.
1829python_disable_pyc() { 1901python_disable_pyc() {
1830 export PYTHONDONTWRITEBYTECODE="1" 1902 export PYTHONDONTWRITEBYTECODE="1"
1903}
1904
1905_python_clean_compiled_modules() {
1906 _python_initialize_prefix_variables
1907 _python_set_color_variables
1908
1909 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
1910
1911 local base_module_name compiled_file compiled_files=() dir path py_file root
1912
1913 # Strip trailing slash from EROOT.
1914 root="${EROOT%/}"
1915
1916 for path in "$@"; do
1917 compiled_files=()
1918 if [[ -d "${path}" ]]; then
1919 while read -d $'\0' -r compiled_file; do
1920 compiled_files+=("${compiled_file}")
1921 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
1922
1923 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
1924 # Delete empty child directories.
1925 find "${path}" -type d | sort -r | while read -r dir; do
1926 rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
1927 done
1928 fi
1929 elif [[ "${path}" == *.py ]]; then
1930 base_module_name="${path##*/}"
1931 base_module_name="${base_module_name%.py}"
1932 if [[ -d "${path%/*}/__pycache__" ]]; then
1933 while read -d $'\0' -r compiled_file; do
1934 compiled_files+=("${compiled_file}")
1935 done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
1936 fi
1937 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
1938 fi
1939
1940 for compiled_file in "${compiled_files[@]}"; do
1941 [[ ! -f "${compiled_file}" ]] && continue
1942 dir="${compiled_file%/*}"
1943 dir="${dir##*/}"
1944 if [[ "${compiled_file}" == *.py[co] ]]; then
1945 if [[ "${dir}" == "__pycache__" ]]; then
1946 base_module_name="${compiled_file##*/}"
1947 base_module_name="${base_module_name%.*py[co]}"
1948 base_module_name="${base_module_name%.*}"
1949 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
1950 else
1951 py_file="${compiled_file%[co]}"
1952 fi
1953 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
1954 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
1955 else
1956 [[ -f "${py_file}" ]] && continue
1957 fi
1958 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
1959 rm -f "${compiled_file%[co]}"[co]
1960 elif [[ "${compiled_file}" == *\$py.class ]]; then
1961 if [[ "${dir}" == "__pycache__" ]]; then
1962 base_module_name="${compiled_file##*/}"
1963 base_module_name="${base_module_name%\$py.class}"
1964 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
1965 else
1966 py_file="${compiled_file%\$py.class}"
1967 fi
1968 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
1969 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
1970 else
1971 [[ -f "${py_file}" ]] && continue
1972 fi
1973 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
1974 rm -f "${compiled_file}"
1975 else
1976 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
1977 fi
1978
1979 # Delete empty parent directories.
1980 dir="${compiled_file%/*}"
1981 while [[ "${dir}" != "${root}" ]]; do
1982 if rmdir "${compiled_file%/*}" 2> /dev/null; then
1983 echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}"
1984 else
1985 break
1986 fi
1987 dir="${dir%/*}"
1988 done
1989 done
1990 done
1831} 1991}
1832 1992
1833# @FUNCTION: python_mod_optimize 1993# @FUNCTION: python_mod_optimize
1834# @USAGE: [options] [directory|file] 1994# @USAGE: [options] [directory|file]
1835# @DESCRIPTION: 1995# @DESCRIPTION:
1847 2007
1848 # Check if phase is pkg_postinst(). 2008 # Check if phase is pkg_postinst().
1849 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2009 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1850 2010
1851 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2011 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2012 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
1852 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=() 2013 local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1853 2014
2015 if _python_package_supporting_installation_for_multiple_python_abis; then
2016 if [[ -z "${PYTHON_ABIS}" ]]; then
2017 die "${FUNCNAME}(): Environment not initialized"
2018 fi
2019 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2020 else
2021 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2022 fi
2023
1854 # Strip trailing slash from ROOT. 2024 # Strip trailing slash from EROOT.
1855 root="${EROOT%/}" 2025 root="${EROOT%/}"
1856 2026
1857 # Respect ROOT and options passed to compileall.py.
1858 while (($#)); do 2027 while (($#)); do
1859 case "$1" in 2028 case "$1" in
1860 -l|-f|-q) 2029 -l|-f|-q)
1861 options+=("$1") 2030 options+=("$1")
1862 ;; 2031 ;;
1866 ;; 2035 ;;
1867 -*) 2036 -*)
1868 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2037 ewarn "${FUNCNAME}(): Ignoring option '$1'"
1869 ;; 2038 ;;
1870 *) 2039 *)
1871 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1872 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
1873 elif [[ "$1" =~ ^/ ]]; then
1874 if [[ -d "${root}/$1" ]]; then
1875 other_dirs+=("${root}/$1")
1876 elif [[ -f "${root}/$1" ]]; then
1877 other_files+=("${root}/$1")
1878 elif [[ -e "${root}/$1" ]]; then
1879 ewarn "'${root}/$1' is not a file or a directory!"
1880 else
1881 ewarn "'${root}/$1' does not exist!"
1882 fi
1883 else
1884 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
1885 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1886 site_packages_dirs+=("$1")
1887 break 2040 break
1888 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1889 site_packages_files+=("$1")
1890 break
1891 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
1892 ewarn "'$1' is not a file or a directory!"
1893 else
1894 ewarn "'$1' does not exist!"
1895 fi
1896 done
1897 fi
1898 ;; 2041 ;;
1899 esac 2042 esac
1900 shift 2043 shift
1901 done 2044 done
1902 2045
2046 if [[ "$#" -eq 0 ]]; then
2047 _python_set_color_variables
2048
2049 echo
2050 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2051 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2052 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2053 echo
2054
2055 einfo &> /dev/null
2056 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2057 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2058 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2059 einfo &> /dev/null
2060 fi
2061
2062 while (($#)); do
2063 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2064 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2065 elif [[ "$1" =~ ^/ ]]; then
2066 if _python_package_supporting_installation_for_multiple_python_abis; then
2067 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2068 fi
2069 if [[ -d "${root}$1" ]]; then
2070 other_dirs+=("${root}$1")
2071 elif [[ -f "${root}$1" ]]; then
2072 other_files+=("${root}$1")
2073 elif [[ -e "${root}$1" ]]; then
2074 eerror "'${root}$1' is not a file or a directory!"
2075 else
2076 eerror "'${root}$1' does not exist!"
2077 fi
2078 else
2079 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2080 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2081 site_packages_dirs+=("$1")
2082 break
2083 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2084 site_packages_files+=("$1")
2085 break
2086 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2087 eerror "'$1' is not a file or a directory!"
2088 else
2089 eerror "'$1' does not exist!"
2090 fi
2091 done
2092 fi
2093 shift
2094 done
2095
1903 # Set additional options. 2096 # Set additional options.
1904 options+=("-q") 2097 options+=("-q")
1905 2098
1906 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2099 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1907 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2100 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
1908 return_code="0" 2101 return_code="0"
1909 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2102 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1910 if ((${#site_packages_dirs[@]})); then 2103 if ((${#site_packages_dirs[@]})); then
1911 for dir in "${site_packages_dirs[@]}"; do 2104 for dir in "${site_packages_dirs[@]}"; do
1913 done 2106 done
1914 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2107 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
1915 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2108 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1916 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2109 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
1917 fi 2110 fi
2111 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}"
1918 fi 2112 fi
1919 if ((${#site_packages_files[@]})); then 2113 if ((${#site_packages_files[@]})); then
1920 for file in "${site_packages_files[@]}"; do 2114 for file in "${site_packages_files[@]}"; do
1921 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2115 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
1922 done 2116 done
1923 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2117 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
1924 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2118 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1925 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2119 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
1926 fi 2120 fi
2121 _python_clean_compiled_modules "${site_packages_absolute_files[@]}"
1927 fi 2122 fi
1928 eend "${return_code}" 2123 eend "${return_code}"
1929 fi 2124 fi
1930 unset site_packages_absolute_dirs site_packages_absolute_files 2125 unset site_packages_absolute_dirs site_packages_absolute_files
1931 done 2126 done
1932 2127
2128 if _python_package_supporting_installation_for_multiple_python_abis; then
1933 # Restore previous value of PYTHON_ABI. 2129 # Restore previous value of PYTHON_ABI.
1934 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2130 if [[ -n "${previous_PYTHON_ABI}" ]]; then
1935 PYTHON_ABI="${previous_PYTHON_ABI}" 2131 PYTHON_ABI="${previous_PYTHON_ABI}"
1936 else 2132 else
1937 unset PYTHON_ABI 2133 unset PYTHON_ABI
2134 fi
1938 fi 2135 fi
1939 2136
1940 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2137 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1941 return_code="0" 2138 return_code="0"
1942 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2139 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
1943 if ((${#other_dirs[@]})); then 2140 if ((${#other_dirs[@]})); then
1944 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2141 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1945 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2142 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1946 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2143 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1947 fi 2144 fi
2145 _python_clean_compiled_modules "${other_dirs[@]}"
1948 fi 2146 fi
1949 if ((${#other_files[@]})); then 2147 if ((${#other_files[@]})); then
1950 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2148 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1951 if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then 2149 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1952 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2150 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1953 fi 2151 fi
2152 _python_clean_compiled_modules "${other_dirs[@]}"
1954 fi 2153 fi
1955 eend "${return_code}" 2154 eend "${return_code}"
1956 fi 2155 fi
1957 else 2156 else
2157 # Deprecated part of python_mod_optimize()
2158
1958 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2159 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1959 2160
1960 # strip trailing slash 2161 # strip trailing slash
1961 myroot="${EROOT%/}" 2162 myroot="${EROOT%/}"
1962 2163
1963 # respect ROOT and options passed to compileall.py 2164 # respect EROOT and options passed to compileall.py
1964 while (($#)); do 2165 while (($#)); do
1965 case "$1" in 2166 case "$1" in
1966 -l|-f|-q) 2167 -l|-f|-q)
1967 myopts+=("$1") 2168 myopts+=("$1")
1968 ;; 2169 ;;
1972 ;; 2173 ;;
1973 -*) 2174 -*)
1974 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2175 ewarn "${FUNCNAME}(): Ignoring option '$1'"
1975 ;; 2176 ;;
1976 *) 2177 *)
1977 if [[ -d "${myroot}"/$1 ]]; then 2178 break
1978 mydirs+=("${myroot}/$1")
1979 elif [[ -f "${myroot}"/$1 ]]; then
1980 # Files are passed to python_mod_compile which is ROOT-aware
1981 myfiles+=("$1")
1982 elif [[ -e "${myroot}/$1" ]]; then
1983 ewarn "${myroot}/$1 is not a file or directory!"
1984 else
1985 ewarn "${myroot}/$1 does not exist!"
1986 fi
1987 ;; 2179 ;;
1988 esac 2180 esac
1989 shift 2181 shift
1990 done 2182 done
1991 2183
2184 if [[ "$#" -eq 0 ]]; then
2185 _python_set_color_variables
2186
2187 echo
2188 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2189 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2190 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2191 echo
2192
2193 einfo &> /dev/null
2194 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2195 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2196 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2197 einfo &> /dev/null
2198 fi
2199
2200 while (($#)); do
2201 if [[ -d "${myroot}/${1#/}" ]]; then
2202 mydirs+=("${myroot}/${1#/}")
2203 elif [[ -f "${myroot}/${1#/}" ]]; then
2204 # Files are passed to python_mod_compile which is EROOT-aware
2205 myfiles+=("$1")
2206 elif [[ -e "${myroot}/${1#/}" ]]; then
2207 eerror "${myroot}/${1#/} is not a file or directory!"
2208 else
2209 eerror "${myroot}/${1#/} does not exist!"
2210 fi
2211 shift
2212 done
2213
1992 # set additional opts 2214 # set additional opts
1993 myopts+=(-q) 2215 myopts+=(-q)
2216
2217 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1994 2218
1995 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2219 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1996 if ((${#mydirs[@]})); then 2220 if ((${#mydirs[@]})); then
1997 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2221 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1998 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2222 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2223 _python_clean_compiled_modules "${mydirs[@]}"
1999 fi 2224 fi
2000 2225
2001 if ((${#myfiles[@]})); then 2226 if ((${#myfiles[@]})); then
2002 python_mod_compile "${myfiles[@]}" 2227 python_mod_compile "${myfiles[@]}"
2003 fi 2228 fi
2017# If they are, then it will remove their corresponding .pyc and .pyo files. 2242# If they are, then it will remove their corresponding .pyc and .pyo files.
2018# 2243#
2019# This function can be used only in pkg_postrm() phase. 2244# This function can be used only in pkg_postrm() phase.
2020python_mod_cleanup() { 2245python_mod_cleanup() {
2021 _python_initialize_prefix_variables 2246 _python_initialize_prefix_variables
2022 _python_set_color_variables
2023 2247
2024 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2248 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2025 2249
2026 # Check if phase is pkg_postrm(). 2250 # Check if phase is pkg_postrm().
2027 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2251 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2028 2252
2253 if _python_package_supporting_installation_for_multiple_python_abis; then
2254 if [[ -z "${PYTHON_ABIS}" ]]; then
2255 die "${FUNCNAME}(): Environment not initialized"
2256 fi
2257 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2258 else
2259 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2260 fi
2261
2029 # Strip trailing slash from ROOT. 2262 # Strip trailing slash from EROOT.
2030 root="${EROOT%/}" 2263 root="${EROOT%/}"
2031 2264
2032 if (($#)); then 2265 if [[ "$#" -gt 0 ]]; then
2033 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2266 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2034 while (($#)); do 2267 while (($#)); do
2035 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2268 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2036 die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" 2269 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2037 elif [[ "$1" =~ ^/ ]]; then 2270 elif [[ "$1" =~ ^/ ]]; then
2038 SEARCH_PATH+=("${root}/${1#/}") 2271 if _python_package_supporting_installation_for_multiple_python_abis; then
2272 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2273 fi
2274 search_paths+=("${root}$1")
2039 else 2275 else
2040 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2276 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2041 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") 2277 search_paths+=("${root}$(python_get_sitedir)/$1")
2042 done 2278 done
2043 fi 2279 fi
2044 shift 2280 shift
2045 done 2281 done
2046 else 2282 else
2047 SEARCH_PATH=("${@#/}") 2283 # Deprecated part of python_mod_cleanup()
2048 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") 2284
2285 search_paths=("${@#/}")
2286 search_paths=("${search_paths[@]/#/${root}/}")
2049 fi 2287 fi
2050 else 2288 else
2051 local dir sitedir 2289 _python_set_color_variables
2290
2291 echo
2292 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2293 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2294 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2295 echo
2296
2297 einfo &> /dev/null
2298 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2299 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2300 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2301 einfo &> /dev/null
2302
2052 for dir in "${root}"/usr/lib*; do 2303 for dir in "${root}"/usr/lib*; do
2053 if [[ -d "${dir}" && ! -L "${dir}" ]]; then 2304 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2054 for sitedir in "${dir}"/python*/site-packages; do 2305 for sitedir in "${dir}"/python*/site-packages; do
2055 if [[ -d "${sitedir}" ]]; then 2306 if [[ -d "${sitedir}" ]]; then
2056 SEARCH_PATH+=("${sitedir}") 2307 search_paths+=("${sitedir}")
2057 fi 2308 fi
2058 done 2309 done
2059 fi 2310 fi
2060 done 2311 done
2061 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2312 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do
2062 if [[ -d "${sitedir}" ]]; then 2313 if [[ -d "${sitedir}" ]]; then
2063 SEARCH_PATH+=("${sitedir}") 2314 search_paths+=("${sitedir}")
2064 fi 2315 fi
2065 done 2316 done
2066 fi 2317 fi
2067 2318
2068 for path in "${SEARCH_PATH[@]}"; do 2319 _python_clean_compiled_modules "${search_paths[@]}"
2069 if [[ -d "${path}" ]]; then
2070 find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
2071 if [[ "${REPLY}" == *[co] ]]; then
2072 py_file="${REPLY%[co]}"
2073 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
2074 echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
2075 rm -f "${py_file}"[co]
2076 elif [[ "${REPLY}" == *\$py.class ]]; then
2077 py_file="${REPLY%\$py.class}.py"
2078 [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
2079 echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
2080 rm -f "${py_file%.py}\$py.class"
2081 fi
2082 done
2083
2084 # Attempt to delete directories, which may be empty.
2085 find "${path}" -type d | sort -r | while read -r dir; do
2086 rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
2087 done
2088 elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
2089 if [[ (-f "${path}c" || -f "${path}o") ]]; then
2090 echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
2091 rm -f "${path}"[co]
2092 fi
2093 if [[ -f "${path%.py}\$py.class" ]]; then
2094 echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
2095 rm -f "${path%.py}\$py.class"
2096 fi
2097 fi
2098 done
2099} 2320}
2100 2321
2101# ================================================================================================ 2322# ================================================================================================
2102# ===================================== DEPRECATED FUNCTIONS ===================================== 2323# ===================================== DEPRECATED FUNCTIONS =====================================
2103# ================================================================================================ 2324# ================================================================================================
2157 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2378 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2158 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." 2379 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2159 die "${FUNCNAME}() cannot be used in this EAPI" 2380 die "${FUNCNAME}() cannot be used in this EAPI"
2160 fi 2381 fi
2161 2382
2383 _python_set_color_variables
2384
2162 echo 2385 echo
2163 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" 2386 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2164 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}" 2387 echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
2165 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" 2388 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2166 echo 2389 echo
2167 2390
2168 einfo &> /dev/null 2391 eerror &> /dev/null
2169 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null 2392 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2170 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null 2393 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null
2171 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2394 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2172 einfo &> /dev/null 2395 eerror &> /dev/null
2173 2396
2174 if [[ "$#" -ne 1 ]]; then 2397 if [[ "$#" -ne 1 ]]; then
2175 die "${FUNCNAME}() requires 1 argument" 2398 die "${FUNCNAME}() requires 1 argument"
2176 fi 2399 fi
2177 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2400 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2185 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2408 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2186 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2409 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2187 die "${FUNCNAME}() cannot be used in this EAPI" 2410 die "${FUNCNAME}() cannot be used in this EAPI"
2188 fi 2411 fi
2189 2412
2413 _python_set_color_variables
2414
2190 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then 2415 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2191 echo 2416 echo
2192 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" 2417 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
2193 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}" 2418 echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}"
2194 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" 2419 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2195 echo 2420 echo
2196 2421
2197 einfo &> /dev/null 2422 eerror &> /dev/null
2198 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null 2423 eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null
2199 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null 2424 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null
2200 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null 2425 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2201 einfo &> /dev/null 2426 eerror &> /dev/null
2202 fi 2427 fi
2203 2428
2204 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2429 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2205if version_info[0] == 3: 2430if version_info[0] == 3:
2206 import tkinter 2431 import tkinter
2227 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2452 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2228 die "${FUNCNAME}() cannot be used in this EAPI" 2453 die "${FUNCNAME}() cannot be used in this EAPI"
2229 fi 2454 fi
2230 2455
2231 _python_initialize_prefix_variables 2456 _python_initialize_prefix_variables
2457 _python_set_color_variables
2458
2459 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2460 echo
2461 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2462 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2463 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2464 echo
2465
2466 einfo &> /dev/null
2467 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2468 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2469 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2470 einfo &> /dev/null
2471 fi
2232 2472
2233 local f myroot myfiles=() 2473 local f myroot myfiles=()
2234 2474
2235 # Check if phase is pkg_postinst() 2475 # Check if phase is pkg_postinst()
2236 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2476 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2237 2477
2238 # strip trailing slash 2478 # strip trailing slash
2239 myroot="${EROOT%/}" 2479 myroot="${EROOT%/}"
2240 2480
2241 # respect ROOT 2481 # respect EROOT
2242 for f in "$@"; do 2482 for f in "$@"; do
2243 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 2483 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2244 done 2484 done
2485
2486 PYTHON_ABI="$(PYTHON --ABI)"
2245 2487
2246 if ((${#myfiles[@]})); then 2488 if ((${#myfiles[@]})); then
2247 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" 2489 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
2248 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null 2490 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2491 _python_clean_compiled_modules "${myfiles[@]}"
2249 else 2492 else
2250 ewarn "No files to compile!" 2493 ewarn "No files to compile!"
2251 fi 2494 fi
2252} 2495}

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

  ViewVC Help
Powered by ViewVC 1.1.20