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

Diff of /eclass/twisted.eclass

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

Revision 1.7 Revision 1.8
1# Copyright 2005 Gentoo Foundation 1# Copyright 2005-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License, v2 or later 2# Distributed under the terms of the GNU General Public License, v2 or later
3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/twisted.eclass,v 1.7 2009/10/30 13:14:17 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/twisted.eclass,v 1.8 2010/10/10 19:39:49 arfrever Exp $
4#
5# Author: Marien Zwart <marienz@gentoo.org>
6#
7# eclass to aid installing and testing twisted packages.
8#
9# you should set MY_PACKAGE to something like 'Names' before inheriting.
10# you may set MY_PV to the right version (defaults to PV).
11#
12# twisted_src_test relies on the package installing twisted.names to
13# have a ${PN} of twisted-names.
14 4
15inherit distutils eutils versionator 5# @ECLASS: twisted.eclass
6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Twisted packages
9# @DESCRIPTION:
10# The twisted eclass defines phase functions for Twisted packages.
16 11
17MY_PV="${MY_PV:-${PV}}" 12# The following variables can be set in dev-python/twisted* packages before inheriting this eclass:
18MY_VERSION="$(get_version_component_range 1-2 ${MY_PV})" 13# MY_PACKAGE - Package name suffix (required)
19MY_P="Twisted${MY_PACKAGE}-${MY_PV}" 14# MY_PV - Package version (optional)
20 15
21HOMEPAGE="http://www.twistedmatrix.com/" 16inherit distutils versionator
22SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/${MY_VERSION}/${MY_P}.tar.bz2"
23 17
24LICENSE="MIT" 18EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
25SLOT="0"
26IUSE=""
27 19
20if [[ "${CATEGORY}/${PN}" == "dev-python/twisted"* ]]; then
21 EXPORT_FUNCTIONS src_test
22
23 MY_PV="${MY_PV:-${PV}}"
24 MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
25
26 HOMEPAGE="http://www.twistedmatrix.com/"
27 SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/$(get_version_component_range 1-2 ${MY_PV})/${MY_P}.tar.bz2"
28
29 LICENSE="MIT"
30 SLOT="0"
31 IUSE=""
32
28S="${WORKDIR}/${MY_P}" 33 S="${WORKDIR}/${MY_P}"
34
35 TWISTED_PLUGINS="${TWISTED_PLUGINS:-twisted.plugins}"
36fi
37
38# @ECLASS-VARIABLE: TWISTED_PLUGINS
39# @DESCRIPTION:
40# Twisted plugins, whose cache is regenerated in pkg_postinst() and pkg_postrm() phases.
29 41
30twisted_src_test() { 42twisted_src_test() {
31 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 43 if [[ "${CATEGORY}/${PN}" != "dev-python/twisted"* ]]; then
32 testing() { 44 die "${FUNCNAME}() can be used only in dev-python/twisted* packages"
33 # This is a hack to make tests work without installing to the live 45 fi
34 # filesystem. We copy the twisted site-packages to a temporary
35 # dir, install there, and run from there.
36 local spath="$(python_get_sitedir)"
37 mkdir -p "${T}/${spath}"
38 cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die "Copying of files failed with Python ${PYTHON_ABI}"
39 46
40 # We have to get rid of the existing version of this package 47 testing() {
41 # instead of just installing on top of it, since if the existing 48 local sitedir="${EPREFIX}$(python_get_sitedir)"
42 # package has tests in files the version we are installing does
43 # not have we end up running e.g. twisted-names-0.3.0 tests when
44 # downgrading to twisted-names-0.1.0-r1.
45 rm -fr "${T}/${spath}/${PN/-//}"
46 49
47 "$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --root="${T}" --no-compile --force || die "Installation for tests failed with Python ${PYTHON_ABI}" 50 # Copy modules of other Twisted packages from site-packages directory to temporary directory.
48 cd "${T}/${spath}" || die
49 PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" trial ${PN/-/.} || die "trial failed with Python ${PYTHON_ABI}"
50 cd "${S}"
51 rm -fr "${T}/${spath}"
52 }
53 python_execute_function testing
54 else
55 # This is a hack to make tests work without installing to the live
56 # filesystem. We copy the twisted site-packages to a temporary
57 # dir, install there, and run from there.
58 local spath="$(python_get_sitedir)"
59 mkdir -p "${T}/${spath}" 51 mkdir -p "${T}/${sitedir}"
60 cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die 52 cp -R "${ROOT}${sitedir}/twisted" "${T}/${sitedir}" || die "Copying of modules of other Twisted packages failed with $(python_get_implementation) $(python_get_version)"
53 rm -fr "${T}/${sitedir}/${PN/-//}"
61 54
62 # We have to get rid of the existing version of this package 55 # Install modules of current package to temporary directory.
63 # instead of just installing on top of it, since if the existing 56 "$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --force --no-compile --root="${T}" || die "Installation into temporary directory failed with $(python_get_implementation) $(python_get_version)"
64 # package has tests in files the version we are installing does
65 # not have we end up running fex twisted-names-0.3.0 tests when
66 # downgrading to twisted-names-0.1.0-r1.
67 rm -rf "${T}/${spath}/${PN/-//}"
68 57
69 "${python}" setup.py install --root="${T}" --no-compile --force || die 58 pushd "${T}/${sitedir}" > /dev/null || return 1
70 cd "${T}/${spath}" || die 59 PATH="${T}${EPREFIX}/usr/bin:${PATH}" PYTHONPATH="${T}/${sitedir}" trial ${PN/-/.} || return 1
71 PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" \ 60 popd > /dev/null || return 1
72 trial ${PN/-/.} || die "trial failed" 61
73 cd "${S}"
74 rm -rf "${T}/${spath}" 62 rm -fr "${T}/${sitedir}"
75 fi 63 }
64 python_execute_function testing
76} 65}
77 66
78twisted_src_install() { 67twisted_src_install() {
79 distutils_src_install 68 distutils_src_install
80 69
86 insinto /usr/share/doc/${PF} 75 insinto /usr/share/doc/${PF}
87 doins -r $(find doc -mindepth 1 -maxdepth 1 -not -name man) 76 doins -r $(find doc -mindepth 1 -maxdepth 1 -not -name man)
88 fi 77 fi
89} 78}
90 79
91update_plugin_cache() { 80_twisted_update_plugin_cache() {
92 einfo "Updating twisted plugin cache..." 81 local dir exit_status="0" module
93 # we have to remove the cache or removed plugins won't be removed 82
94 # from the cache (http://twistedmatrix.com/bugs/issue926) 83 for module in ${TWISTED_PLUGINS}; do
95 rm "${ROOT}$(python_get_sitedir)/twisted/plugins/dropin.cache" 84 if [[ -d "${EROOT}$(python_get_sitedir -b)/${module//.//}" ]]; then
96 # notice we have to use getPlugIns here for <=twisted-2.0.1 compatibility 85 find "${EROOT}$(python_get_sitedir -b)/${module//.//}" -name dropin.cache -print0 | xargs -0 rm -f
97 python -c "from twisted.plugin import IPlugin, getPlugIns;list(getPlugIns(IPlugin))" 86 fi
87 done
88
89 if [[ -n "$(type -p "$(PYTHON)")" ]]; then
90 for module in ${TWISTED_PLUGINS}; do
91 # http://twistedmatrix.com/documents/current/core/howto/plugin.html
92 "$(PYTHON)" -c \
93"import sys
94sys.path.insert(0, '${EROOT}$(python_get_sitedir -b)')
95
96try:
97 import twisted.plugin
98 import ${module}
99except ImportError:
100 if '${EBUILD_PHASE}' == 'postinst':
101 raise
102 else:
103 # Twisted, zope.interface or given plugins might have been uninstalled.
104 sys.exit(0)
105
106list(twisted.plugin.getPlugins(twisted.plugin.IPlugin, ${module}))" || exit_status="1"
107 done
108 fi
109
110 for module in ${TWISTED_PLUGINS}; do
111 # Delete empty parent directories.
112 local dir="${EROOT}$(python_get_sitedir -b)/${module//.//}"
113 while [[ "${dir}" != "${EROOT%/}" ]]; do
114 rmdir "${dir}" 2> /dev/null || break
115 dir="${dir%/*}"
116 done
117 done
118
119 return "${exit_status}"
120}
121
122twisted_pkg_postinst() {
123 distutils_pkg_postinst
124 python_execute_function \
125 --action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
126 --failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
127 --nonfatal \
128 _twisted_update_plugin_cache
98} 129}
99 130
100twisted_pkg_postrm() { 131twisted_pkg_postrm() {
101 distutils_pkg_postrm 132 distutils_pkg_postrm
102 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 133 python_execute_function \
103 python_execute_function update_plugin_cache 134 --action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
104 else 135 --failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
136 --nonfatal \
105 update_plugin_cache 137 _twisted_update_plugin_cache
106 fi
107} 138}
108
109twisted_pkg_postinst() {
110 distutils_pkg_postinst
111 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
112 python_execute_function update_plugin_cache
113 else
114 update_plugin_cache
115 fi
116}
117
118EXPORT_FUNCTIONS src_test src_install pkg_postrm pkg_postinst

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20