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.150 2012/02/13 23:50:12 zmedico Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.157 2012/08/16 23:57:32 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 |
… | |
… | |
28 | fi |
28 | fi |
29 | |
29 | |
30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9) |
34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
35 | |
35 | |
36 | # ================================================================================================ |
36 | # ================================================================================================ |
37 | # ===================================== HANDLING OF METADATA ===================================== |
37 | # ===================================== HANDLING OF METADATA ===================================== |
38 | # ================================================================================================ |
38 | # ================================================================================================ |
… | |
… | |
98 | |
98 | |
99 | return 1 |
99 | return 1 |
100 | fi |
100 | fi |
101 | } |
101 | } |
102 | |
102 | |
|
|
103 | _python_implementation() { |
|
|
104 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
105 | return 0 |
|
|
106 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
107 | return 0 |
|
|
108 | elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then |
|
|
109 | return 0 |
|
|
110 | else |
|
|
111 | return 1 |
|
|
112 | fi |
|
|
113 | } |
|
|
114 | |
103 | _python_package_supporting_installation_for_multiple_python_abis() { |
115 | _python_package_supporting_installation_for_multiple_python_abis() { |
104 | if has "${EAPI:-0}" 0 1 2 3 4; then |
116 | if has "${EAPI:-0}" 0 1 2 3 4; then |
105 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
117 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
106 | return 0 |
118 | return 0 |
107 | else |
119 | else |
… | |
… | |
243 | else |
255 | else |
244 | die "Invalid syntax of PYTHON_DEPEND" |
256 | die "Invalid syntax of PYTHON_DEPEND" |
245 | fi |
257 | fi |
246 | } |
258 | } |
247 | |
259 | |
|
|
260 | if _python_implementation; then |
248 | DEPEND=">=app-admin/eselect-python-20091230" |
261 | DEPEND=">=app-admin/eselect-python-20091230" |
249 | RDEPEND="${DEPEND}" |
262 | RDEPEND="${DEPEND}" |
|
|
263 | PDEPEND="app-admin/python-updater" |
|
|
264 | fi |
250 | |
265 | |
251 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
266 | if [[ -n "${PYTHON_DEPEND}" ]]; then |
252 | _python_parse_PYTHON_DEPEND |
267 | _python_parse_PYTHON_DEPEND |
253 | else |
268 | else |
254 | _PYTHON_ATOMS=("dev-lang/python") |
269 | _PYTHON_ATOMS=("dev-lang/python") |
… | |
… | |
293 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
308 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
294 | fi |
309 | fi |
295 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
310 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
296 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
311 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
297 | fi |
312 | fi |
298 | DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
313 | DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
299 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
314 | RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}" |
300 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
315 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
301 | fi |
316 | fi |
302 | |
317 | |
303 | unset _PYTHON_ATOMS |
318 | unset _PYTHON_ATOMS |
304 | |
319 | |
305 | # ================================================================================================ |
320 | # ================================================================================================ |
306 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
321 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
307 | # ================================================================================================ |
322 | # ================================================================================================ |
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 | |
323 | |
321 | _python_abi-specific_local_scope() { |
324 | _python_abi-specific_local_scope() { |
322 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
325 | [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |
323 | } |
326 | } |
324 | |
327 | |
… | |
… | |
842 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
845 | die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}" |
843 | fi |
846 | fi |
844 | else |
847 | else |
845 | python3_version="" |
848 | python3_version="" |
846 | fi |
849 | fi |
|
|
850 | fi |
|
|
851 | |
|
|
852 | if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then |
|
|
853 | eerror "${CATEGORY}/${PF} requires at least one of the following packages:" |
|
|
854 | for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do |
|
|
855 | if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then |
|
|
856 | eerror " dev-lang/python:${PYTHON_ABI}" |
|
|
857 | fi |
|
|
858 | done |
|
|
859 | die "No supported version of CPython installed" |
847 | fi |
860 | fi |
848 | |
861 | |
849 | if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then |
862 | 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" |
863 | eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink" |
851 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
864 | eerror "is set incorrectly. Use \`eselect python\` to fix configuration." |
… | |
… | |
1009 | python_default_function() { |
1022 | python_default_function() { |
1010 | emake "$@" |
1023 | emake "$@" |
1011 | } |
1024 | } |
1012 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1025 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
1013 | python_default_function() { |
1026 | python_default_function() { |
|
|
1027 | # Stolen from portage's _eapi0_src_test() |
|
|
1028 | local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}" |
1014 | if emake -j1 -n check &> /dev/null; then |
1029 | if ${emake_cmd} -j1 -n check &> /dev/null; then |
1015 | emake -j1 check "$@" |
1030 | ${emake_cmd} -j1 check "$@" |
1016 | elif emake -j1 -n test &> /dev/null; then |
1031 | elif ${emake_cmd} -j1 -n test &> /dev/null; then |
1017 | emake -j1 test "$@" |
1032 | ${emake_cmd} -j1 test "$@" |
1018 | fi |
1033 | fi |
1019 | } |
1034 | } |
1020 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1035 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
1021 | python_default_function() { |
1036 | python_default_function() { |
1022 | emake DESTDIR="${D}" install "$@" |
1037 | emake DESTDIR="${D}" install "$@" |
… | |
… | |
1290 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
1305 | 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)") |
1306 | 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$") |
1307 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1293 | |
1308 | |
1294 | pypy_versions_mapping = { |
1309 | pypy_versions_mapping = { |
1295 | "1.5": "2.7" |
1310 | "1.5": "2.7", |
|
|
1311 | "1.6": "2.7", |
|
|
1312 | "1.7": "2.7", |
|
|
1313 | "1.8": "2.7", |
|
|
1314 | "1.9": "2.7", |
1296 | } |
1315 | } |
1297 | |
1316 | |
1298 | def get_PYTHON_ABI(python_interpreter): |
1317 | def get_PYTHON_ABI(python_interpreter): |
1299 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
1318 | cpython_matched = cpython_interpreter_re.match(python_interpreter) |
1300 | jython_matched = jython_interpreter_re.match(python_interpreter) |
1319 | jython_matched = jython_interpreter_re.match(python_interpreter) |
… | |
… | |
2692 | fi |
2711 | fi |
2693 | |
2712 | |
2694 | export PYTHONDONTWRITEBYTECODE="1" |
2713 | export PYTHONDONTWRITEBYTECODE="1" |
2695 | } |
2714 | } |
2696 | |
2715 | |
|
|
2716 | _python_vecho() { |
|
|
2717 | [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@" |
|
|
2718 | } |
|
|
2719 | |
2697 | _python_clean_compiled_modules() { |
2720 | _python_clean_compiled_modules() { |
2698 | _python_initialize_prefix_variables |
2721 | _python_initialize_prefix_variables |
2699 | _python_set_color_variables |
2722 | _python_set_color_variables |
2700 | |
2723 | |
2701 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
2724 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
… | |
… | |
2714 | |
2737 | |
2715 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
2738 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
2716 | # Delete empty child directories. |
2739 | # Delete empty child directories. |
2717 | find "${path}" -type d | sort -r | while read -r dir; do |
2740 | find "${path}" -type d | sort -r | while read -r dir; do |
2718 | if rmdir "${dir}" 2> /dev/null; then |
2741 | if rmdir "${dir}" 2> /dev/null; then |
2719 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2742 | _python_vecho "<<< ${dir}" |
2720 | fi |
2743 | fi |
2721 | done |
2744 | done |
2722 | fi |
2745 | fi |
2723 | elif [[ "${path}" == *.py ]]; then |
2746 | elif [[ "${path}" == *.py ]]; then |
2724 | base_module_name="${path##*/}" |
2747 | base_module_name="${path##*/}" |
… | |
… | |
2747 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2770 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2748 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2771 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2749 | else |
2772 | else |
2750 | [[ -f "${py_file}" ]] && continue |
2773 | [[ -f "${py_file}" ]] && continue |
2751 | fi |
2774 | fi |
2752 | echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" |
2775 | _python_vecho "<<< ${compiled_file%[co]}[co]" |
2753 | rm -f "${compiled_file%[co]}"[co] |
2776 | rm -f "${compiled_file%[co]}"[co] |
2754 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
2777 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
2755 | if [[ "${dir}" == "__pycache__" ]]; then |
2778 | if [[ "${dir}" == "__pycache__" ]]; then |
2756 | base_module_name="${compiled_file##*/}" |
2779 | base_module_name="${compiled_file##*/}" |
2757 | base_module_name="${base_module_name%\$py.class}" |
2780 | base_module_name="${base_module_name%\$py.class}" |
… | |
… | |
2762 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2785 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
2763 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2786 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
2764 | else |
2787 | else |
2765 | [[ -f "${py_file}" ]] && continue |
2788 | [[ -f "${py_file}" ]] && continue |
2766 | fi |
2789 | fi |
2767 | echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" |
2790 | _python_vecho "<<< ${compiled_file}" |
2768 | rm -f "${compiled_file}" |
2791 | rm -f "${compiled_file}" |
2769 | else |
2792 | else |
2770 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
2793 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
2771 | fi |
2794 | fi |
2772 | |
2795 | |
2773 | # Delete empty parent directories. |
2796 | # Delete empty parent directories. |
2774 | dir="${compiled_file%/*}" |
2797 | dir="${compiled_file%/*}" |
2775 | while [[ "${dir}" != "${root}" ]]; do |
2798 | while [[ "${dir}" != "${root}" ]]; do |
2776 | if rmdir "${dir}" 2> /dev/null; then |
2799 | if rmdir "${dir}" 2> /dev/null; then |
2777 | echo "${_CYAN}<<< ${dir}${_NORMAL}" |
2800 | _python_vecho "<<< ${dir}" |
2778 | else |
2801 | else |
2779 | break |
2802 | break |
2780 | fi |
2803 | fi |
2781 | dir="${dir%/*}" |
2804 | dir="${dir%/*}" |
2782 | done |
2805 | done |