/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.103 Revision 1.104
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.104 2010/10/25 11:54:19 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
16fi 16fi
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# ================================================================================================
26
27_python_set_IUSE() {
28 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI
29
30 _PYTHON_ABIS_USE_FLAGS=""
31 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
32
33 for PYTHON_ABI in "${_PYTHON_SUPPORTED_ABIS[@]}"; do
34 support_ABI="1"
35 while read restricted_ABI; do
36 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
37 support_ABI="0"
38 break
39 fi
40 done <<< "${restricted_ABIs}"
41 [[ "${support_ABI}" == "1" ]] && _PYTHON_ABIS_USE_FLAGS+="${_PYTHON_ABIS_USE_FLAGS:+ }python_abis_${PYTHON_ABI}"
42 done
43
44 IUSE="${_PYTHON_ABIS_USE_FLAGS}"
45}
46
47if ! has "${EAPI:-0}" 0 1 2 3 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
48 _python_set_IUSE
49fi
50unset -f _python_set_IUSE
21 51
22# @ECLASS-VARIABLE: PYTHON_DEPEND 52# @ECLASS-VARIABLE: PYTHON_DEPEND
23# @DESCRIPTION: 53# @DESCRIPTION:
24# Specification of dependency on dev-lang/python. 54# Specification of dependency on dev-lang/python.
25# Syntax: 55# Syntax:
27# version_components_group: <major_version[:[minimal_version][:maximal_version]]> 57# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
28# major_version: <2|3|*> 58# major_version: <2|3|*>
29# minimal_version: <minimal_major_version.minimal_minor_version> 59# minimal_version: <minimal_major_version.minimal_minor_version>
30# maximal_version: <maximal_major_version.maximal_minor_version> 60# maximal_version: <maximal_major_version.maximal_minor_version>
31 61
32_parse_PYTHON_DEPEND() { 62_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 63 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 64
35 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?" 65 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
36 version_components_groups="${PYTHON_DEPEND}" 66 version_components_groups="${PYTHON_DEPEND}"
37 67
153} 183}
154 184
155DEPEND=">=app-admin/eselect-python-20091230" 185DEPEND=">=app-admin/eselect-python-20091230"
156RDEPEND="${DEPEND}" 186RDEPEND="${DEPEND}"
157 187
158if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then
159 die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously"
160elif [[ -n "${PYTHON_DEPEND}" ]]; then 188if [[ -n "${PYTHON_DEPEND}" ]]; then
161 _parse_PYTHON_DEPEND 189 _python_parse_PYTHON_DEPEND
162elif [[ -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[@]}"
180else 190else
181 _PYTHON_ATOMS=("dev-lang/python") 191 _PYTHON_ATOMS=("dev-lang/python")
192fi
193unset -f _python_parse_PYTHON_DEPEND
194
195if [[ -n "${NEED_PYTHON}" ]]; then
196 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
197 die "NEED_PYTHON variable is banned"
182fi 198fi
183 199
184# @ECLASS-VARIABLE: PYTHON_USE_WITH 200# @ECLASS-VARIABLE: PYTHON_USE_WITH
185# @DESCRIPTION: 201# @DESCRIPTION:
186# Set this to a space separated list of USE flags the Python slot in use must be built with. 202# Set this to a space separated list of USE flags the Python slot in use must be built with.
221 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY 237 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
222fi 238fi
223 239
224unset _PYTHON_ATOMS 240unset _PYTHON_ATOMS
225 241
242# @FUNCTION: python_abi_depend
243# @USAGE: [-e|--exclude-ABIs Python_ABIs] [-i|--include-ABIs Python_ABIs] [--] <dependency_atom> [dependency_atoms]
244# @DESCRIPTION:
245# Print dependency atoms with USE dependencies for Python ABIs added.
246# If --exclude-ABIs option is specified, then Python ABIs matching its argument are not used.
247# If --include-ABIs option is specified, then only Python ABIs matching its argument are used.
248# --exclude-ABIs and --include-ABIs options cannot be specified simultaneously.
249python_abi_depend() {
250 local atom atom_index atoms=() exclude_ABIs="0" excluded_ABI excluded_ABIs include_ABIs="0" included_ABI included_ABIs support_ABI USE_dependencies USE_flag USE_flag_index USE_flags=()
251
252 if has "${EAPI:-0}" 0 1 2 3; then
253 die "${FUNCNAME}() cannot be used in this EAPI"
254 fi
255
256 if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
257 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
258 fi
259
260 while (($#)); do
261 case "$1" in
262 -e|--exclude-ABIs)
263 exclude_ABIs="1"
264 excluded_ABIs="${2// /$'\n'}"
265 shift
266 ;;
267 -i|--include-ABIs)
268 include_ABIs="1"
269 included_ABIs="${2// /$'\n'}"
270 shift
271 ;;
272 --)
273 shift
274 break
275 ;;
276 -*)
277 die "${FUNCNAME}(): Unrecognized option '$1'"
278 ;;
279 *)
280 break
281 ;;
282 esac
283 shift
284 done
285
286 if [[ "${exclude_ABIs}" == "1" && "${include_ABIs}" == "1" ]]; then
287 die "${FUNCNAME}(): '--exclude-ABIs' and '--include-ABIs' options cannot be specified simultaneously"
288 fi
289
290 if [[ "$#" -eq 0 ]]; then
291 die "${FUNCNAME}(): Missing dependency atoms"
292 fi
293
294 atoms=("$@")
295
296 if [[ "${exclude_ABIs}" == "0" && "${include_ABIs}" == "0" ]]; then
297 USE_dependencies="$(printf ",%s?" ${_PYTHON_ABIS_USE_FLAGS})"
298 USE_dependencies="${USE_dependencies#,}"
299
300 for atom_index in "${!atoms[@]}"; do
301 atom="${atoms[${atom_index}]}"
302
303 if [[ "${atom}" == *"["*"]" ]]; then
304 echo -n "${atom%]},"
305 else
306 echo -n "${atom}["
307 fi
308 echo -n "${USE_dependencies}]"
309
310 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
311 echo -n " "
312 fi
313 done
314 else
315 if [[ "${exclude_ABIs}" == "1" ]]; then
316 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
317 while read excluded_ABI; do
318 support_ABI="1"
319 if [[ "${USE_flag}" == python_abis_${excluded_ABI} ]]; then
320 support_ABI="0"
321 break
322 fi
323 done <<< "${excluded_ABIs}"
324 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
325 done
326 elif [[ "${include_ABIs}" == "1" ]]; then
327 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
328 while read included_ABI; do
329 support_ABI="0"
330 if [[ "${USE_flag}" == python_abis_${included_ABI} ]]; then
331 support_ABI="1"
332 break
333 fi
334 done <<< "${included_ABIs}"
335 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
336 done
337 else
338 die "${FUNCNAME}(): Internal error"
339 fi
340
341 for USE_flag_index in "${!USE_flags[@]}"; do
342 USE_flag="${USE_flags[${USE_flag_index}]}"
343 USE_dependencies="${USE_flag}"
344
345 echo -n "${USE_flag}? ( "
346
347 for atom_index in "${!atoms[@]}"; do
348 atom="${atoms[${atom_index}]}"
349
350 if [[ "${atom}" == *"["*"]" ]]; then
351 echo -n "${atom%]},"
352 else
353 echo -n "${atom}["
354 fi
355 echo -n "${USE_dependencies}]"
356
357 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
358 echo -n " "
359 fi
360 done
361
362 echo -n " )"
363
364 if [[ "${USE_flag_index}" -ne $((${#USE_flags[@]} - 1)) ]]; then
365 echo -n " "
366 fi
367 done
368 fi
369}
370
226# ================================================================================================ 371# ================================================================================================
227# =================================== MISCELLANEOUS FUNCTIONS ==================================== 372# =================================== MISCELLANEOUS FUNCTIONS ====================================
228# ================================================================================================ 373# ================================================================================================
229 374
230_python_implementation() { 375_python_implementation() {
408 fi 553 fi
409 554
410 PYTHON_PKG_SETUP_EXECUTED="1" 555 PYTHON_PKG_SETUP_EXECUTED="1"
411} 556}
412 557
413if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then 558if ! 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 559 EXPORT_FUNCTIONS pkg_setup
415fi 560fi
416 561
417# @FUNCTION: python_convert_shebangs 562# @FUNCTION: python_convert_shebangs
418# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 563# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
601 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then 746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
602 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
603 fi 748 fi
604fi 749fi
605 750
751if has "${EAPI:-0}" 0 1 2 3; then
606unset PYTHON_ABIS 752 unset PYTHON_ABIS
753fi
607 754
608_python_calculate_PYTHON_ABIS() { 755_python_calculate_PYTHON_ABIS() {
609 if ! _python_package_supporting_installation_for_multiple_python_abis; then 756 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" 757 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
611 fi 758 fi
612 759
613 _python_initial_sanity_checks 760 _python_initial_sanity_checks
614 761
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 762 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= 763 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[@]}" 764
765 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
619 766
620 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 767 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
621 local cpython_enabled="0" 768 local cpython_enabled="0"
622 769
623 if [[ -z "${USE_PYTHON}" ]]; then 770 if [[ -z "${USE_PYTHON}" ]]; then
624 die "USE_PYTHON variable is empty" 771 die "USE_PYTHON variable is empty"
625 fi 772 fi
626 773
627 for PYTHON_ABI in ${USE_PYTHON}; do 774 for PYTHON_ABI in ${USE_PYTHON}; do
628 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 775 if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then
629 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 776 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
630 fi 777 fi
631 778
632 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then 779 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
633 cpython_enabled="1" 780 cpython_enabled="1"
634 fi 781 fi
635 782
636 support_ABI="1" 783 support_ABI="1"
637 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 784 while read restricted_ABI; do
638 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 785 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
639 support_ABI="0" 786 support_ABI="0"
640 break 787 break
641 fi 788 fi
642 done 789 done <<< "${restricted_ABIs}"
643 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 790 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
644 done 791 done
645 792
646 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 793 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
647 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" 794 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
666 813
667 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 814 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
668 815
669 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do 816 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
670 support_python_major_version="1" 817 support_python_major_version="1"
671 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 818 while read restricted_ABI; do
672 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 819 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
673 support_python_major_version="0" 820 support_python_major_version="0"
674 fi 821 fi
675 done 822 done <<< "${restricted_ABIs}"
676 [[ "${support_python_major_version}" == "1" ]] && break 823 [[ "${support_python_major_version}" == "1" ]] && break
677 done 824 done
678 if [[ "${support_python_major_version}" == "1" ]]; then 825 if [[ "${support_python_major_version}" == "1" ]]; then
679 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 826 while read restricted_ABI; do
680 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 827 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
681 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 828 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
682 fi 829 fi
683 done 830 done <<< "${restricted_ABIs}"
684 else 831 else
685 python2_version="" 832 python2_version=""
686 fi 833 fi
687 fi 834 fi
688 835
693 840
694 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" 841 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
695 842
696 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do 843 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
697 support_python_major_version="1" 844 support_python_major_version="1"
698 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 845 while read restricted_ABI; do
699 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 846 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
700 support_python_major_version="0" 847 support_python_major_version="0"
701 fi 848 fi
702 done 849 done <<< "${restricted_ABIs}"
703 [[ "${support_python_major_version}" == "1" ]] && break 850 [[ "${support_python_major_version}" == "1" ]] && break
704 done 851 done
705 if [[ "${support_python_major_version}" == "1" ]]; then 852 if [[ "${support_python_major_version}" == "1" ]]; then
706 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 853 while read restricted_ABI; do
707 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 854 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
708 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 855 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
709 fi 856 fi
710 done 857 done <<< "${restricted_ABIs}"
711 else 858 else
712 python3_version="" 859 python3_version=""
713 fi 860 fi
714 fi 861 fi
715 862
1562 else 1709 else
1563 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 1710 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1564 fi 1711 fi
1565 fi 1712 fi
1566 1713
1714 if [[ "${EAPI:-0}" == "0" ]]; then
1567 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then 1715 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1568 echo "dev-lang/python:${PYTHON_ABI}" 1716 echo "=dev-lang/python-${PYTHON_ABI}*"
1569 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then 1717 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1718 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1719 fi
1720 else
1721 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1722 echo "dev-lang/python:${PYTHON_ABI}"
1723 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1570 echo "dev-java/jython:${PYTHON_ABI%-jython}" 1724 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1725 fi
1571 fi 1726 fi
1572} 1727}
1573 1728
1574# @FUNCTION: python_get_includedir 1729# @FUNCTION: python_get_includedir
1575# @USAGE: [-b|--base-path] [-f|--final-ABI] 1730# @USAGE: [-b|--base-path] [-f|--final-ABI]
2114 2269
2115_python_clean_compiled_modules() { 2270_python_clean_compiled_modules() {
2116 _python_initialize_prefix_variables 2271 _python_initialize_prefix_variables
2117 _python_set_color_variables 2272 _python_set_color_variables
2118 2273
2119 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" 2274 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
2120 2275
2121 local base_module_name compiled_file compiled_files=() dir path py_file root 2276 local base_module_name compiled_file compiled_files=() dir path py_file root
2122 2277
2123 # Strip trailing slash from EROOT. 2278 # Strip trailing slash from EROOT.
2124 root="${EROOT%/}" 2279 root="${EROOT%/}"
2201 done 2356 done
2202 done 2357 done
2203} 2358}
2204 2359
2205# @FUNCTION: python_mod_optimize 2360# @FUNCTION: python_mod_optimize
2206# @USAGE: [options] [directory|file] 2361# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
2207# @DESCRIPTION: 2362# @DESCRIPTION:
2208# If no arguments supplied, it will recompile not recursively all modules 2363# 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. 2364# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2215# 2365#
2216# This function can be used only in pkg_postinst() phase. 2366# This function can be used only in pkg_postinst() phase.
2217python_mod_optimize() { 2367python_mod_optimize() {
2218 _python_check_python_pkg_setup_execution 2368 _python_check_python_pkg_setup_execution
2219 _python_initialize_prefix_variables 2369 _python_initialize_prefix_variables
2220 2370
2221 # Check if phase is pkg_postinst(). 2371 # Check if phase is pkg_postinst().
2222 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" 2372 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2223 2373
2224 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2374 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. 2375 # 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=() 2376 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 2377
2228 if _python_package_supporting_installation_for_multiple_python_abis; then 2378 if _python_package_supporting_installation_for_multiple_python_abis; then
2229 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2379 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 2420 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" 2421 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2272 fi 2422 fi
2273 2423
2274 if [[ "$#" -eq 0 ]]; then 2424 if [[ "$#" -eq 0 ]]; then
2275 ewarn 2425 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 2426 fi
2281 2427
2282 while (($#)); do 2428 while (($#)); do
2283 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2429 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2284 die "${FUNCNAME}(): Invalid argument '$1'" 2430 die "${FUNCNAME}(): Invalid argument '$1'"
2386 if ((${#other_files[@]})); then 2532 if ((${#other_files[@]})); then
2387 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2533 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2388 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2534 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" 2535 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2390 fi 2536 fi
2391 _python_clean_compiled_modules "${other_dirs[@]}" 2537 _python_clean_compiled_modules "${other_files[@]}"
2392 fi 2538 fi
2393 eend "${return_code}" 2539 eend "${return_code}"
2394 fi 2540 fi
2395 else 2541 else
2396 # Deprecated part of python_mod_optimize() 2542 # Deprecated part of python_mod_optimize()
2543 # ewarn
2544 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2545 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2546 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2547 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2548 # ewarn
2397 2549
2398 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2550 local myroot mydirs=() myfiles=() myopts=() return_code="0"
2399 2551
2400 # strip trailing slash 2552 # strip trailing slash
2401 myroot="${EROOT%/}" 2553 myroot="${EROOT%/}"
2423 esac 2575 esac
2424 shift 2576 shift
2425 done 2577 done
2426 2578
2427 if [[ "$#" -eq 0 ]]; then 2579 if [[ "$#" -eq 0 ]]; then
2428 ewarn 2580 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 2581 fi
2434 2582
2435 while (($#)); do 2583 while (($#)); do
2436 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2584 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2437 die "${FUNCNAME}(): Invalid argument '$1'" 2585 die "${FUNCNAME}(): Invalid argument '$1'"
2438 elif [[ -d "${myroot}/${1#/}" ]]; then 2586 elif [[ -d "${myroot}/${1#/}" ]]; then
2439 mydirs+=("${myroot}/${1#/}") 2587 mydirs+=("${myroot}/${1#/}")
2440 elif [[ -f "${myroot}/${1#/}" ]]; then 2588 elif [[ -f "${myroot}/${1#/}" ]]; then
2441 # Files are passed to python_mod_compile which is EROOT-aware 2589 myfiles+=("${myroot}/${1#/}")
2442 myfiles+=("$1")
2443 elif [[ -e "${myroot}/${1#/}" ]]; then 2590 elif [[ -e "${myroot}/${1#/}" ]]; then
2444 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory" 2591 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2445 else 2592 else
2446 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist" 2593 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2447 fi 2594 fi
2459 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2606 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2460 _python_clean_compiled_modules "${mydirs[@]}" 2607 _python_clean_compiled_modules "${mydirs[@]}"
2461 fi 2608 fi
2462 2609
2463 if ((${#myfiles[@]})); then 2610 if ((${#myfiles[@]})); then
2611 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2612 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
2464 python_mod_compile "${myfiles[@]}" 2613 _python_clean_compiled_modules "${myfiles[@]}"
2465 fi 2614 fi
2466 2615
2467 eend "${return_code}" 2616 eend "${return_code}"
2468 fi 2617 fi
2469} 2618}
2470 2619
2471# @FUNCTION: python_mod_cleanup 2620# @FUNCTION: python_mod_cleanup
2472# @USAGE: [directory|file] 2621# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
2473# @DESCRIPTION: 2622# @DESCRIPTION:
2474# Run with optional arguments, where arguments are Python modules. If none given, 2623# 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# 2624#
2481# This function can be used only in pkg_postrm() phase. 2625# This function can be used only in pkg_postrm() phase.
2482python_mod_cleanup() { 2626python_mod_cleanup() {
2483 _python_check_python_pkg_setup_execution 2627 _python_check_python_pkg_setup_execution
2484 _python_initialize_prefix_variables 2628 _python_initialize_prefix_variables
2525 2669
2526 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then 2670 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" 2671 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2528 fi 2672 fi
2529 2673
2530 if [[ "$#" -gt 0 ]]; then 2674 if [[ "$#" -eq 0 ]]; then
2531 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then 2675 die "${FUNCNAME}(): Missing files or directories"
2676 fi
2677
2678 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 2679 while (($#)); do
2533 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then 2680 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2534 die "${FUNCNAME}(): Invalid argument '$1'" 2681 die "${FUNCNAME}(): Invalid argument '$1'"
2535 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2682 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" 2683 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2537 elif [[ "$1" =~ ^/ ]]; then 2684 elif [[ "$1" =~ ^/ ]]; then
2538 if _python_package_supporting_installation_for_multiple_python_abis; then 2685 if _python_package_supporting_installation_for_multiple_python_abis; then
2539 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then 2686 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" 2687 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 2688 fi
2689 if [[ "$1" != *\$* ]]; then
2690 die "${FUNCNAME}(): '$1' has invalid syntax"
2691 fi
2692 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2693 eval "search_paths+=(\"\${root}$1\")"
2694 done
2551 else 2695 else
2696 search_paths+=("${root}$1")
2697 fi
2698 else
2552 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do 2699 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2553 search_paths+=("${root}$(python_get_sitedir)/$1") 2700 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 2701 done
2578 fi 2702 fi
2703 shift
2579 done 2704 done
2580 for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do 2705 else
2581 if [[ -d "${sitedir}" ]]; then 2706 # Deprecated part of python_mod_cleanup()
2707 # ewarn
2708 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2709 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2710 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2711 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2712 # ewarn
2713
2582 search_paths+=("${sitedir}") 2714 search_paths=("${@#/}")
2583 fi 2715 search_paths=("${search_paths[@]/#/${root}/}")
2584 done
2585 fi 2716 fi
2586 2717
2587 _python_clean_compiled_modules "${search_paths[@]}" 2718 _python_clean_compiled_modules "${search_paths[@]}"
2588} 2719}
2589 2720
2607python_tkinter_exists() { 2738python_tkinter_exists() {
2608 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2739 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2609 die "${FUNCNAME}() is banned" 2740 die "${FUNCNAME}() is banned"
2610} 2741}
2611 2742
2612# @FUNCTION: python_mod_compile 2743# 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#
2621python_mod_compile() { 2744python_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}()." 2745 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2624 die "${FUNCNAME}() cannot be used in this EAPI" 2746 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} 2747}

Legend:
Removed from v.1.103  
changed lines
  Added in v.1.104

  ViewVC Help
Powered by ViewVC 1.1.20