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

Diff of /eclass/python.eclass

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

Revision 1.90 Revision 1.93
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.90 2010/02/28 11:48:40 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.93 2010/03/12 18:27:01 betelgeuse 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
188# @DESCRIPTION: 188# @DESCRIPTION:
189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 189# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
190# are respected. Only exported if one of those variables is set. 190# are respected. Only exported if one of those variables is set.
191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 191if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
192 python_pkg_setup() { 192 python_pkg_setup() {
193 # Check if phase is pkg_setup().
194 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
195
193 python_pkg_setup_fail() { 196 python_pkg_setup_fail() {
194 eerror "${1}" 197 eerror "${1}"
195 die "${1}" 198 die "${1}"
196 } 199 }
197 200
227 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail 230 unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
228 } 231 }
229 232
230 EXPORT_FUNCTIONS pkg_setup 233 EXPORT_FUNCTIONS pkg_setup
231 234
232 _PYTHON_USE_WITH_ATOM="" 235 _PYTHON_USE_WITH_ATOMS_ARRAY=()
233 if [[ -n "${PYTHON_USE_WITH}" ]]; then 236 if [[ -n "${PYTHON_USE_WITH}" ]]; then
234 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 237 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
235 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 238 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]")
236 done 239 done
237 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )"
238 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 240 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
239 for _USE_flag in ${PYTHON_USE_WITH_OR}; do 241 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
240 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do 242 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
241 _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${_USE_flag}]" 243 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
242 done 244 done
243 done 245 done
244 unset _USE_flag 246 unset _USE_flag
247 fi
248 if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
245 _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )" 249 _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
250 else
251 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
246 fi 252 fi
247 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then 253 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
248 _PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOM} )" 254 _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
249 fi 255 fi
250 DEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 256 DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
251 RDEPEND+=" ${_PYTHON_USE_WITH_ATOM}" 257 RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
252 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOM 258 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
253fi 259fi
254 260
255unset _PYTHON_ATOMS 261unset _PYTHON_ATOMS
256 262
257# ================================================================================================ 263# ================================================================================================
1261 die "${FUNCNAME}(): Jython does not have shared library" 1267 die "${FUNCNAME}(): Jython does not have shared library"
1262 fi 1268 fi
1263} 1269}
1264 1270
1265# @FUNCTION: python_get_version 1271# @FUNCTION: python_get_version
1266# @USAGE: [-f|--final-ABI] [--major] [--minor] [--micro] 1272# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro]
1267# @DESCRIPTION: 1273# @DESCRIPTION:
1268# Print Python version. 1274# Print Python version.
1269# --major, --minor and --micro options cannot be specified simultaneously. 1275# --full, --major, --minor and --micro options cannot be specified simultaneously.
1270# If --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. 1276# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1271# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 1277# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1272python_get_version() { 1278python_get_version() {
1273 local final_ABI="0" major="0" minor="0" micro="0" python_command 1279 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1274 1280
1275 while (($#)); do 1281 while (($#)); do
1276 case "$1" in 1282 case "$1" in
1277 -f|--final-ABI) 1283 -f|--final-ABI)
1278 final_ABI="1" 1284 final_ABI="1"
1279 ;; 1285 ;;
1286 --full)
1287 full="1"
1288 ;;
1280 --major) 1289 --major)
1281 major="1" 1290 major="1"
1282 ;; 1291 ;;
1283 --minor) 1292 --minor)
1284 minor="1" 1293 minor="1"
1294 ;; 1303 ;;
1295 esac 1304 esac
1296 shift 1305 shift
1297 done 1306 done
1298 1307
1299 if [[ "$((${major} + ${minor} + ${micro}))" -gt 1 ]]; then 1308 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
1300 die "${FUNCNAME}(): '--major', '--minor' or '--micro' options cannot be specified simultaneously" 1309 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
1301 fi 1310 fi
1302 1311
1312 if [[ "${full}" == "1" ]]; then
1313 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
1303 if [[ "${major}" == "1" ]]; then 1314 elif [[ "${major}" == "1" ]]; then
1304 python_command="from sys import version_info; print(version_info[0])" 1315 python_command="from sys import version_info; print(version_info[0])"
1305 elif [[ "${minor}" == "1" ]]; then 1316 elif [[ "${minor}" == "1" ]]; then
1306 python_command="from sys import version_info; print(version_info[1])" 1317 python_command="from sys import version_info; print(version_info[1])"
1307 elif [[ "${micro}" == "1" ]]; then 1318 elif [[ "${micro}" == "1" ]]; then
1308 python_command="from sys import version_info; print(version_info[2])" 1319 python_command="from sys import version_info; print(version_info[2])"
1309 else 1320 else
1321 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
1322 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1323 echo "${PYTHON_ABI}"
1324 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1325 echo "${PYTHON_ABI%-jython}"
1326 fi
1327 return
1328 fi
1310 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" 1329 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
1311 fi 1330 fi
1312 1331
1313 if [[ "${final_ABI}" == "1" ]]; then 1332 if [[ "${final_ABI}" == "1" ]]; then
1314 "$(PYTHON -f)" -c "${python_command}" 1333 "$(PYTHON -f)" -c "${python_command}"
1477 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" 1496 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
1478 fi 1497 fi
1479 done 1498 done
1480} 1499}
1481 1500
1482# @FUNCTION: python_mod_exists
1483# @USAGE: <module>
1484# @DESCRIPTION:
1485# Run with the module name as an argument. It will check if a
1486# Python module is installed and loadable. It will return
1487# TRUE(0) if the module exists, and FALSE(1) if the module does
1488# not exist.
1489#
1490# Example:
1491# if python_mod_exists gtk; then
1492# echo "gtk support enabled"
1493# fi
1494python_mod_exists() {
1495 if [[ "$#" -ne 1 ]]; then
1496 die "${FUNCNAME}() requires 1 argument"
1497 fi
1498 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
1499}
1500
1501# ================================================================================================ 1501# ================================================================================================
1502# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ 1502# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
1503# ================================================================================================ 1503# ================================================================================================
1504 1504
1505# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY 1505# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
1506# @DESCRIPTION: 1506# @DESCRIPTION:
1507# User-configurable verbosity of tests of Python modules. 1507# User-configurable verbosity of tests of Python modules.
1508# Supported values: 0, 1, 2, 3, 4. 1508# Supported values: 0, 1, 2, 3, 4.
1509PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}" 1509PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
1510 1510
1511_python_test_hook() {
1512 if [[ "$#" -ne 1 ]]; then
1513 die "${FUNCNAME}() requires 1 argument"
1514 fi
1515
1516 if [[ -n "${SUPPORT_PYTHON_ABIS}" && "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
1517 "${FUNCNAME[3]}_$1_hook"
1518 fi
1519}
1520
1511# @FUNCTION: python_execute_nosetests 1521# @FUNCTION: python_execute_nosetests
1512# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1522# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1513# @DESCRIPTION: 1523# @DESCRIPTION:
1514# Execute nosetests for all enabled versions of Python. 1524# Execute nosetests for all enabled versions of Python.
1525# In ebuilds of packages supporting installation for multiple versions of Python, this function
1526# calls python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
1515python_execute_nosetests() { 1527python_execute_nosetests() {
1516 _python_set_color_variables 1528 _python_set_color_variables
1517 1529
1518 local PYTHONPATH_template= separate_build_dirs= 1530 local PYTHONPATH_template= separate_build_dirs=
1519 1531
1548 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1560 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1549 unset evaluated_PYTHONPATH 1561 unset evaluated_PYTHONPATH
1550 fi 1562 fi
1551 fi 1563 fi
1552 1564
1565 _python_test_hook pre
1566
1553 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1567 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1554 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1568 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1555 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1569 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1556 else 1570 else
1557 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 1571 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
1558 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" 1572 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
1559 fi 1573 fi
1574
1575 _python_test_hook post
1560 } 1576 }
1561 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1577 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1562 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1578 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1563 else 1579 else
1564 if [[ -n "${separate_build_dirs}" ]]; then 1580 if [[ -n "${separate_build_dirs}" ]]; then
1572 1588
1573# @FUNCTION: python_execute_py.test 1589# @FUNCTION: python_execute_py.test
1574# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1590# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1575# @DESCRIPTION: 1591# @DESCRIPTION:
1576# Execute py.test for all enabled versions of Python. 1592# Execute py.test for all enabled versions of Python.
1593# In ebuilds of packages supporting installation for multiple versions of Python, this function
1594# calls python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
1577python_execute_py.test() { 1595python_execute_py.test() {
1578 _python_set_color_variables 1596 _python_set_color_variables
1579 1597
1580 local PYTHONPATH_template= separate_build_dirs= 1598 local PYTHONPATH_template= separate_build_dirs=
1581 1599
1610 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1628 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1611 unset evaluated_PYTHONPATH 1629 unset evaluated_PYTHONPATH
1612 fi 1630 fi
1613 fi 1631 fi
1614 1632
1633 _python_test_hook pre
1634
1615 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1635 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1616 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 1636 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
1617 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" 1637 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
1618 else 1638 else
1619 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} 1639 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
1620 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" 1640 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
1621 fi 1641 fi
1642
1643 _python_test_hook post
1622 } 1644 }
1623 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1645 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1624 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1646 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1625 else 1647 else
1626 if [[ -n "${separate_build_dirs}" ]]; then 1648 if [[ -n "${separate_build_dirs}" ]]; then
1634 1656
1635# @FUNCTION: python_execute_trial 1657# @FUNCTION: python_execute_trial
1636# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 1658# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
1637# @DESCRIPTION: 1659# @DESCRIPTION:
1638# Execute trial for all enabled versions of Python. 1660# Execute trial for all enabled versions of Python.
1661# In ebuilds of packages supporting installation for multiple versions of Python, this function
1662# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
1639python_execute_trial() { 1663python_execute_trial() {
1640 _python_set_color_variables 1664 _python_set_color_variables
1641 1665
1642 local PYTHONPATH_template= separate_build_dirs= 1666 local PYTHONPATH_template= separate_build_dirs=
1643 1667
1672 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then 1696 if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then
1673 unset evaluated_PYTHONPATH 1697 unset evaluated_PYTHONPATH
1674 fi 1698 fi
1675 fi 1699 fi
1676 1700
1701 _python_test_hook pre
1702
1677 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 1703 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
1678 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1704 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1679 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1705 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1680 else 1706 else
1681 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 1707 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
1682 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" 1708 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
1683 fi 1709 fi
1710
1711 _python_test_hook post
1684 } 1712 }
1685 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1713 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1686 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 1714 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
1687 else 1715 else
1688 if [[ -n "${separate_build_dirs}" ]]; then 1716 if [[ -n "${separate_build_dirs}" ]]; then
1721# If no arguments supplied, it will recompile not recursively all modules 1749# If no arguments supplied, it will recompile not recursively all modules
1722# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). 1750# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1723# 1751#
1724# If supplied with arguments, it will recompile all modules recursively 1752# If supplied with arguments, it will recompile all modules recursively
1725# in the supplied directory. 1753# in the supplied directory.
1726# This function should only be run in pkg_postinst().
1727# 1754#
1728# Options passed to this function are passed to compileall.py. 1755# Options passed to this function are passed to compileall.py.
1729# 1756#
1730# Example: 1757# This function can be used only in pkg_postinst() phase.
1731# python_mod_optimize ctypesgencore
1732python_mod_optimize() { 1758python_mod_optimize() {
1733 _python_initialize_prefix_variables 1759 _python_initialize_prefix_variables
1734 1760
1735 # Check if phase is pkg_postinst(). 1761 # Check if phase is pkg_postinst().
1736 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 1762 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1737 1763
1738 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1764 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1739 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 1765 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1740 1766
1741 # Strip trailing slash from ROOT. 1767 # Strip trailing slash from ROOT.
1901# 1927#
1902# It will recursively scan all compiled Python modules in the directories and 1928# It will recursively scan all compiled Python modules in the directories and
1903# determine if they are orphaned (i.e. their corresponding .py files are missing.) 1929# determine if they are orphaned (i.e. their corresponding .py files are missing.)
1904# If they are, then it will remove their corresponding .pyc and .pyo files. 1930# If they are, then it will remove their corresponding .pyc and .pyo files.
1905# 1931#
1906# This function should only be run in pkg_postrm(). 1932# This function can be used only in pkg_postrm() phase.
1907python_mod_cleanup() { 1933python_mod_cleanup() {
1908 _python_initialize_prefix_variables 1934 _python_initialize_prefix_variables
1909 _python_set_color_variables 1935 _python_set_color_variables
1910 1936
1911 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root 1937 local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
1912 1938
1913 # Check if phase is pkg_postrm(). 1939 # Check if phase is pkg_postrm().
1914 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" 1940 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1915 1941
1916 # Strip trailing slash from ROOT. 1942 # Strip trailing slash from ROOT.
1917 root="${EROOT%/}" 1943 root="${EROOT%/}"
1918 1944
1919 if (($#)); then 1945 if (($#)); then
1997 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2023 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1998 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." 2024 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
1999 die "${FUNCNAME}() cannot be used in this EAPI" 2025 die "${FUNCNAME}() cannot be used in this EAPI"
2000 fi 2026 fi
2001 2027
2028 if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then
2029 einfo
2030 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2031 einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2032 einfo
2033 fi
2034
2002 [[ -n "${PYVER}" ]] && return 0 2035 [[ -n "${PYVER}" ]] && return 0
2003 local tmpstr 2036 local tmpstr
2004 python="${python:-${EPREFIX}/usr/bin/python}" 2037 python="${python:-${EPREFIX}/usr/bin/python}"
2005 tmpstr="$(EPYTHON= ${python} -V 2>&1 )" 2038 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
2006 export PYVER_ALL="${tmpstr#Python }" 2039 export PYVER_ALL="${tmpstr#Python }"
2010 export PYVER_MICRO="${PYVER_ALL:4}" 2043 export PYVER_MICRO="${PYVER_ALL:4}"
2011 fi 2044 fi
2012 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" 2045 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
2013} 2046}
2014 2047
2048# @FUNCTION: python_mod_exists
2049# @USAGE: <module>
2050# @DESCRIPTION:
2051# Run with the module name as an argument. It will check if a
2052# Python module is installed and loadable. It will return
2053# TRUE(0) if the module exists, and FALSE(1) if the module does
2054# not exist.
2055#
2056# Example:
2057# if python_mod_exists gtk; then
2058# echo "gtk support enabled"
2059# fi
2060python_mod_exists() {
2061 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2062 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2063 die "${FUNCNAME}() cannot be used in this EAPI"
2064 fi
2065
2066 einfo
2067 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2068 einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2069 einfo
2070
2071 if [[ "$#" -ne 1 ]]; then
2072 die "${FUNCNAME}() requires 1 argument"
2073 fi
2074 "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null
2075}
2076
2015# @FUNCTION: python_tkinter_exists 2077# @FUNCTION: python_tkinter_exists
2016# @DESCRIPTION: 2078# @DESCRIPTION:
2017# Run without arguments, checks if Python was compiled with Tkinter 2079# Run without arguments, checks if Python was compiled with Tkinter
2018# support. If not, prints an error message and dies. 2080# support. If not, prints an error message and dies.
2019python_tkinter_exists() { 2081python_tkinter_exists() {
2020 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2082 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
2021 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." 2083 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2022 die "${FUNCNAME}() cannot be used in this EAPI" 2084 die "${FUNCNAME}() cannot be used in this EAPI"
2085 fi
2086
2087 if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
2088 einfo
2089 einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01."
2090 einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2091 einfo
2023 fi 2092 fi
2024 2093
2025 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info 2094 if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info
2026if version_info[0] == 3: 2095if version_info[0] == 3:
2027 import tkinter 2096 import tkinter
2036 2105
2037# @FUNCTION: python_mod_compile 2106# @FUNCTION: python_mod_compile
2038# @USAGE: <file> [more files ...] 2107# @USAGE: <file> [more files ...]
2039# @DESCRIPTION: 2108# @DESCRIPTION:
2040# Given filenames, it will pre-compile the module's .pyc and .pyo. 2109# Given filenames, it will pre-compile the module's .pyc and .pyo.
2041# This function should only be run in pkg_postinst() 2110# This function can be used only in pkg_postinst() phase.
2042# 2111#
2043# Example: 2112# Example:
2044# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py 2113# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
2045# 2114#
2046python_mod_compile() { 2115python_mod_compile() {
2052 _python_initialize_prefix_variables 2121 _python_initialize_prefix_variables
2053 2122
2054 local f myroot myfiles=() 2123 local f myroot myfiles=()
2055 2124
2056 # Check if phase is pkg_postinst() 2125 # Check if phase is pkg_postinst()
2057 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" 2126 [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2058 2127
2059 # strip trailing slash 2128 # strip trailing slash
2060 myroot="${EROOT%/}" 2129 myroot="${EROOT%/}"
2061 2130
2062 # respect ROOT 2131 # respect ROOT

Legend:
Removed from v.1.90  
changed lines
  Added in v.1.93

  ViewVC Help
Powered by ViewVC 1.1.20