| 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.103 2010/10/03 00:38:13 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.105 2010/10/29 19:09:08 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 |
| … | |
… | |
| 16 | fi |
16 | fi |
| 17 | |
17 | |
| 18 | _CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
18 | _CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 19 | _CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) |
19 | _CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2) |
| 20 | _JYTHON_SUPPORTED_ABIS=(2.5-jython) |
20 | _JYTHON_SUPPORTED_ABIS=(2.5-jython) |
|
|
21 | _PYTHON_SUPPORTED_ABIS=(${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}) |
|
|
22 | |
|
|
23 | # ================================================================================================ |
|
|
24 | # ===================================== HANDLING OF METADATA ===================================== |
|
|
25 | # ================================================================================================ |
| 21 | |
26 | |
| 22 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
27 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
| 23 | # @DESCRIPTION: |
28 | # @DESCRIPTION: |
| 24 | # Specification of dependency on dev-lang/python. |
29 | # Specification of dependency on dev-lang/python. |
| 25 | # Syntax: |
30 | # Syntax: |
| … | |
… | |
| 27 | # version_components_group: <major_version[:[minimal_version][:maximal_version]]> |
32 | # version_components_group: <major_version[:[minimal_version][:maximal_version]]> |
| 28 | # major_version: <2|3|*> |
33 | # major_version: <2|3|*> |
| 29 | # minimal_version: <minimal_major_version.minimal_minor_version> |
34 | # minimal_version: <minimal_major_version.minimal_minor_version> |
| 30 | # maximal_version: <maximal_major_version.maximal_minor_version> |
35 | # maximal_version: <maximal_major_version.maximal_minor_version> |
| 31 | |
36 | |
| 32 | _parse_PYTHON_DEPEND() { |
37 | _python_parse_PYTHON_DEPEND() { |
| 33 | local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups |
38 | local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups |
| 34 | |
39 | |
| 35 | version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" |
40 | version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" |
| 36 | version_components_groups="${PYTHON_DEPEND}" |
41 | version_components_groups="${PYTHON_DEPEND}" |
| 37 | |
42 | |
| … | |
… | |
| 153 | } |
158 | } |
| 154 | |
159 | |
| 155 | DEPEND=">=app-admin/eselect-python-20091230" |
160 | DEPEND=">=app-admin/eselect-python-20091230" |
| 156 | RDEPEND="${DEPEND}" |
161 | RDEPEND="${DEPEND}" |
| 157 | |
162 | |
| 158 | if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then |
|
|
| 159 | die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" |
|
|
| 160 | elif [[ -n "${PYTHON_DEPEND}" ]]; then |
163 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
| 161 | _parse_PYTHON_DEPEND |
164 | _python_parse_PYTHON_DEPEND |
| 162 | elif [[ -n "${NEED_PYTHON}" ]]; then |
|
|
| 163 | if ! has "${EAPI:-0}" 0 1 2; then |
|
|
| 164 | eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
| 165 | die "NEED_PYTHON variable cannot be used in this EAPI" |
|
|
| 166 | fi |
|
|
| 167 | |
|
|
| 168 | ewarn |
|
|
| 169 | ewarn "\"${EBUILD}\":" |
|
|
| 170 | ewarn "Deprecation Warning: NEED_PYTHON variable is deprecated and will be banned on 2010-10-01." |
|
|
| 171 | ewarn "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
| 172 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 173 | ewarn |
|
|
| 174 | |
|
|
| 175 | unset _BOLD _NORMAL |
|
|
| 176 | |
|
|
| 177 | _PYTHON_ATOMS=(">=dev-lang/python-${NEED_PYTHON}") |
|
|
| 178 | DEPEND+="${DEPEND:+ }${_PYTHON_ATOMS[@]}" |
|
|
| 179 | RDEPEND+="${RDEPEND:+ }${_PYTHON_ATOMS[@]}" |
|
|
| 180 | else |
165 | else |
| 181 | _PYTHON_ATOMS=("dev-lang/python") |
166 | _PYTHON_ATOMS=("dev-lang/python") |
|
|
167 | fi |
|
|
168 | unset -f _python_parse_PYTHON_DEPEND |
|
|
169 | |
|
|
170 | if [[ -n "${NEED_PYTHON}" ]]; then |
|
|
171 | eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable." |
|
|
172 | die "NEED_PYTHON variable is banned" |
| 182 | fi |
173 | fi |
| 183 | |
174 | |
| 184 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
175 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
| 185 | # @DESCRIPTION: |
176 | # @DESCRIPTION: |
| 186 | # Set this to a space separated list of USE flags the Python slot in use must be built with. |
177 | # Set this to a space separated list of USE flags the Python slot in use must be built with. |
| … | |
… | |
| 408 | fi |
399 | fi |
| 409 | |
400 | |
| 410 | PYTHON_PKG_SETUP_EXECUTED="1" |
401 | PYTHON_PKG_SETUP_EXECUTED="1" |
| 411 | } |
402 | } |
| 412 | |
403 | |
| 413 | if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then |
404 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
| 414 | EXPORT_FUNCTIONS pkg_setup |
405 | EXPORT_FUNCTIONS pkg_setup |
| 415 | fi |
406 | fi |
| 416 | |
407 | |
| 417 | # @FUNCTION: python_convert_shebangs |
408 | # @FUNCTION: python_convert_shebangs |
| 418 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
409 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
| … | |
… | |
| 601 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
592 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 602 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
593 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
| 603 | fi |
594 | fi |
| 604 | fi |
595 | fi |
| 605 | |
596 | |
|
|
597 | if has "${EAPI:-0}" 0 1 2 3; then |
| 606 | unset PYTHON_ABIS |
598 | unset PYTHON_ABIS |
|
|
599 | fi |
| 607 | |
600 | |
| 608 | _python_calculate_PYTHON_ABIS() { |
601 | _python_calculate_PYTHON_ABIS() { |
| 609 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
602 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 610 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
603 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 611 | fi |
604 | fi |
| 612 | |
605 | |
| 613 | _python_initial_sanity_checks |
606 | _python_initial_sanity_checks |
| 614 | |
607 | |
| 615 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. |
|
|
| 616 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
608 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then |
| 617 | local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= |
609 | local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS |
| 618 | PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" |
610 | |
|
|
611 | restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}" |
| 619 | |
612 | |
| 620 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
613 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
| 621 | local cpython_enabled="0" |
614 | local cpython_enabled="0" |
| 622 | |
615 | |
| 623 | if [[ -z "${USE_PYTHON}" ]]; then |
616 | if [[ -z "${USE_PYTHON}" ]]; then |
| 624 | die "USE_PYTHON variable is empty" |
617 | die "USE_PYTHON variable is empty" |
| 625 | fi |
618 | fi |
| 626 | |
619 | |
| 627 | for PYTHON_ABI in ${USE_PYTHON}; do |
620 | for PYTHON_ABI in ${USE_PYTHON}; do |
| 628 | if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
621 | if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then |
| 629 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
622 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
| 630 | fi |
623 | fi |
| 631 | |
624 | |
| 632 | if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then |
625 | if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then |
| 633 | cpython_enabled="1" |
626 | cpython_enabled="1" |
| 634 | fi |
627 | fi |
| 635 | |
628 | |
| 636 | support_ABI="1" |
629 | support_ABI="1" |
| 637 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
630 | while read restricted_ABI; do |
| 638 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
631 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
| 639 | support_ABI="0" |
632 | support_ABI="0" |
| 640 | break |
633 | break |
| 641 | fi |
634 | fi |
| 642 | done |
635 | done <<< "${restricted_ABIs}" |
| 643 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
636 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
| 644 | done |
637 | done |
| 645 | |
638 | |
| 646 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
639 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
| 647 | die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" |
640 | die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" |
| … | |
… | |
| 666 | |
659 | |
| 667 | python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
660 | python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| 668 | |
661 | |
| 669 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
662 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
| 670 | support_python_major_version="1" |
663 | support_python_major_version="1" |
| 671 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
664 | while read restricted_ABI; do |
| 672 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
665 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
| 673 | support_python_major_version="0" |
666 | support_python_major_version="0" |
| 674 | fi |
667 | fi |
| 675 | done |
668 | done <<< "${restricted_ABIs}" |
| 676 | [[ "${support_python_major_version}" == "1" ]] && break |
669 | [[ "${support_python_major_version}" == "1" ]] && break |
| 677 | done |
670 | done |
| 678 | if [[ "${support_python_major_version}" == "1" ]]; then |
671 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 679 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
672 | while read restricted_ABI; do |
| 680 | if [[ "${python2_version}" == ${restricted_ABI} ]]; then |
673 | if [[ "${python2_version}" == ${restricted_ABI} ]]; then |
| 681 | die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" |
674 | die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" |
| 682 | fi |
675 | fi |
| 683 | done |
676 | done <<< "${restricted_ABIs}" |
| 684 | else |
677 | else |
| 685 | python2_version="" |
678 | python2_version="" |
| 686 | fi |
679 | fi |
| 687 | fi |
680 | fi |
| 688 | |
681 | |
| … | |
… | |
| 693 | |
686 | |
| 694 | python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
687 | python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| 695 | |
688 | |
| 696 | for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do |
689 | for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do |
| 697 | support_python_major_version="1" |
690 | support_python_major_version="1" |
| 698 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
691 | while read restricted_ABI; do |
| 699 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
692 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
| 700 | support_python_major_version="0" |
693 | support_python_major_version="0" |
| 701 | fi |
694 | fi |
| 702 | done |
695 | done <<< "${restricted_ABIs}" |
| 703 | [[ "${support_python_major_version}" == "1" ]] && break |
696 | [[ "${support_python_major_version}" == "1" ]] && break |
| 704 | done |
697 | done |
| 705 | if [[ "${support_python_major_version}" == "1" ]]; then |
698 | if [[ "${support_python_major_version}" == "1" ]]; then |
| 706 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
699 | while read restricted_ABI; do |
| 707 | if [[ "${python3_version}" == ${restricted_ABI} ]]; then |
700 | if [[ "${python3_version}" == ${restricted_ABI} ]]; then |
| 708 | die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" |
701 | die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" |
| 709 | fi |
702 | fi |
| 710 | done |
703 | done <<< "${restricted_ABIs}" |
| 711 | else |
704 | else |
| 712 | python3_version="" |
705 | python3_version="" |
| 713 | fi |
706 | fi |
| 714 | fi |
707 | fi |
| 715 | |
708 | |
| … | |
… | |
| 1562 | else |
1555 | else |
| 1563 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
1556 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
| 1564 | fi |
1557 | fi |
| 1565 | fi |
1558 | fi |
| 1566 | |
1559 | |
|
|
1560 | if [[ "${EAPI:-0}" == "0" ]]; then |
| 1567 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1561 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1568 | echo "dev-lang/python:${PYTHON_ABI}" |
1562 | echo "=dev-lang/python-${PYTHON_ABI}*" |
| 1569 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1563 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
|
|
1564 | echo "=dev-java/jython-${PYTHON_ABI%-jython}*" |
|
|
1565 | fi |
|
|
1566 | else |
|
|
1567 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
|
|
1568 | echo "dev-lang/python:${PYTHON_ABI}" |
|
|
1569 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| 1570 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
1570 | echo "dev-java/jython:${PYTHON_ABI%-jython}" |
|
|
1571 | fi |
| 1571 | fi |
1572 | fi |
| 1572 | } |
1573 | } |
| 1573 | |
1574 | |
| 1574 | # @FUNCTION: python_get_includedir |
1575 | # @FUNCTION: python_get_includedir |
| 1575 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
1576 | # @USAGE: [-b|--base-path] [-f|--final-ABI] |
| … | |
… | |
| 2114 | |
2115 | |
| 2115 | _python_clean_compiled_modules() { |
2116 | _python_clean_compiled_modules() { |
| 2116 | _python_initialize_prefix_variables |
2117 | _python_initialize_prefix_variables |
| 2117 | _python_set_color_variables |
2118 | _python_set_color_variables |
| 2118 | |
2119 | |
| 2119 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
2120 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
| 2120 | |
2121 | |
| 2121 | local base_module_name compiled_file compiled_files=() dir path py_file root |
2122 | local base_module_name compiled_file compiled_files=() dir path py_file root |
| 2122 | |
2123 | |
| 2123 | # Strip trailing slash from EROOT. |
2124 | # Strip trailing slash from EROOT. |
| 2124 | root="${EROOT%/}" |
2125 | root="${EROOT%/}" |
| … | |
… | |
| 2201 | done |
2202 | done |
| 2202 | done |
2203 | done |
| 2203 | } |
2204 | } |
| 2204 | |
2205 | |
| 2205 | # @FUNCTION: python_mod_optimize |
2206 | # @FUNCTION: python_mod_optimize |
| 2206 | # @USAGE: [options] [directory|file] |
2207 | # @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories] |
| 2207 | # @DESCRIPTION: |
2208 | # @DESCRIPTION: |
| 2208 | # If no arguments supplied, it will recompile not recursively all modules |
2209 | # Byte-compile specified Python modules. |
| 2209 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
|
|
| 2210 | # |
|
|
| 2211 | # If supplied with arguments, it will recompile all modules recursively |
|
|
| 2212 | # in the supplied directory. |
|
|
| 2213 | # |
|
|
| 2214 | # Options passed to this function are passed to compileall.py. |
2210 | # -d, -f, -l, -q and -x options passed to this function are passed to compileall.py. |
| 2215 | # |
2211 | # |
| 2216 | # This function can be used only in pkg_postinst() phase. |
2212 | # This function can be used only in pkg_postinst() phase. |
| 2217 | python_mod_optimize() { |
2213 | python_mod_optimize() { |
| 2218 | _python_check_python_pkg_setup_execution |
2214 | _python_check_python_pkg_setup_execution |
| 2219 | _python_initialize_prefix_variables |
2215 | _python_initialize_prefix_variables |
| 2220 | |
2216 | |
| 2221 | # Check if phase is pkg_postinst(). |
2217 | # Check if phase is pkg_postinst(). |
| 2222 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
2218 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
| 2223 | |
2219 | |
| 2224 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2220 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then |
| 2225 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
2221 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
| 2226 | local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() |
2222 | local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() |
| 2227 | |
2223 | |
| 2228 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2224 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2229 | if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then |
2225 | if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then |
| … | |
… | |
| 2270 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
2266 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2271 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2267 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2272 | fi |
2268 | fi |
| 2273 | |
2269 | |
| 2274 | if [[ "$#" -eq 0 ]]; then |
2270 | if [[ "$#" -eq 0 ]]; then |
| 2275 | ewarn |
2271 | die "${FUNCNAME}(): Missing files or directories" |
| 2276 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
|
|
| 2277 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
|
|
| 2278 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2279 | ewarn |
|
|
| 2280 | fi |
2272 | fi |
| 2281 | |
2273 | |
| 2282 | while (($#)); do |
2274 | while (($#)); do |
| 2283 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2275 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2284 | die "${FUNCNAME}(): Invalid argument '$1'" |
2276 | die "${FUNCNAME}(): Invalid argument '$1'" |
| … | |
… | |
| 2386 | if ((${#other_files[@]})); then |
2378 | if ((${#other_files[@]})); then |
| 2387 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
2379 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 2388 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2380 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 2389 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
2381 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 2390 | fi |
2382 | fi |
| 2391 | _python_clean_compiled_modules "${other_dirs[@]}" |
2383 | _python_clean_compiled_modules "${other_files[@]}" |
| 2392 | fi |
2384 | fi |
| 2393 | eend "${return_code}" |
2385 | eend "${return_code}" |
| 2394 | fi |
2386 | fi |
| 2395 | else |
2387 | else |
| 2396 | # Deprecated part of python_mod_optimize() |
2388 | # Deprecated part of python_mod_optimize() |
|
|
2389 | # ewarn |
|
|
2390 | # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" |
|
|
2391 | # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01." |
|
|
2392 | # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax." |
|
|
2393 | # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
2394 | # ewarn |
| 2397 | |
2395 | |
| 2398 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
2396 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 2399 | |
2397 | |
| 2400 | # strip trailing slash |
2398 | # strip trailing slash |
| 2401 | myroot="${EROOT%/}" |
2399 | myroot="${EROOT%/}" |
| … | |
… | |
| 2423 | esac |
2421 | esac |
| 2424 | shift |
2422 | shift |
| 2425 | done |
2423 | done |
| 2426 | |
2424 | |
| 2427 | if [[ "$#" -eq 0 ]]; then |
2425 | if [[ "$#" -eq 0 ]]; then |
| 2428 | ewarn |
2426 | die "${FUNCNAME}(): Missing files or directories" |
| 2429 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
|
|
| 2430 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
|
|
| 2431 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2432 | ewarn |
|
|
| 2433 | fi |
2427 | fi |
| 2434 | |
2428 | |
| 2435 | while (($#)); do |
2429 | while (($#)); do |
| 2436 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2430 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2437 | die "${FUNCNAME}(): Invalid argument '$1'" |
2431 | die "${FUNCNAME}(): Invalid argument '$1'" |
| 2438 | elif [[ -d "${myroot}/${1#/}" ]]; then |
2432 | elif [[ -d "${myroot}/${1#/}" ]]; then |
| 2439 | mydirs+=("${myroot}/${1#/}") |
2433 | mydirs+=("${myroot}/${1#/}") |
| 2440 | elif [[ -f "${myroot}/${1#/}" ]]; then |
2434 | elif [[ -f "${myroot}/${1#/}" ]]; then |
| 2441 | # Files are passed to python_mod_compile which is EROOT-aware |
2435 | myfiles+=("${myroot}/${1#/}") |
| 2442 | myfiles+=("$1") |
|
|
| 2443 | elif [[ -e "${myroot}/${1#/}" ]]; then |
2436 | elif [[ -e "${myroot}/${1#/}" ]]; then |
| 2444 | eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" |
2437 | eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" |
| 2445 | else |
2438 | else |
| 2446 | eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" |
2439 | eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" |
| 2447 | fi |
2440 | fi |
| … | |
… | |
| 2459 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
2452 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 2460 | _python_clean_compiled_modules "${mydirs[@]}" |
2453 | _python_clean_compiled_modules "${mydirs[@]}" |
| 2461 | fi |
2454 | fi |
| 2462 | |
2455 | |
| 2463 | if ((${#myfiles[@]})); then |
2456 | if ((${#myfiles[@]})); then |
|
|
2457 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1" |
|
|
2458 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1" |
| 2464 | python_mod_compile "${myfiles[@]}" |
2459 | _python_clean_compiled_modules "${myfiles[@]}" |
| 2465 | fi |
2460 | fi |
| 2466 | |
2461 | |
| 2467 | eend "${return_code}" |
2462 | eend "${return_code}" |
| 2468 | fi |
2463 | fi |
| 2469 | } |
2464 | } |
| 2470 | |
2465 | |
| 2471 | # @FUNCTION: python_mod_cleanup |
2466 | # @FUNCTION: python_mod_cleanup |
| 2472 | # @USAGE: [directory|file] |
2467 | # @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories] |
| 2473 | # @DESCRIPTION: |
2468 | # @DESCRIPTION: |
| 2474 | # Run with optional arguments, where arguments are Python modules. If none given, |
2469 | # Delete orphaned byte-compiled Python modules corresponding to specified Python modules. |
| 2475 | # it will look in /usr/lib/python[0-9].[0-9]. |
|
|
| 2476 | # |
|
|
| 2477 | # It will recursively scan all compiled Python modules in the directories and |
|
|
| 2478 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
|
|
| 2479 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
|
|
| 2480 | # |
2470 | # |
| 2481 | # This function can be used only in pkg_postrm() phase. |
2471 | # This function can be used only in pkg_postrm() phase. |
| 2482 | python_mod_cleanup() { |
2472 | python_mod_cleanup() { |
| 2483 | _python_check_python_pkg_setup_execution |
2473 | _python_check_python_pkg_setup_execution |
| 2484 | _python_initialize_prefix_variables |
2474 | _python_initialize_prefix_variables |
| … | |
… | |
| 2525 | |
2515 | |
| 2526 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
2516 | if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 2527 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
2517 | die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 2528 | fi |
2518 | fi |
| 2529 | |
2519 | |
| 2530 | if [[ "$#" -gt 0 ]]; then |
2520 | if [[ "$#" -eq 0 ]]; then |
| 2531 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2521 | die "${FUNCNAME}(): Missing files or directories" |
|
|
2522 | fi |
|
|
2523 | |
|
|
2524 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then |
| 2532 | while (($#)); do |
2525 | while (($#)); do |
| 2533 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
2526 | if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then |
| 2534 | die "${FUNCNAME}(): Invalid argument '$1'" |
2527 | die "${FUNCNAME}(): Invalid argument '$1'" |
| 2535 | elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
2528 | elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
| 2536 | die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" |
2529 | die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" |
| 2537 | elif [[ "$1" =~ ^/ ]]; then |
2530 | elif [[ "$1" =~ ^/ ]]; then |
| 2538 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2531 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2539 | if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then |
2532 | if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then |
| 2540 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
2533 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 2541 | fi |
|
|
| 2542 | if [[ "$1" != *\$* ]]; then |
|
|
| 2543 | die "${FUNCNAME}(): '$1' has invalid syntax" |
|
|
| 2544 | fi |
|
|
| 2545 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
|
|
| 2546 | eval "search_paths+=(\"\${root}$1\")" |
|
|
| 2547 | done |
|
|
| 2548 | else |
|
|
| 2549 | search_paths+=("${root}$1") |
|
|
| 2550 | fi |
2534 | fi |
|
|
2535 | if [[ "$1" != *\$* ]]; then |
|
|
2536 | die "${FUNCNAME}(): '$1' has invalid syntax" |
|
|
2537 | fi |
|
|
2538 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
|
|
2539 | eval "search_paths+=(\"\${root}$1\")" |
|
|
2540 | done |
| 2551 | else |
2541 | else |
|
|
2542 | search_paths+=("${root}$1") |
|
|
2543 | fi |
|
|
2544 | else |
| 2552 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
2545 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 2553 | search_paths+=("${root}$(python_get_sitedir)/$1") |
2546 | search_paths+=("${root}$(python_get_sitedir)/$1") |
| 2554 | done |
|
|
| 2555 | fi |
|
|
| 2556 | shift |
|
|
| 2557 | done |
|
|
| 2558 | else |
|
|
| 2559 | # Deprecated part of python_mod_cleanup() |
|
|
| 2560 | |
|
|
| 2561 | search_paths=("${@#/}") |
|
|
| 2562 | search_paths=("${search_paths[@]/#/${root}/}") |
|
|
| 2563 | fi |
|
|
| 2564 | else |
|
|
| 2565 | ewarn |
|
|
| 2566 | ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" |
|
|
| 2567 | ewarn "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." |
|
|
| 2568 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2569 | ewarn |
|
|
| 2570 | |
|
|
| 2571 | for dir in "${root}"/usr/lib*; do |
|
|
| 2572 | if [[ -d "${dir}" && ! -L "${dir}" ]]; then |
|
|
| 2573 | for sitedir in "${dir}"/python*/site-packages; do |
|
|
| 2574 | if [[ -d "${sitedir}" ]]; then |
|
|
| 2575 | search_paths+=("${sitedir}") |
|
|
| 2576 | fi |
|
|
| 2577 | done |
2547 | done |
| 2578 | fi |
2548 | fi |
|
|
2549 | shift |
| 2579 | done |
2550 | done |
| 2580 | for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do |
2551 | else |
| 2581 | if [[ -d "${sitedir}" ]]; then |
2552 | # Deprecated part of python_mod_cleanup() |
|
|
2553 | # ewarn |
|
|
2554 | # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation" |
|
|
2555 | # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01." |
|
|
2556 | # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax." |
|
|
2557 | # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
2558 | # ewarn |
|
|
2559 | |
| 2582 | search_paths+=("${sitedir}") |
2560 | search_paths=("${@#/}") |
| 2583 | fi |
2561 | search_paths=("${search_paths[@]/#/${root}/}") |
| 2584 | done |
|
|
| 2585 | fi |
2562 | fi |
| 2586 | |
2563 | |
| 2587 | _python_clean_compiled_modules "${search_paths[@]}" |
2564 | _python_clean_compiled_modules "${search_paths[@]}" |
| 2588 | } |
2565 | } |
| 2589 | |
2566 | |
| … | |
… | |
| 2607 | python_tkinter_exists() { |
2584 | python_tkinter_exists() { |
| 2608 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
2585 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
| 2609 | die "${FUNCNAME}() is banned" |
2586 | die "${FUNCNAME}() is banned" |
| 2610 | } |
2587 | } |
| 2611 | |
2588 | |
| 2612 | # @FUNCTION: python_mod_compile |
2589 | # Scheduled for deletion on 2011-04-01. |
| 2613 | # @USAGE: <file> [more files ...] |
|
|
| 2614 | # @DESCRIPTION: |
|
|
| 2615 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
|
|
| 2616 | # This function can be used only in pkg_postinst() phase. |
|
|
| 2617 | # |
|
|
| 2618 | # Example: |
|
|
| 2619 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
|
|
| 2620 | # |
|
|
| 2621 | python_mod_compile() { |
2590 | python_mod_compile() { |
| 2622 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
| 2623 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
2591 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
| 2624 | die "${FUNCNAME}() cannot be used in this EAPI" |
2592 | die "${FUNCNAME}() is banned" |
| 2625 | fi |
|
|
| 2626 | |
|
|
| 2627 | _python_initialize_prefix_variables |
|
|
| 2628 | _python_set_color_variables |
|
|
| 2629 | |
|
|
| 2630 | if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then |
|
|
| 2631 | ewarn |
|
|
| 2632 | ewarn "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." |
|
|
| 2633 | ewarn "Use python_mod_optimize() instead of ${FUNCNAME}()." |
|
|
| 2634 | ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." |
|
|
| 2635 | ewarn |
|
|
| 2636 | fi |
|
|
| 2637 | |
|
|
| 2638 | local f myroot myfiles=() |
|
|
| 2639 | |
|
|
| 2640 | # Check if phase is pkg_postinst() |
|
|
| 2641 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
|
|
| 2642 | |
|
|
| 2643 | # strip trailing slash |
|
|
| 2644 | myroot="${EROOT%/}" |
|
|
| 2645 | |
|
|
| 2646 | # respect EROOT |
|
|
| 2647 | for f in "$@"; do |
|
|
| 2648 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
|
|
| 2649 | done |
|
|
| 2650 | |
|
|
| 2651 | PYTHON_ABI="$(PYTHON --ABI)" |
|
|
| 2652 | |
|
|
| 2653 | if ((${#myfiles[@]})); then |
|
|
| 2654 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
|
|
| 2655 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
|
|
| 2656 | _python_clean_compiled_modules "${myfiles[@]}" |
|
|
| 2657 | else |
|
|
| 2658 | ewarn "No files to compile!" |
|
|
| 2659 | fi |
|
|
| 2660 | } |
2593 | } |