/[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.100
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.100 2010/05/29 16:39:13 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
846 fi 1103 fi
847 cat << EOF >> "${file}" 1104 cat << EOF >> "${file}"
848 1105
849wrapper_script_path = os.path.realpath(sys.argv[0]) 1106wrapper_script_path = os.path.realpath(sys.argv[0])
850target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1107target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1108os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
851os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1109os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
852os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1110os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
853if not os.path.exists(target_executable_path): 1111if not os.path.exists(target_executable_path):
854 sys.stderr.write("'%s' does not exist\n" % target_executable_path) 1112 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
855 sys.exit(1) 1113 sys.exit(1)
1037 if [[ "$#" -eq 0 ]]; then 1295 if [[ "$#" -eq 0 ]]; then
1038 if [[ "${final_ABI}" == "1" ]]; then 1296 if [[ "${final_ABI}" == "1" ]]; then
1039 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1297 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" 1298 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1041 fi 1299 fi
1042 validate_PYTHON_ABIS 1300 _python_calculate_PYTHON_ABIS
1043 PYTHON_ABI="${PYTHON_ABIS##* }" 1301 PYTHON_ABI="${PYTHON_ABIS##* }"
1044 elif [[ "${python2}" == "1" ]]; then 1302 elif [[ "${python2}" == "1" ]]; then
1045 PYTHON_ABI="$(eselect python show --python2 --ABI)" 1303 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1046 if [[ -z "${PYTHON_ABI}" ]]; then 1304 if [[ -z "${PYTHON_ABI}" ]]; then
1047 die "${FUNCNAME}(): Active Python 2 interpreter not set" 1305 die "${FUNCNAME}(): Active version of Python 2 not set"
1048 elif [[ "${PYTHON_ABI}" != "2."* ]]; then 1306 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1049 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" 1307 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1050 fi 1308 fi
1051 elif [[ "${python3}" == "1" ]]; then 1309 elif [[ "${python3}" == "1" ]]; then
1052 PYTHON_ABI="$(eselect python show --python3 --ABI)" 1310 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1053 if [[ -z "${PYTHON_ABI}" ]]; then 1311 if [[ -z "${PYTHON_ABI}" ]]; then
1054 die "${FUNCNAME}(): Active Python 3 interpreter not set" 1312 die "${FUNCNAME}(): Active version of Python 3 not set"
1055 elif [[ "${PYTHON_ABI}" != "3."* ]]; then 1313 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1056 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" 1314 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1057 fi 1315 fi
1058 elif ! _python_package_supporting_installation_for_multiple_python_abis; then 1316 elif ! _python_package_supporting_installation_for_multiple_python_abis; then
1059 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
1060 elif [[ -z "${PYTHON_ABI}" ]]; then 1321 elif [[ -z "${PYTHON_ABI}" ]]; then
1061 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"
1062 fi 1323 fi
1063 elif [[ "$#" -eq 1 ]]; then 1324 elif [[ "$#" -eq 1 ]]; then
1064 if [[ "${final_ABI}" == "1" ]]; then 1325 if [[ "${final_ABI}" == "1" ]]; then
1395 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" 1656 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
1396 fi 1657 fi
1397} 1658}
1398 1659
1399# ================================================================================================ 1660# ================================================================================================
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}
1586
1587# ================================================================================================
1588# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1661# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1589# ================================================================================================ 1662# ================================================================================================
1590 1663
1591# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY 1664# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
1592# @DESCRIPTION: 1665# @DESCRIPTION:
1825# Tell Python not to automatically recompile modules to .pyc/.pyo 1898# Tell Python not to automatically recompile modules to .pyc/.pyo
1826# 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
1827# to protect sandbox. 1900# to protect sandbox.
1828python_disable_pyc() { 1901python_disable_pyc() {
1829 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 if rmdir "${dir}" 2> /dev/null; then
1927 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1928 fi
1929 done
1930 fi
1931 elif [[ "${path}" == *.py ]]; then
1932 base_module_name="${path##*/}"
1933 base_module_name="${base_module_name%.py}"
1934 if [[ -d "${path%/*}/__pycache__" ]]; then
1935 while read -d $'\0' -r compiled_file; do
1936 compiled_files+=("${compiled_file}")
1937 done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
1938 fi
1939 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
1940 fi
1941
1942 for compiled_file in "${compiled_files[@]}"; do
1943 [[ ! -f "${compiled_file}" ]] && continue
1944 dir="${compiled_file%/*}"
1945 dir="${dir##*/}"
1946 if [[ "${compiled_file}" == *.py[co] ]]; then
1947 if [[ "${dir}" == "__pycache__" ]]; then
1948 base_module_name="${compiled_file##*/}"
1949 base_module_name="${base_module_name%.*py[co]}"
1950 base_module_name="${base_module_name%.*}"
1951 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
1952 else
1953 py_file="${compiled_file%[co]}"
1954 fi
1955 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
1956 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
1957 else
1958 [[ -f "${py_file}" ]] && continue
1959 fi
1960 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
1961 rm -f "${compiled_file%[co]}"[co]
1962 elif [[ "${compiled_file}" == *\$py.class ]]; then
1963 if [[ "${dir}" == "__pycache__" ]]; then
1964 base_module_name="${compiled_file##*/}"
1965 base_module_name="${base_module_name%\$py.class}"
1966 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
1967 else
1968 py_file="${compiled_file%\$py.class}"
1969 fi
1970 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
1971 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
1972 else
1973 [[ -f "${py_file}" ]] && continue
1974 fi
1975 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
1976 rm -f "${compiled_file}"
1977 else
1978 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
1979 fi
1980
1981 # Delete empty parent directories.
1982 dir="${compiled_file%/*}"
1983 while [[ "${dir}" != "${root}" ]]; do
1984 if rmdir "${dir}" 2> /dev/null; then
1985 echo "${_CYAN}<<< ${dir}${_NORMAL}"
1986 else
1987 break
1988 fi
1989 dir="${dir%/*}"
1990 done
1991 done
1992 done
1830} 1993}
1831 1994
1832# @FUNCTION: python_mod_optimize 1995# @FUNCTION: python_mod_optimize
1833# @USAGE: [options] [directory|file] 1996# @USAGE: [options] [directory|file]
1834# @DESCRIPTION: 1997# @DESCRIPTION:
1846 2009
1847 # Check if phase is pkg_postinst(). 2010 # Check if phase is pkg_postinst().
1848 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2011 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1849 2012
1850 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2013 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2014 # 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=() 2015 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 2016
2017 if _python_package_supporting_installation_for_multiple_python_abis; then
2018 if [[ -z "${PYTHON_ABIS}" ]]; then
2019 die "${FUNCNAME}(): Environment not initialized"
2020 fi
2021 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2022 else
2023 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2024 fi
2025
1853 # Strip trailing slash from ROOT. 2026 # Strip trailing slash from EROOT.
1854 root="${EROOT%/}" 2027 root="${EROOT%/}"
1855 2028
1856 # Respect ROOT and options passed to compileall.py.
1857 while (($#)); do 2029 while (($#)); do
1858 case "$1" in 2030 case "$1" in
1859 -l|-f|-q) 2031 -l|-f|-q)
1860 options+=("$1") 2032 options+=("$1")
1861 ;; 2033 ;;
1865 ;; 2037 ;;
1866 -*) 2038 -*)
1867 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2039 ewarn "${FUNCNAME}(): Ignoring option '$1'"
1868 ;; 2040 ;;
1869 *) 2041 *)
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 2042 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 ;; 2043 ;;
1898 esac 2044 esac
1899 shift 2045 shift
1900 done 2046 done
1901 2047
2048 if [[ "$#" -eq 0 ]]; then
2049 _python_set_color_variables
2050
2051 echo
2052 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2053 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2054 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2055 echo
2056
2057 einfo &> /dev/null
2058 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2059 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2060 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2061 einfo &> /dev/null
2062 fi
2063
2064 while (($#)); do
2065 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2066 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2067 elif [[ "$1" =~ ^/ ]]; then
2068 if _python_package_supporting_installation_for_multiple_python_abis; then
2069 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2070 fi
2071 if [[ -d "${root}$1" ]]; then
2072 other_dirs+=("${root}$1")
2073 elif [[ -f "${root}$1" ]]; then
2074 other_files+=("${root}$1")
2075 elif [[ -e "${root}$1" ]]; then
2076 eerror "'${root}$1' is not a file or a directory!"
2077 else
2078 eerror "'${root}$1' does not exist!"
2079 fi
2080 else
2081 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2082 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2083 site_packages_dirs+=("$1")
2084 break
2085 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2086 site_packages_files+=("$1")
2087 break
2088 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2089 eerror "'$1' is not a file or a directory!"
2090 else
2091 eerror "'$1' does not exist!"
2092 fi
2093 done
2094 fi
2095 shift
2096 done
2097
1902 # Set additional options. 2098 # Set additional options.
1903 options+=("-q") 2099 options+=("-q")
1904 2100
1905 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2101 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1906 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2102 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
1907 return_code="0" 2103 return_code="0"
1908 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2104 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1909 if ((${#site_packages_dirs[@]})); then 2105 if ((${#site_packages_dirs[@]})); then
1910 for dir in "${site_packages_dirs[@]}"; do 2106 for dir in "${site_packages_dirs[@]}"; do
1912 done 2108 done
1913 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2109 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
1914 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2110 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" 2111 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
1916 fi 2112 fi
2113 _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}"
1917 fi 2114 fi
1918 if ((${#site_packages_files[@]})); then 2115 if ((${#site_packages_files[@]})); then
1919 for file in "${site_packages_files[@]}"; do 2116 for file in "${site_packages_files[@]}"; do
1920 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2117 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
1921 done 2118 done
1922 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2119 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
1923 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2120 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" 2121 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
1925 fi 2122 fi
2123 _python_clean_compiled_modules "${site_packages_absolute_files[@]}"
1926 fi 2124 fi
1927 eend "${return_code}" 2125 eend "${return_code}"
1928 fi 2126 fi
1929 unset site_packages_absolute_dirs site_packages_absolute_files 2127 unset site_packages_absolute_dirs site_packages_absolute_files
1930 done 2128 done
1931 2129
2130 if _python_package_supporting_installation_for_multiple_python_abis; then
1932 # Restore previous value of PYTHON_ABI. 2131 # Restore previous value of PYTHON_ABI.
1933 if [[ -n "${previous_PYTHON_ABI}" ]]; then 2132 if [[ -n "${previous_PYTHON_ABI}" ]]; then
1934 PYTHON_ABI="${previous_PYTHON_ABI}" 2133 PYTHON_ABI="${previous_PYTHON_ABI}"
1935 else 2134 else
1936 unset PYTHON_ABI 2135 unset PYTHON_ABI
2136 fi
1937 fi 2137 fi
1938 2138
1939 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2139 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1940 return_code="0" 2140 return_code="0"
1941 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" 2141 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 2142 if ((${#other_dirs[@]})); then
1943 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2143 "$(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 2144 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" 2145 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1946 fi 2146 fi
2147 _python_clean_compiled_modules "${other_dirs[@]}"
1947 fi 2148 fi
1948 if ((${#other_files[@]})); then 2149 if ((${#other_files[@]})); then
1949 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2150 "$(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 2151 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" 2152 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1952 fi 2153 fi
2154 _python_clean_compiled_modules "${other_dirs[@]}"
1953 fi 2155 fi
1954 eend "${return_code}" 2156 eend "${return_code}"
1955 fi 2157 fi
1956 else 2158 else
2159 # Deprecated part of python_mod_optimize()
2160
1957 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2161 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1958 2162
1959 # strip trailing slash 2163 # strip trailing slash
1960 myroot="${EROOT%/}" 2164 myroot="${EROOT%/}"
1961 2165
1962 # respect ROOT and options passed to compileall.py 2166 # respect EROOT and options passed to compileall.py
1963 while (($#)); do 2167 while (($#)); do
1964 case "$1" in 2168 case "$1" in
1965 -l|-f|-q) 2169 -l|-f|-q)
1966 myopts+=("$1") 2170 myopts+=("$1")
1967 ;; 2171 ;;
1971 ;; 2175 ;;
1972 -*) 2176 -*)
1973 ewarn "${FUNCNAME}(): Ignoring option '$1'" 2177 ewarn "${FUNCNAME}(): Ignoring option '$1'"
1974 ;; 2178 ;;
1975 *) 2179 *)
1976 if [[ -d "${myroot}"/$1 ]]; then 2180 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 ;; 2181 ;;
1987 esac 2182 esac
1988 shift 2183 shift
1989 done 2184 done
1990 2185
2186 if [[ "$#" -eq 0 ]]; then
2187 _python_set_color_variables
2188
2189 echo
2190 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2191 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2192 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2193 echo
2194
2195 einfo &> /dev/null
2196 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2197 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2198 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2199 einfo &> /dev/null
2200 fi
2201
2202 while (($#)); do
2203 if [[ -d "${myroot}/${1#/}" ]]; then
2204 mydirs+=("${myroot}/${1#/}")
2205 elif [[ -f "${myroot}/${1#/}" ]]; then
2206 # Files are passed to python_mod_compile which is EROOT-aware
2207 myfiles+=("$1")
2208 elif [[ -e "${myroot}/${1#/}" ]]; then
2209 eerror "${myroot}/${1#/} is not a file or directory!"
2210 else
2211 eerror "${myroot}/${1#/} does not exist!"
2212 fi
2213 shift
2214 done
2215
1991 # set additional opts 2216 # set additional opts
1992 myopts+=(-q) 2217 myopts+=(-q)
2218
2219 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1993 2220
1994 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" 2221 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1995 if ((${#mydirs[@]})); then 2222 if ((${#mydirs[@]})); then
1996 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2223 "$(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" 2224 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2225 _python_clean_compiled_modules "${mydirs[@]}"
1998 fi 2226 fi
1999 2227
2000 if ((${#myfiles[@]})); then 2228 if ((${#myfiles[@]})); then
2001 python_mod_compile "${myfiles[@]}" 2229 python_mod_compile "${myfiles[@]}"
2002 fi 2230 fi
2016# If they are, then it will remove their corresponding .pyc and .pyo files. 2244# If they are, then it will remove their corresponding .pyc and .pyo files.
2017# 2245#
2018# This function can be used only in pkg_postrm() phase. 2246# This function can be used only in pkg_postrm() phase.
2019python_mod_cleanup() { 2247python_mod_cleanup() {
2020 _python_initialize_prefix_variables 2248 _python_initialize_prefix_variables
2021 _python_set_color_variables
2022 2249
2023 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 2250 local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2024 2251
2025 # Check if phase is pkg_postrm(). 2252 # Check if phase is pkg_postrm().
2026 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" 2253 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2027 2254
2255 if _python_package_supporting_installation_for_multiple_python_abis; then
2256 if [[ -z "${PYTHON_ABIS}" ]]; then
2257 die "${FUNCNAME}(): Environment not initialized"
2258 fi
2259 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2260 else
2261 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2262 fi
2263
2028 # Strip trailing slash from ROOT. 2264 # Strip trailing slash from EROOT.
2029 root="${EROOT%/}" 2265 root="${EROOT%/}"
2030 2266
2031 if (($#)); then 2267 if [[ "$#" -gt 0 ]]; then
2032 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2268 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
2033 while (($#)); do 2269 while (($#)); do
2034 if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2270 if ! _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" 2271 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2036 elif [[ "$1" =~ ^/ ]]; then 2272 elif [[ "$1" =~ ^/ ]]; then
2037 SEARCH_PATH+=("${root}/${1#/}") 2273 if _python_package_supporting_installation_for_multiple_python_abis; then
2274 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2275 fi
2276 search_paths+=("${root}$1")
2038 else 2277 else
2039 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do 2278 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2040 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") 2279 search_paths+=("${root}$(python_get_sitedir)/$1")
2041 done 2280 done
2042 fi 2281 fi
2043 shift 2282 shift
2044 done 2283 done
2045 else 2284 else
2046 SEARCH_PATH=("${@#/}") 2285 # Deprecated part of python_mod_cleanup()
2047 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") 2286
2287 search_paths=("${@#/}")
2288 search_paths=("${search_paths[@]/#/${root}/}")
2048 fi 2289 fi
2049 else 2290 else
2050 local dir sitedir 2291 _python_set_color_variables
2292
2293 echo
2294 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}"
2295 echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}"
2296 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2297 echo
2298
2299 einfo &> /dev/null
2300 einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null
2301 einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null
2302 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2303 einfo &> /dev/null
2304
2051 for dir in "${root}"/usr/lib*; do 2305 for dir in "${root}"/usr/lib*; do
2052 if [[ -d "${dir}" && ! -L "${dir}" ]]; then 2306 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
2053 for sitedir in "${dir}"/python*/site-packages; do 2307 for sitedir in "${dir}"/python*/site-packages; do
2054 if [[ -d "${sitedir}" ]]; then 2308 if [[ -d "${sitedir}" ]]; then
2055 SEARCH_PATH+=("${sitedir}") 2309 search_paths+=("${sitedir}")
2056 fi 2310 fi
2057 done 2311 done
2058 fi 2312 fi
2059 done 2313 done
2060 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2314 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do
2061 if [[ -d "${sitedir}" ]]; then 2315 if [[ -d "${sitedir}" ]]; then
2062 SEARCH_PATH+=("${sitedir}") 2316 search_paths+=("${sitedir}")
2063 fi 2317 fi
2064 done 2318 done
2065 fi 2319 fi
2066 2320
2067 for path in "${SEARCH_PATH[@]}"; do 2321 _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} 2322}
2099 2323
2100# ================================================================================================ 2324# ================================================================================================
2101# ===================================== DEPRECATED FUNCTIONS ===================================== 2325# ===================================== DEPRECATED FUNCTIONS =====================================
2102# ================================================================================================ 2326# ================================================================================================
2156 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2380 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}()." 2381 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2158 die "${FUNCNAME}() cannot be used in this EAPI" 2382 die "${FUNCNAME}() cannot be used in this EAPI"
2159 fi 2383 fi
2160 2384
2385 _python_set_color_variables
2386
2161 echo 2387 echo
2162 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" 2388 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}" 2389 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}" 2390 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2165 echo 2391 echo
2166 2392
2167 einfo &> /dev/null 2393 eerror &> /dev/null
2168 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null 2394 eerror "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 2395 eerror "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 2396 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2171 einfo &> /dev/null 2397 eerror &> /dev/null
2172 2398
2173 if [[ "$#" -ne 1 ]]; then 2399 if [[ "$#" -ne 1 ]]; then
2174 die "${FUNCNAME}() requires 1 argument" 2400 die "${FUNCNAME}() requires 1 argument"
2175 fi 2401 fi
2176 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null 2402 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2184 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2410 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}()." 2411 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2186 die "${FUNCNAME}() cannot be used in this EAPI" 2412 die "${FUNCNAME}() cannot be used in this EAPI"
2187 fi 2413 fi
2188 2414
2415 _python_set_color_variables
2416
2189 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then 2417 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2190 echo 2418 echo
2191 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" 2419 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}" 2420 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}" 2421 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2194 echo 2422 echo
2195 2423
2196 einfo &> /dev/null 2424 eerror &> /dev/null
2197 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null 2425 eerror "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 2426 eerror "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 2427 eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2200 einfo &> /dev/null 2428 eerror &> /dev/null
2201 fi 2429 fi
2202 2430
2203 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2431 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2204if version_info[0] == 3: 2432if version_info[0] == 3:
2205 import tkinter 2433 import tkinter
2226 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." 2454 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2227 die "${FUNCNAME}() cannot be used in this EAPI" 2455 die "${FUNCNAME}() cannot be used in this EAPI"
2228 fi 2456 fi
2229 2457
2230 _python_initialize_prefix_variables 2458 _python_initialize_prefix_variables
2459 _python_set_color_variables
2460
2461 if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then
2462 echo
2463 echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}"
2464 echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}"
2465 echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}"
2466 echo
2467
2468 einfo &> /dev/null
2469 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null
2470 einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null
2471 einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null
2472 einfo &> /dev/null
2473 fi
2231 2474
2232 local f myroot myfiles=() 2475 local f myroot myfiles=()
2233 2476
2234 # Check if phase is pkg_postinst() 2477 # Check if phase is pkg_postinst()
2235 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2478 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2236 2479
2237 # strip trailing slash 2480 # strip trailing slash
2238 myroot="${EROOT%/}" 2481 myroot="${EROOT%/}"
2239 2482
2240 # respect ROOT 2483 # respect EROOT
2241 for f in "$@"; do 2484 for f in "$@"; do
2242 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 2485 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
2243 done 2486 done
2487
2488 PYTHON_ABI="$(PYTHON --ABI)"
2244 2489
2245 if ((${#myfiles[@]})); then 2490 if ((${#myfiles[@]})); then
2246 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" 2491 "$(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 2492 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
2493 _python_clean_compiled_modules "${myfiles[@]}"
2248 else 2494 else
2249 ewarn "No files to compile!" 2495 ewarn "No files to compile!"
2250 fi 2496 fi
2251} 2497}

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

  ViewVC Help
Powered by ViewVC 1.1.20