| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2009 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.60 2009/08/05 18:31:30 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.66 2009/08/28 16:08:51 arfrever Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # python@gentoo.org |
7 | # python@gentoo.org |
| 8 | # |
8 | # |
| 9 | # original author: Alastair Tse <liquidx@gentoo.org> |
9 | # original author: Alastair Tse <liquidx@gentoo.org> |
| 10 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
10 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
| 11 | # @DESCRIPTION: |
11 | # @DESCRIPTION: |
| 12 | # Some useful functions for dealing with python. |
12 | # Some useful functions for dealing with Python. |
| 13 | inherit alternatives multilib |
|
|
| 14 | |
13 | |
|
|
14 | inherit multilib |
| 15 | |
15 | |
| 16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
| 17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
| 18 | DEPEND="${PYTHON_ATOM}" |
18 | DEPEND="${PYTHON_ATOM}" |
| 19 | RDEPEND="${DEPEND}" |
19 | RDEPEND="${DEPEND}" |
| 20 | else |
20 | else |
| 21 | PYTHON_ATOM="dev-lang/python" |
21 | PYTHON_ATOM="dev-lang/python" |
| 22 | fi |
22 | fi |
| 23 | |
23 | |
|
|
24 | DEPEND="${DEPEND} >=app-shells/bash-3.2" |
| 24 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
25 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
| 25 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
26 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
| 26 | fi |
27 | fi |
| 27 | |
28 | |
| 28 | __python_eclass_test() { |
29 | __python_eclass_test() { |
| … | |
… | |
| 110 | |
111 | |
| 111 | # @FUNCTION: validate_PYTHON_ABIS |
112 | # @FUNCTION: validate_PYTHON_ABIS |
| 112 | # @DESCRIPTION: |
113 | # @DESCRIPTION: |
| 113 | # Make sure PYTHON_ABIS variable has valid value. |
114 | # Make sure PYTHON_ABIS variable has valid value. |
| 114 | validate_PYTHON_ABIS() { |
115 | validate_PYTHON_ABIS() { |
|
|
116 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. |
|
|
117 | if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
118 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
|
|
119 | fi |
|
|
120 | |
| 115 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
121 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
| 116 | if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then |
122 | if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then |
| 117 | die "/usr/bin/python isn't valid program" |
123 | die "'/usr/bin/python' isn't valid symlink" |
| 118 | fi |
124 | fi |
| 119 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
125 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
| 120 | die "/usr/bin/python-config isn't valid script" |
126 | die "'/usr/bin/python-config' isn't valid script" |
| 121 | fi |
127 | fi |
| 122 | |
128 | |
| 123 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
129 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
| 124 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
130 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
| 125 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
131 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
| … | |
… | |
| 128 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
134 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
| 129 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
135 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
| 130 | continue |
136 | continue |
| 131 | fi |
137 | fi |
| 132 | support_ABI="1" |
138 | support_ABI="1" |
|
|
139 | if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then |
| 133 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
140 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
| 134 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
141 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
| 135 | support_ABI="0" |
142 | support_ABI="0" |
| 136 | break |
143 | break |
| 137 | fi |
144 | fi |
| 138 | done |
145 | done |
|
|
146 | fi |
| 139 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
147 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
| 140 | done |
148 | done |
| 141 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
149 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
| 142 | fi |
150 | fi |
| 143 | |
151 | |
| 144 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
152 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
| 145 | python_version |
153 | python_version |
| 146 | export PYTHON_ABIS="${PYVER}" |
154 | export PYTHON_ABIS="${PYVER}" |
| 147 | fi |
155 | fi |
|
|
156 | |
|
|
157 | # Ensure that EPYTHON variable is respected. |
|
|
158 | local PYTHON_ABI |
|
|
159 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
160 | if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then |
|
|
161 | die "'python' doesn't respect EPYTHON variable" |
|
|
162 | fi |
|
|
163 | done |
| 148 | } |
164 | } |
| 149 | |
165 | |
| 150 | # @FUNCTION: python_copy_sources |
166 | # @FUNCTION: python_copy_sources |
| 151 | # @USAGE: [directory] |
167 | # @USAGE: [directory] |
| 152 | # @DESCRIPTION: |
168 | # @DESCRIPTION: |
| … | |
… | |
| 176 | # @DESCRIPTION: |
192 | # @DESCRIPTION: |
| 177 | # Create build directory symlink. |
193 | # Create build directory symlink. |
| 178 | python_set_build_dir_symlink() { |
194 | python_set_build_dir_symlink() { |
| 179 | local dir="$1" |
195 | local dir="$1" |
| 180 | |
196 | |
| 181 | [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" |
197 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
| 182 | [[ -z "${dir}" ]] && dir="build" |
198 | [[ -z "${dir}" ]] && dir="build" |
| 183 | |
199 | |
| 184 | # Don't delete preexistent directories. |
200 | # Don't delete preexistent directories. |
| 185 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
201 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
| 186 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
202 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
| … | |
… | |
| 239 | if has "${EAPI:-0}" 0 1; then |
255 | if has "${EAPI:-0}" 0 1; then |
| 240 | die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" |
256 | die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" |
| 241 | fi |
257 | fi |
| 242 | |
258 | |
| 243 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
259 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
|
|
260 | if has "${EAPI}" 2; then |
| 244 | python_default_function() { |
261 | python_default_function() { |
| 245 | econf |
262 | econf |
| 246 | } |
263 | } |
|
|
264 | else |
|
|
265 | python_default_function() { |
|
|
266 | nonfatal econf |
|
|
267 | } |
|
|
268 | fi |
| 247 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
269 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
| 248 | python_default_function() { |
270 | python_default_function() { |
| 249 | emake |
271 | emake |
| 250 | } |
272 | } |
| 251 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
273 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| … | |
… | |
| 301 | else |
323 | else |
| 302 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
324 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
| 303 | fi |
325 | fi |
| 304 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
326 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
| 305 | fi |
327 | fi |
|
|
328 | |
| 306 | if [[ "${separate_build_dirs}" == "1" ]]; then |
329 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 307 | export BUILDDIR="${S}-${PYTHON_ABI}" |
330 | export BUILDDIR="${S}-${PYTHON_ABI}" |
| 308 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
331 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
| 309 | else |
332 | else |
| 310 | export BUILDDIR="${S}" |
333 | export BUILDDIR="${S}" |
| 311 | fi |
334 | fi |
|
|
335 | |
|
|
336 | if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
337 | EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" |
|
|
338 | else |
| 312 | if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then |
339 | EPYTHON="$(PYTHON)" "${function}" "$@" |
|
|
340 | fi |
|
|
341 | |
|
|
342 | if [[ "$?" != "0" ]]; then |
| 313 | if [[ -n "${failure_message_template}" ]]; then |
343 | if [[ -n "${failure_message_template}" ]]; then |
| 314 | failure_message="$(eval echo -n "${failure_message_template}")" |
344 | failure_message="$(eval echo -n "${failure_message_template}")" |
| 315 | else |
345 | else |
| 316 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
346 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
| 317 | fi |
347 | fi |
|
|
348 | |
| 318 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
349 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
| 319 | local ABI enabled_PYTHON_ABIS |
350 | local ABI enabled_PYTHON_ABIS |
| 320 | for ABI in ${PYTHON_ABIS}; do |
351 | for ABI in ${PYTHON_ABIS}; do |
| 321 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
352 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
| 322 | done |
353 | done |
| … | |
… | |
| 326 | fi |
357 | fi |
| 327 | else |
358 | else |
| 328 | die "${failure_message}" |
359 | die "${failure_message}" |
| 329 | fi |
360 | fi |
| 330 | fi |
361 | fi |
|
|
362 | |
| 331 | if [[ "${separate_build_dirs}" == "1" ]]; then |
363 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 332 | popd > /dev/null || die "popd failed" |
364 | popd > /dev/null || die "popd failed" |
| 333 | fi |
365 | fi |
| 334 | unset BUILDDIR |
366 | unset BUILDDIR |
| 335 | done |
367 | done |
| … | |
… | |
| 358 | |
390 | |
| 359 | # @FUNCTION: python_pkg_setup |
391 | # @FUNCTION: python_pkg_setup |
| 360 | # @DESCRIPTION: |
392 | # @DESCRIPTION: |
| 361 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
393 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
| 362 | # are respected. Only exported if one of those variables is set. |
394 | # are respected. Only exported if one of those variables is set. |
| 363 | if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
395 | if ! has ${EAPI:-0} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 364 | python_pkg_setup_fail() { |
396 | python_pkg_setup_fail() { |
| 365 | eerror "${1}" |
397 | eerror "${1}" |
| 366 | die "${1}" |
398 | die "${1}" |
| 367 | } |
399 | } |
| 368 | |
400 | |
| … | |
… | |
| 412 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
444 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
| 413 | fi |
445 | fi |
| 414 | |
446 | |
| 415 | # @FUNCTION: python_disable_pyc |
447 | # @FUNCTION: python_disable_pyc |
| 416 | # @DESCRIPTION: |
448 | # @DESCRIPTION: |
| 417 | # Tells python not to automatically recompile modules to .pyc/.pyo |
449 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
| 418 | # even if the timestamps/version stamps don't match. This is done |
450 | # even if the timestamps/version stamps don't match. This is done |
| 419 | # to protect sandbox. |
451 | # to protect sandbox. |
| 420 | # |
|
|
| 421 | # note: supported by >=dev-lang/python-2.2.3-r3 only. |
|
|
| 422 | # |
|
|
| 423 | python_disable_pyc() { |
452 | python_disable_pyc() { |
| 424 | export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above |
453 | export PYTHONDONTWRITEBYTECODE="1" |
| 425 | export PYTHON_DONTCOMPILE=1 # For 2.5 and below |
|
|
| 426 | } |
454 | } |
| 427 | |
455 | |
| 428 | # @FUNCTION: python_enable_pyc |
456 | # @FUNCTION: python_enable_pyc |
| 429 | # @DESCRIPTION: |
457 | # @DESCRIPTION: |
| 430 | # Tells python to automatically recompile modules to .pyc/.pyo if the |
458 | # Tell Python to automatically recompile modules to .pyc/.pyo if the |
| 431 | # timestamps/version stamps change |
459 | # timestamps/version stamps have changed. |
| 432 | python_enable_pyc() { |
460 | python_enable_pyc() { |
| 433 | unset PYTHONDONTWRITEBYTECODE |
461 | unset PYTHONDONTWRITEBYTECODE |
| 434 | unset PYTHON_DONTCOMPILE |
|
|
| 435 | } |
462 | } |
| 436 | |
463 | |
| 437 | python_disable_pyc |
464 | python_disable_pyc |
| 438 | |
465 | |
| 439 | # @FUNCTION: python_need_rebuild |
466 | # @FUNCTION: python_need_rebuild |
| … | |
… | |
| 471 | # @FUNCTION: python_get_sitedir |
498 | # @FUNCTION: python_get_sitedir |
| 472 | # @DESCRIPTION: |
499 | # @DESCRIPTION: |
| 473 | # Run without arguments, returns the Python site-packages directory. |
500 | # Run without arguments, returns the Python site-packages directory. |
| 474 | python_get_sitedir() { |
501 | python_get_sitedir() { |
| 475 | echo "$(python_get_libdir)/site-packages" |
502 | echo "$(python_get_libdir)/site-packages" |
| 476 | } |
|
|
| 477 | |
|
|
| 478 | # @FUNCTION: python_makesym |
|
|
| 479 | # @DESCRIPTION: |
|
|
| 480 | # Run without arguments, it will create the /usr/bin/python symlinks |
|
|
| 481 | # to the latest installed version |
|
|
| 482 | python_makesym() { |
|
|
| 483 | alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]" |
|
|
| 484 | alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]" |
|
|
| 485 | } |
503 | } |
| 486 | |
504 | |
| 487 | # @FUNCTION: python_tkinter_exists |
505 | # @FUNCTION: python_tkinter_exists |
| 488 | # @DESCRIPTION: |
506 | # @DESCRIPTION: |
| 489 | # Run without arguments, checks if python was compiled with Tkinter |
507 | # Run without arguments, checks if python was compiled with Tkinter |
| … | |
… | |
| 550 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
568 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 551 | done |
569 | done |
| 552 | |
570 | |
| 553 | if ((${#myfiles[@]})); then |
571 | if ((${#myfiles[@]})); then |
| 554 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
572 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
| 555 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
573 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null |
| 556 | else |
574 | else |
| 557 | ewarn "No files to compile!" |
575 | ewarn "No files to compile!" |
| 558 | fi |
576 | fi |
| 559 | } |
577 | } |
| 560 | |
578 | |
| … | |
… | |
| 608 | else |
626 | else |
| 609 | ewarn "'${root}/$1' doesn't exist!" |
627 | ewarn "'${root}/$1' doesn't exist!" |
| 610 | fi |
628 | fi |
| 611 | else |
629 | else |
| 612 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
630 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 613 | if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then |
631 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
| 614 | site_packages_dirs+=("$1") |
632 | site_packages_dirs+=("$1") |
| 615 | break |
633 | break |
| 616 | elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then |
634 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
| 617 | site_packages_files+=("$1") |
635 | site_packages_files+=("$1") |
| 618 | break |
636 | break |
| 619 | elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then |
637 | elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then |
| 620 | ewarn "'$1' is not a file or a directory!" |
638 | ewarn "'$1' is not a file or a directory!" |
| 621 | else |
639 | else |
| 622 | ewarn "'$1' doesn't exist!" |
640 | ewarn "'$1' doesn't exist!" |
| 623 | fi |
641 | fi |
| 624 | done |
642 | done |
| … | |
… | |
| 635 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
653 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
| 636 | return_code="0" |
654 | return_code="0" |
| 637 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
655 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
| 638 | if ((${#site_packages_dirs[@]})); then |
656 | if ((${#site_packages_dirs[@]})); then |
| 639 | for dir in "${site_packages_dirs[@]}"; do |
657 | for dir in "${site_packages_dirs[@]}"; do |
| 640 | site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") |
658 | site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") |
| 641 | done |
659 | done |
| 642 | "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
660 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
| 643 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
661 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" |
| 644 | fi |
662 | fi |
| 645 | if ((${#site_packages_files[@]})); then |
663 | if ((${#site_packages_files[@]})); then |
| 646 | for file in "${site_packages_files[@]}"; do |
664 | for file in "${site_packages_files[@]}"; do |
| 647 | site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") |
665 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
| 648 | done |
666 | done |
| 649 | "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
667 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
| 650 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
668 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" |
| 651 | fi |
669 | fi |
| 652 | eend "${return_code}" |
670 | eend "${return_code}" |
| 653 | fi |
671 | fi |
| 654 | unset site_packages_absolute_dirs site_packages_absolute_files |
672 | unset site_packages_absolute_dirs site_packages_absolute_files |
| 655 | done |
673 | done |
| … | |
… | |
| 659 | |
677 | |
| 660 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
678 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 661 | return_code="0" |
679 | return_code="0" |
| 662 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
680 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
| 663 | if ((${#other_dirs[@]})); then |
681 | if ((${#other_dirs[@]})); then |
| 664 | python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
682 | python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 665 | python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
683 | python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 666 | fi |
684 | fi |
| 667 | if ((${#other_files[@]})); then |
685 | if ((${#other_files[@]})); then |
| 668 | python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
686 | python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 669 | python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
687 | python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 670 | fi |
688 | fi |
| 671 | eend "${return_code}" |
689 | eend "${return_code}" |
| 672 | fi |
690 | fi |
| 673 | else |
691 | else |
| 674 | local myroot mydirs=() myfiles=() myopts=() |
692 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 675 | |
693 | |
| 676 | # strip trailing slash |
694 | # strip trailing slash |
| 677 | myroot="${ROOT%/}" |
695 | myroot="${ROOT%/}" |
| 678 | |
696 | |
| 679 | # respect ROOT and options passed to compileall.py |
697 | # respect ROOT and options passed to compileall.py |
| … | |
… | |
| 717 | |
735 | |
| 718 | ebegin "Byte compiling python modules for python-${PYVER} .." |
736 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 719 | if ((${#mydirs[@]})); then |
737 | if ((${#mydirs[@]})); then |
| 720 | python${PYVER} \ |
738 | python${PYVER} \ |
| 721 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
739 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 722 | "${myopts[@]}" "${mydirs[@]}" |
740 | "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 723 | python${PYVER} -O \ |
741 | python${PYVER} -O \ |
| 724 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
742 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 725 | "${myopts[@]}" "${mydirs[@]}" |
743 | "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 726 | fi |
744 | fi |
| 727 | |
745 | |
| 728 | if ((${#myfiles[@]})); then |
746 | if ((${#myfiles[@]})); then |
| 729 | python_mod_compile "${myfiles[@]}" |
747 | python_mod_compile "${myfiles[@]}" |
| 730 | fi |
748 | fi |
| 731 | |
749 | |
| 732 | eend $? |
750 | eend "${return_code}" |
| 733 | fi |
751 | fi |
| 734 | } |
752 | } |
| 735 | |
753 | |
| 736 | # @FUNCTION: python_mod_cleanup |
754 | # @FUNCTION: python_mod_cleanup |
| 737 | # @USAGE: [directory] |
755 | # @USAGE: [directory] |
| … | |
… | |
| 760 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
778 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
| 761 | elif [[ "$1" =~ ^/ ]]; then |
779 | elif [[ "$1" =~ ^/ ]]; then |
| 762 | SEARCH_PATH+=("${root}/${1#/}") |
780 | SEARCH_PATH+=("${root}/${1#/}") |
| 763 | else |
781 | else |
| 764 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
782 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 765 | SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") |
783 | SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
| 766 | done |
784 | done |
| 767 | fi |
785 | fi |
| 768 | shift |
786 | shift |
| 769 | done |
787 | done |
| 770 | else |
788 | else |
| … | |
… | |
| 774 | else |
792 | else |
| 775 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
793 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
| 776 | fi |
794 | fi |
| 777 | |
795 | |
| 778 | for path in "${SEARCH_PATH[@]}"; do |
796 | for path in "${SEARCH_PATH[@]}"; do |
|
|
797 | [[ ! -d "${path}" ]] && continue |
| 779 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
798 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
| 780 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
799 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
| 781 | src_py="${REPLY%[co]}" |
800 | src_py="${REPLY%[co]}" |
| 782 | [[ -f "${src_py}" ]] && continue |
801 | [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue |
| 783 | einfo "Purging ${src_py}[co]" |
802 | einfo "Purging ${src_py}[co]" |
| 784 | rm -f "${src_py}"[co] |
803 | rm -f "${src_py}"[co] |
| 785 | done |
804 | done |
| 786 | |
805 | |
| 787 | # Attempt to remove directories that may be empty. |
806 | # Attempt to remove directories that may be empty. |
| 788 | find "${path}" -type d | sort -r | while read -r dir; do |
807 | find "${path}" -type d | sort -r | while read -r dir; do |
| 789 | rmdir "${dir}" 2>/dev/null |
808 | rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}" |
| 790 | done |
809 | done |
| 791 | done |
810 | done |
| 792 | } |
811 | } |