| 1 | # Copyright 1999-2012 Gentoo Foundation |
1 | # Copyright 1999-2012 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.146 2012/01/30 20:18:38 floppym Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.164 2012/12/20 06:34:57 floppym 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 |
| 9 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 10 | # The python eclass contains miscellaneous, useful functions for Python packages. |
10 | # The python eclass contains miscellaneous, useful functions for Python packages. |
| 11 | |
11 | |
|
|
12 | if [[ ${_PYTHON_UTILS_R1} ]]; then |
|
|
13 | die 'python.eclass can not be used with python-r1 suite eclasses.' |
|
|
14 | fi |
|
|
15 | |
| 12 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
16 | # Must call inherit before EXPORT_FUNCTIONS to avoid QA warning. |
| 13 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
17 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 14 | inherit eutils multilib |
18 | inherit multilib |
| 15 | fi |
19 | fi |
| 16 | |
20 | |
| 17 | # Export pkg_setup every time to avoid issues with eclass inheritance order. |
21 | # Export pkg_setup every time to avoid issues with eclass inheritance order. |
| 18 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
22 | if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then |
| 19 | EXPORT_FUNCTIONS pkg_setup |
23 | EXPORT_FUNCTIONS pkg_setup |
| … | |
… | |
| 21 | |
25 | |
| 22 | # Avoid processing this eclass more than once. |
26 | # Avoid processing this eclass more than once. |
| 23 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
27 | if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then |
| 24 | _PYTHON_ECLASS_INHERITED="1" |
28 | _PYTHON_ECLASS_INHERITED="1" |
| 25 | |
29 | |
| 26 | if ! has "${EAPI:-0}" 0 1 2 3 4; then |
30 | if ! has "${EAPI:-0}" 0 1 2 3 4 5; then |
| 27 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
31 | die "API of python.eclass in EAPI=\"${EAPI}\" not established" |
| 28 | fi |
32 | fi |
| 29 | |
33 | |
| 30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
34 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
35 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3) |
| 32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
36 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7) |
37 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9 2.7-pypy-2.0) |
| 34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
38 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 35 | |
39 | |
| 36 | # ================================================================================================ |
40 | # ================================================================================================ |
| 37 | # ===================================== HANDLING OF METADATA ===================================== |
41 | # ===================================== HANDLING OF METADATA ===================================== |
| 38 | # ================================================================================================ |
42 | # ================================================================================================ |
| … | |
… | |
| 98 | |
102 | |
| 99 | return 1 |
103 | return 1 |
| 100 | fi |
104 | fi |
| 101 | } |
105 | } |
| 102 | |
106 | |
|
|
107 | _python_implementation() { |
|
|
108 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
109 | return 0 |
|
|
110 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
111 | return 0 |
|
|
112 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
113 | return 0 |
|
|
114 | else |
|
|
115 | return 1 |
|
|
116 | fi |
|
|
117 | } |
|
|
118 | |
| 103 | _python_package_supporting_installation_for_multiple_python_abis() { |
119 | _python_package_supporting_installation_for_multiple_python_abis() { |
| 104 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 105 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
120 | [[ -n "${SUPPORT_PYTHON_ABIS}" ]] |
| 106 | return 0 |
|
|
| 107 | else |
|
|
| 108 | return 1 |
|
|
| 109 | fi |
|
|
| 110 | else |
|
|
| 111 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
| 112 | fi |
|
|
| 113 | } |
121 | } |
| 114 | |
122 | |
| 115 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
123 | # @ECLASS-VARIABLE: PYTHON_DEPEND |
| 116 | # @DESCRIPTION: |
124 | # @DESCRIPTION: |
| 117 | # Specification of dependency on dev-lang/python. |
125 | # Specification of dependency on dev-lang/python. |
| … | |
… | |
| 243 | else |
251 | else |
| 244 | die "Invalid syntax of PYTHON_DEPEND" |
252 | die "Invalid syntax of PYTHON_DEPEND" |
| 245 | fi |
253 | fi |
| 246 | } |
254 | } |
| 247 | |
255 | |
|
|
256 | if _python_implementation; then |
| 248 | DEPEND=">=app-admin/eselect-python-20091230" |
257 | DEPEND=">=app-admin/eselect-python-20091230" |
| 249 | RDEPEND="${DEPEND}" |
258 | RDEPEND="${DEPEND}" |
|
|
259 | PDEPEND="app-admin/python-updater" |
|
|
260 | fi |
| 250 | |
261 | |
| 251 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
262 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
| 252 | _python_parse_PYTHON_DEPEND |
263 | _python_parse_PYTHON_DEPEND |
| 253 | else |
264 | else |
| 254 | _PYTHON_ATOMS=("dev-lang/python") |
265 | _PYTHON_ATOMS=("dev-lang/python") |
| … | |
… | |
| 293 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
304 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
| 294 | fi |
305 | fi |
| 295 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
306 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
| 296 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
307 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
| 297 | fi |
308 | fi |
| 298 | DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
309 | DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 299 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
310 | RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
| 300 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
311 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
| 301 | fi |
312 | fi |
| 302 | |
313 | |
| 303 | unset _PYTHON_ATOMS |
314 | unset _PYTHON_ATOMS |
| 304 | |
315 | |
| 305 | # ================================================================================================ |
316 | # ================================================================================================ |
| 306 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
317 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
| 307 | # ================================================================================================ |
318 | # ================================================================================================ |
| 308 | |
|
|
| 309 | _python_implementation() { |
|
|
| 310 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
| 311 | return 0 |
|
|
| 312 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
| 313 | return 0 |
|
|
| 314 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
| 315 | return 0 |
|
|
| 316 | else |
|
|
| 317 | return 1 |
|
|
| 318 | fi |
|
|
| 319 | } |
|
|
| 320 | |
319 | |
| 321 | _python_abi-specific_local_scope() { |
320 | _python_abi-specific_local_scope() { |
| 322 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
321 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
| 323 | } |
322 | } |
| 324 | |
323 | |
| … | |
… | |
| 558 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
557 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
| 559 | fi |
558 | fi |
| 560 | done |
559 | done |
| 561 | |
560 | |
| 562 | if [[ "${shebangs_converted}" == "0" ]]; then |
561 | if [[ "${shebangs_converted}" == "0" ]]; then |
| 563 | eqawarn "${FUNCNAME}(): Python scripts not found" |
562 | ewarn "${FUNCNAME}(): Python scripts not found" |
| 564 | fi |
563 | fi |
| 565 | } |
564 | } |
| 566 | |
565 | |
| 567 | # @FUNCTION: python_clean_py-compile_files |
566 | # @FUNCTION: python_clean_py-compile_files |
| 568 | # @USAGE: [-q|--quiet] |
567 | # @USAGE: [-q|--quiet] |
| … | |
… | |
| 747 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
746 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 748 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
747 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
| 749 | fi |
748 | fi |
| 750 | fi |
749 | fi |
| 751 | |
750 | |
| 752 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 753 | unset PYTHON_ABIS |
751 | unset PYTHON_ABIS |
| 754 | fi |
|
|
| 755 | |
752 | |
| 756 | _python_calculate_PYTHON_ABIS() { |
753 | _python_calculate_PYTHON_ABIS() { |
| 757 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
754 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 758 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
755 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 759 | fi |
756 | fi |
| 760 | |
757 | |
| 761 | _python_initial_sanity_checks |
758 | _python_initial_sanity_checks |
| 762 | |
759 | |
| 763 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
760 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then |
| 764 | local PYTHON_ABI |
761 | local PYTHON_ABI |
| 765 | |
762 | |
| 766 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
763 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
| 767 | local cpython_enabled="0" |
764 | local cpython_enabled="0" |
| 768 | |
765 | |
| … | |
… | |
| 842 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
839 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
| 843 | fi |
840 | fi |
| 844 | else |
841 | else |
| 845 | python3_version="" |
842 | python3_version="" |
| 846 | fi |
843 | fi |
|
|
844 | fi |
|
|
845 | |
|
|
846 | if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then |
|
|
847 | eerror "${CATEGORY}/${PF} requires at least one of the following packages:" |
|
|
848 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
849 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
|
|
850 | eerror " dev-lang/python:${PYTHON_ABI}" |
|
|
851 | fi |
|
|
852 | done |
|
|
853 | die "No supported version of CPython installed" |
| 847 | fi |
854 | fi |
| 848 | |
855 | |
| 849 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
856 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
| 850 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
857 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
| 851 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
858 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
| … | |
… | |
| 1009 | python_default_function() { |
1016 | python_default_function() { |
| 1010 | emake "$@" |
1017 | emake "$@" |
| 1011 | } |
1018 | } |
| 1012 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1019 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| 1013 | python_default_function() { |
1020 | python_default_function() { |
|
|
1021 | # Stolen from portage's _eapi0_src_test() |
|
|
1022 | local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}" |
| 1014 | if emake -j1 -n check &> /dev/null; then |
1023 | if ${emake_cmd} -j1 -n check &> /dev/null; then |
| 1015 | emake -j1 check "$@" |
1024 | ${emake_cmd} -j1 check "$@" |
| 1016 | elif emake -j1 -n test &> /dev/null; then |
1025 | elif ${emake_cmd} -j1 -n test &> /dev/null; then |
| 1017 | emake -j1 test "$@" |
1026 | ${emake_cmd} -j1 test "$@" |
| 1018 | fi |
1027 | fi |
| 1019 | } |
1028 | } |
| 1020 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1029 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
| 1021 | python_default_function() { |
1030 | python_default_function() { |
| 1022 | emake DESTDIR="${D}" install "$@" |
1031 | emake DESTDIR="${D}" install "$@" |
| … | |
… | |
| 1289 | pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$") |
1298 | pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$") |
| 1290 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
1299 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
| 1291 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
1300 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
| 1292 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1301 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 1293 | |
1302 | |
| 1294 | pypy_versions_mapping = { |
1303 | #pypy_versions_mapping = { |
| 1295 | "1.5": "2.7" |
1304 | # "1.5": "2.7", |
| 1296 | } |
1305 | # "1.6": "2.7", |
|
|
1306 | # "1.7": "2.7", |
|
|
1307 | # "1.8": "2.7", |
|
|
1308 | # "1.9": "2.7", |
|
|
1309 | # "2.0": "2.7", |
|
|
1310 | #} |
| 1297 | |
1311 | |
| 1298 | def get_PYTHON_ABI(python_interpreter): |
1312 | def get_PYTHON_ABI(python_interpreter): |
| 1299 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
1313 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
| 1300 | jython_matched = jython_interpreter_re.match(python_interpreter) |
1314 | jython_matched = jython_interpreter_re.match(python_interpreter) |
| 1301 | pypy_matched = pypy_interpreter_re.match(python_interpreter) |
1315 | pypy_matched = pypy_interpreter_re.match(python_interpreter) |
| 1302 | if cpython_matched is not None: |
1316 | if cpython_matched is not None: |
| 1303 | PYTHON_ABI = cpython_matched.group(1) |
1317 | PYTHON_ABI = cpython_matched.group(1) |
| 1304 | elif jython_matched is not None: |
1318 | elif jython_matched is not None: |
| 1305 | PYTHON_ABI = jython_matched.group(1) + "-jython" |
1319 | PYTHON_ABI = jython_matched.group(1) + "-jython" |
| 1306 | elif pypy_matched is not None: |
1320 | elif pypy_matched is not None: |
| 1307 | PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1) |
1321 | #PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1) |
|
|
1322 | PYTHON_ABI = "2.7-pypy-" + pypy_matched.group(1) |
| 1308 | else: |
1323 | else: |
| 1309 | PYTHON_ABI = None |
1324 | PYTHON_ABI = None |
| 1310 | return PYTHON_ABI |
1325 | return PYTHON_ABI |
| 1311 | |
1326 | |
| 1312 | def get_python_interpreter(PYTHON_ABI): |
1327 | def get_python_interpreter(PYTHON_ABI): |
| … | |
… | |
| 2692 | fi |
2707 | fi |
| 2693 | |
2708 | |
| 2694 | export PYTHONDONTWRITEBYTECODE="1" |
2709 | export PYTHONDONTWRITEBYTECODE="1" |
| 2695 | } |
2710 | } |
| 2696 | |
2711 | |
|
|
2712 | _python_vecho() { |
|
|
2713 | [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@" |
|
|
2714 | } |
|
|
2715 | |
| 2697 | _python_clean_compiled_modules() { |
2716 | _python_clean_compiled_modules() { |
| 2698 | _python_initialize_prefix_variables |
2717 | _python_initialize_prefix_variables |
| 2699 | _python_set_color_variables |
2718 | _python_set_color_variables |
| 2700 | |
2719 | |
| 2701 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
2720 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
| … | |
… | |
| 2714 | |
2733 | |
| 2715 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
2734 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
| 2716 | # Delete empty child directories. |
2735 | # Delete empty child directories. |
| 2717 | find "${path}" -type d | sort -r | while read -r dir; do |
2736 | find "${path}" -type d | sort -r | while read -r dir; do |
| 2718 | if rmdir "${dir}" 2> /dev/null; then |
2737 | if rmdir "${dir}" 2> /dev/null; then |
| 2719 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2738 | _python_vecho "<<< ${dir}" |
| 2720 | fi |
2739 | fi |
| 2721 | done |
2740 | done |
| 2722 | fi |
2741 | fi |
| 2723 | elif [[ "${path}" == *.py ]]; then |
2742 | elif [[ "${path}" == *.py ]]; then |
| 2724 | base_module_name="${path##*/}" |
2743 | base_module_name="${path##*/}" |
| … | |
… | |
| 2747 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2766 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2748 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2767 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2749 | else |
2768 | else |
| 2750 | [[ -f "${py_file}" ]] && continue |
2769 | [[ -f "${py_file}" ]] && continue |
| 2751 | fi |
2770 | fi |
| 2752 | echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" |
2771 | _python_vecho "<<< ${compiled_file%[co]}[co]" |
| 2753 | rm -f "${compiled_file%[co]}"[co] |
2772 | rm -f "${compiled_file%[co]}"[co] |
| 2754 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
2773 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
| 2755 | if [[ "${dir}" == "__pycache__" ]]; then |
2774 | if [[ "${dir}" == "__pycache__" ]]; then |
| 2756 | base_module_name="${compiled_file##*/}" |
2775 | base_module_name="${compiled_file##*/}" |
| 2757 | base_module_name="${base_module_name%\$py.class}" |
2776 | base_module_name="${base_module_name%\$py.class}" |
| … | |
… | |
| 2762 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2781 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
| 2763 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2782 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
| 2764 | else |
2783 | else |
| 2765 | [[ -f "${py_file}" ]] && continue |
2784 | [[ -f "${py_file}" ]] && continue |
| 2766 | fi |
2785 | fi |
| 2767 | echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" |
2786 | _python_vecho "<<< ${compiled_file}" |
| 2768 | rm -f "${compiled_file}" |
2787 | rm -f "${compiled_file}" |
| 2769 | else |
2788 | else |
| 2770 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
2789 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
| 2771 | fi |
2790 | fi |
| 2772 | |
2791 | |
| 2773 | # Delete empty parent directories. |
2792 | # Delete empty parent directories. |
| 2774 | dir="${compiled_file%/*}" |
2793 | dir="${compiled_file%/*}" |
| 2775 | while [[ "${dir}" != "${root}" ]]; do |
2794 | while [[ "${dir}" != "${root}" ]]; do |
| 2776 | if rmdir "${dir}" 2> /dev/null; then |
2795 | if rmdir "${dir}" 2> /dev/null; then |
| 2777 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2796 | _python_vecho "<<< ${dir}" |
| 2778 | else |
2797 | else |
| 2779 | break |
2798 | break |
| 2780 | fi |
2799 | fi |
| 2781 | dir="${dir%/*}" |
2800 | dir="${dir%/*}" |
| 2782 | done |
2801 | done |