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

Diff of /eclass/twisted.eclass

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

Revision 1.4 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.4 2006/04/09 23:18:36 marienz Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/twisted.eclass,v 1.8 2010/10/10 19:39:49 arfrever Exp $
4# 4
5# Author: Marien Zwart <marienz@gentoo.org> 5# @ECLASS: twisted.eclass
6# 6# @MAINTAINER:
7# eclass to aid installing and testing twisted packages. 7# Gentoo Python Project <python@gentoo.org>
8# 8# @BLURB: Eclass for Twisted packages
9# you should set MY_PACKAGE to something like 'Names' before inheriting. 9# @DESCRIPTION:
10# you may set MY_PV to the right version (defaults to PV). 10# The twisted eclass defines phase functions for Twisted packages.
11
12# The following variables can be set in dev-python/twisted* packages before inheriting this eclass:
13# MY_PACKAGE - Package name suffix (required)
14# MY_PV - Package version (optional)
11 15
12inherit distutils versionator 16inherit distutils versionator
13 17
14MY_PV=${MY_PV:-${PV}} 18EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
15MY_VERSION=$(get_version_component_range 1-2 ${MY_PV})
16MY_P=Twisted${MY_PACKAGE}-${MY_PV}
17 19
18HOMEPAGE="http://www.twistedmatrix.com/" 20if [[ "${CATEGORY}/${PN}" == "dev-python/twisted"* ]]; then
19SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/${MY_VERSION}/${MY_P}.tar.bz2" 21 EXPORT_FUNCTIONS src_test
20 22
21LICENSE="MIT" 23 MY_PV="${MY_PV:-${PV}}"
22SLOT="0" 24 MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
23 25
24IUSE="" 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"
25 28
29 LICENSE="MIT"
30 SLOT="0"
31 IUSE=""
32
26S="${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.
27 41
28twisted_src_test() { 42twisted_src_test() {
29 python_version 43 if [[ "${CATEGORY}/${PN}" != "dev-python/twisted"* ]]; then
30 # This is a hack to make tests work without installing to the live 44 die "${FUNCNAME}() can be used only in dev-python/twisted* packages"
31 # filesystem. We copy the twisted site-packages to a temporary
32 # dir, install there, and run from there.
33 local spath="usr/lib/python${PYVER}/site-packages/"
34 mkdir -p "${T}/${spath}"
35 cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die
36 if has_version ">=dev-lang/python-2.3"; then
37 ${python} setup.py install --root="${T}" --no-compile --force || die
38 else
39 ${python} setup.py install --root="${T}" --force || die
40 fi 45 fi
41 cd "${T}/${spath}" || die 46
42 local trialopts 47 testing() {
43 if ! has_version ">=dev-python/twisted-2.2"; then 48 local sitedir="${EPREFIX}$(python_get_sitedir)"
44 trialopts=-R 49
45 fi 50 # Copy modules of other Twisted packages from site-packages directory to temporary directory.
46 PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" \ 51 mkdir -p "${T}/${sitedir}"
47 trial ${trialopts} ${PN/-/.} || die "trial failed" 52 cp -R "${ROOT}${sitedir}/twisted" "${T}/${sitedir}" || die "Copying of modules of other Twisted packages failed with $(python_get_implementation) $(python_get_version)"
48 cd "${S}" 53 rm -fr "${T}/${sitedir}/${PN/-//}"
54
55 # Install modules of current package to temporary directory.
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)"
57
58 pushd "${T}/${sitedir}" > /dev/null || return 1
59 PATH="${T}${EPREFIX}/usr/bin:${PATH}" PYTHONPATH="${T}/${sitedir}" trial ${PN/-/.} || return 1
60 popd > /dev/null || return 1
61
49 rm -rf "${T}/${spath}" 62 rm -fr "${T}/${sitedir}"
63 }
64 python_execute_function testing
50} 65}
51 66
52twisted_src_install() { 67twisted_src_install() {
53 distutils_src_install 68 distutils_src_install
54 69
60 insinto /usr/share/doc/${PF} 75 insinto /usr/share/doc/${PF}
61 doins -r $(find doc -mindepth 1 -maxdepth 1 -not -name man) 76 doins -r $(find doc -mindepth 1 -maxdepth 1 -not -name man)
62 fi 77 fi
63} 78}
64 79
65update_plugin_cache() { 80_twisted_update_plugin_cache() {
66 einfo "Updating twisted plugin cache..." 81 local dir exit_status="0" module
67 python_version 82
68 # we have to remove the cache or removed plugins won't be removed 83 for module in ${TWISTED_PLUGINS}; do
69 # from the cache (http://twistedmatrix.com/bugs/issue926) 84 if [[ -d "${EROOT}$(python_get_sitedir -b)/${module//.//}" ]]; then
70 rm "${ROOT}usr/$(get_libdir)/python${PYVER}/site-packages/twisted/plugins/dropin.cache" 85 find "${EROOT}$(python_get_sitedir -b)/${module//.//}" -name dropin.cache -print0 | xargs -0 rm -f
71 # notice we have to use getPlugIns here for <=twisted-2.0.1 compatibility 86 fi
72 python -c "from twisted.plugin import IPlugin, getPlugIns;list(getPlugIns(IPlugin))" 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
73} 129}
74 130
75twisted_pkg_postrm() { 131twisted_pkg_postrm() {
76 distutils_pkg_postrm 132 distutils_pkg_postrm
133 python_execute_function \
134 --action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
135 --failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
136 --nonfatal \
77 update_plugin_cache 137 _twisted_update_plugin_cache
78} 138}
79
80twisted_pkg_postinst() {
81 distutils_pkg_postinst
82 update_plugin_cache
83}
84
85EXPORT_FUNCTIONS src_test src_install pkg_postrm pkg_postinst

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

  ViewVC Help
Powered by ViewVC 1.1.20