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

Contents of /eclass/twisted-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sun Jan 5 10:12:49 2014 UTC (7 months, 2 weeks ago) by mgorny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +3 -3 lines
Fix twisted SRC_URI. Thanks to yac for the patch.

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License, v2 or later
3 # $Header: /var/cvsroot/gentoo-x86/eclass/twisted-r1.eclass,v 1.1 2013/08/08 22:29:21 mgorny Exp $
4
5 # @ECLASS: twisted-r1.eclass
6 # @MAINTAINER:
7 # Gentoo Python Project <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Author: Jan Matejka <yac@gentoo.org>
11 # @BLURB: Eclass for Twisted packages
12 # @DESCRIPTION:
13 # The twisted eclass defines phase functions for Twisted packages.
14
15 case "${EAPI:-0}" in
16 0|1|2|3)
17 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
18 ;;
19 4|5)
20 ;;
21 *)
22 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
23 ;;
24 esac
25
26 if [[ ! ${_TWISTED_R1} ]]; then
27
28 inherit distutils-r1 versionator
29
30 fi # ! ${_TWISTED_R1}
31
32 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
33
34 if [[ ! ${_TWISTED_R1} ]]; then
35
36 # @FUNCTION: _twisted-r1_camelcase
37 # @USAGE: <pn>
38 # @DESCRIPTION:
39 # Convert dash-separated <pn> to CamelCase name suitable for Twisted.
40 # In pure bash, therefore safe for global scope execution.
41 _twisted-r1_camelcase() {
42 local IFS=-
43
44 # IFS=- splits words by -.
45 local words=( ${1} )
46
47 # we can't keep '-' as it collides with [a-z] check
48 # and '' is used by bash-4 words[*], so let's just set globally
49 IFS=
50
51 if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
52 echo "${words[*]^}"
53 return
54 fi
55
56 local w LC_COLLATE=C uc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
57
58 local out
59 for w in "${words[@]}"; do
60 local fl=${w:0:1}
61
62 # Danger: magic starts here. Please close your eyes.
63 # In base 36, a..z represents digits 10..35. We substract 10
64 # and get array subscripts for uc.
65
66 [[ ${fl} == [a-z] ]] && fl=${uc:36#${fl} - 10:1}
67
68 out+=${fl}${w:1}
69 done
70
71 echo "${out}"
72 }
73
74 # @ECLASS-VARIABLE: TWISTED_PN
75 # @DESCRIPTION:
76 # The real package name. Default to camel-case conversion of ${PN}.
77 #
78 # Example: TwistedCore
79 : ${TWISTED_PN:=$(_twisted-r1_camelcase ${PN})}
80
81 # @ECLASS-VARIABLE: TWISTED_P
82 # @DESCRIPTION:
83 # The real package name with version appended.
84 #
85 # It is used to build the default SRC_URI and S values.
86 #
87 # Example: TwistedCore-1.2.3
88 : ${TWISTED_P:=${TWISTED_PN}-${PV}}
89
90 # @ECLASS-VARIABLE: TWISTED_RELEASE
91 # @DESCRIPTION:
92 # The 'release' of Twisted. Defaults to the major & minor version
93 # number from ${PV}.
94 #
95 # It is used to build the default SRC_URI. It may be also used
96 # in dependencies against other Twisted packages.
97 #
98 # Example: 1.2
99 : ${TWISTED_RELEASE:=$(get_version_component_range 1-2 ${PV})}
100
101 HOMEPAGE="http://www.twistedmatrix.com/"
102 SRC_URI="http://twistedmatrix.com/Releases/${TWISTED_PN#Twisted}"
103 SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2"
104
105 LICENSE="MIT"
106 SLOT="0"
107 IUSE=""
108
109 S=${WORKDIR}/${TWISTED_P}
110
111 # @ECLASS-VARIABLE: TWISTED_PLUGINS
112 # @DESCRIPTION:
113 # An array of Twisted plugins, whose cache is regenerated
114 # in pkg_postinst() and pkg_postrm() phases.
115 #
116 # If no plugins are installed, set to empty array.
117 declare -p TWISTED_PLUGINS &>/dev/null || TWISTED_PLUGINS=( twisted.plugins )
118
119 # @FUNCTION: twisted-r1_python_test
120 # @DESCRIPTION:
121 # The common python_test() implementation that suffices for Twisted
122 # packages.
123 twisted-r1_python_test() {
124 local sitedir=$(python_get_sitedir)
125
126 # Copy modules of other Twisted packages from site-packages
127 # directory to the temporary directory.
128 local libdir=${BUILD_DIR}/test/lib
129 mkdir -p "${libdir}" || die
130 cp -r "${ROOT}${sitedir}"/twisted "${libdir}" || die
131 # Drop the installed module in case previous version conflicts with
132 # the new one somehow.
133 rm -fr "${libdir}/${PN/-//}" || die
134
135 distutils_install_for_testing || die
136
137 if [[ ${TEST_DIR} != ${BUILD_DIR}/test ]]; then
138 eqawarn "twisted-r1 integrity check failed."
139 eqawarn "TEST_DIR: ${TEST_DIR}"
140 eqawarn "expected: ${BUILD_DIR}/test"
141 fi
142
143 cd "${TEST_DIR}"/lib || die
144 trial ${PN/-/.} || die "Tests fail with ${EPYTHON}"
145 }
146
147 # @FUNCTION: python_test
148 # @DESCRIPTION:
149 # Default python_test() for Twisted packages. If you need to override
150 # it, you can access the original implementation
151 # via twisted-r1_python_test.
152 python_test() {
153 twisted-r1_python_test
154 }
155
156 # @FUNCTION: twisted-r1_src_install
157 # @DESCRIPTION:
158 # Default src_install() for Twisted packages. Automatically handles HTML
159 # docs (unless HTML_DOCS is set explicitly) and manpages in Twisted
160 # packages.
161 twisted-r1_src_install() {
162 [[ -d doc ]] && local HTML_DOCS=( "${HTML_DOCS[@]:-doc/.}" )
163 [[ -d doc/man ]] && doman doc/man/*.[[:digit:]]
164
165 distutils-r1_src_install
166 }
167
168 # @FUNCTION: _twisted-r1_create_caches
169 # @USAGE: <packages>...
170 # @DESCRIPTION:
171 # Create dropin.cache for plugins in specified packages. The packages
172 # are to be listed in standard dotted Python syntax.
173 _twisted-r1_create_caches() {
174 # http://twistedmatrix.com/documents/current/core/howto/plugin.html
175 "${PYTHON}" -c \
176 "import sys
177 sys.path.insert(0, '${ROOT}$(python_get_sitedir)')
178
179 fail = False
180
181 try:
182 from twisted.plugin import getPlugins, IPlugin
183 except ImportError as e:
184 if '${EBUILD_PHASE}' == 'postinst':
185 raise
186 else:
187 for module in sys.argv[1:]:
188 try:
189 __import__(module, globals())
190 except ImportError as e:
191 if '${EBUILD_PHASE}' == 'postinst':
192 raise
193 else:
194 list(getPlugins(IPlugin, sys.modules[module]))
195 " \
196 "${@}" || die "twisted plugin cache update failed"
197 }
198
199 # @FUNCTION: twisted-r1_update_plugin_cache
200 # @DESCRIPTION:
201 # Update and clean up plugin caches for packages listed
202 # in TWISTED_PLUGINS.
203 twisted-r1_update_plugin_cache() {
204 [[ ${TWISTED_PLUGINS[@]} ]] || return
205
206 local subdirs=( "${TWISTED_PLUGINS[@]//.//}" )
207 local paths=( "${subdirs[@]/#/${ROOT}$(python_get_sitedir)/}" )
208 local caches=( "${paths[@]/%//dropin.cache}" )
209
210 # First, delete existing (possibly stray) caches.
211 rm -f "${caches[@]}" || die
212
213 # Now, let's see which ones we can regenerate.
214 _twisted-r1_create_caches "${TWISTED_PLUGINS[@]}"
215
216 # Finally, drop empty parent directories.
217 rmdir -p "${paths[@]}" 2>/dev/null
218 }
219
220 # @FUNCTION: twisted-r1_pkg_postinst
221 # @DESCRIPTION:
222 # Post-installation hook for twisted-r1. Updates plugin caches.
223 twisted-r1_pkg_postinst() {
224 _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
225 }
226
227 # @FUNCTION: twisted-r1_pkg_postrm
228 # @DESCRIPTION:
229 # Post-removal hook for twisted-r1. Updates plugin caches.
230 twisted-r1_pkg_postrm() {
231 _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
232 }
233
234 _TWISTED_R1=1
235
236 fi # ! ${_TWISTED_R1}

  ViewVC Help
Powered by ViewVC 1.1.20