net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[gentoo.git] / eclass / twisted-r1.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: twisted-r1.eclass
5 # @MAINTAINER:
6 # Gentoo Python Project <python@gentoo.org>
7 # @AUTHOR:
8 # Author: Michał Górny <mgorny@gentoo.org>
9 # Author: Jan Matejka <yac@gentoo.org>
10 # @BLURB: Eclass for Twisted packages
11 # @DESCRIPTION:
12 # The twisted eclass defines phase functions for Twisted packages.
13
14 case "${EAPI:-0}" in
15         0|1|2|3)
16                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
17                 ;;
18         4|5)
19                 ;;
20         *)
21                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
22                 ;;
23 esac
24
25 if [[ ! ${_TWISTED_R1} ]]; then
26
27 inherit distutils-r1 versionator
28
29 fi # ! ${_TWISTED_R1}
30
31 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
32
33 if [[ ! ${_TWISTED_R1} ]]; then
34
35 # @FUNCTION: _twisted-r1_camelcase
36 # @USAGE: <pn>
37 # @DESCRIPTION:
38 # Convert dash-separated <pn> to CamelCase name suitable for Twisted.
39 # In pure bash, therefore safe for global scope execution.
40 _twisted-r1_camelcase() {
41         local IFS=-
42
43         # IFS=- splits words by -.
44         local words=( ${1} )
45
46         # we can't keep '-' as it collides with [a-z] check
47         # and '' is used by bash-4 words[*], so let's just set globally
48         IFS=
49
50         if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
51                 echo "${words[*]^}"
52                 return
53         fi
54
55         local w LC_COLLATE=C uc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
56
57         local out
58         for w in "${words[@]}"; do
59                 local fl=${w:0:1}
60
61                 # Danger: magic starts here. Please close your eyes.
62                 # In base 36, a..z represents digits 10..35. We substract 10
63                 # and get array subscripts for uc.
64
65                 [[ ${fl} == [a-z] ]] && fl=${uc:36#${fl} - 10:1}
66
67                 out+=${fl}${w:1}
68         done
69
70         echo "${out}"
71 }
72
73 # @ECLASS-VARIABLE: TWISTED_PN
74 # @DESCRIPTION:
75 # The real package name. Default to camel-case conversion of ${PN}.
76 #
77 # Example: TwistedCore
78 : ${TWISTED_PN:=$(_twisted-r1_camelcase ${PN})}
79
80 # @ECLASS-VARIABLE: TWISTED_P
81 # @DESCRIPTION:
82 # The real package name with version appended.
83 #
84 # It is used to build the default SRC_URI and S values.
85 #
86 # Example: TwistedCore-1.2.3
87 : ${TWISTED_P:=${TWISTED_PN}-${PV}}
88
89 # @ECLASS-VARIABLE: TWISTED_RELEASE
90 # @DESCRIPTION:
91 # The 'release' of Twisted. Defaults to the major & minor version
92 # number from ${PV}.
93 #
94 # It is used to build the default SRC_URI. It may be also used
95 # in dependencies against other Twisted packages.
96 #
97 # Example: 1.2
98 : ${TWISTED_RELEASE:=$(get_version_component_range 1-2 ${PV})}
99
100 HOMEPAGE="http://www.twistedmatrix.com/"
101 SRC_URI="http://twistedmatrix.com/Releases/${TWISTED_PN#Twisted}"
102 SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2"
103
104 LICENSE="MIT"
105 SLOT="0"
106 IUSE=""
107
108 S=${WORKDIR}/${TWISTED_P}
109
110 # @ECLASS-VARIABLE: TWISTED_PLUGINS
111 # @DESCRIPTION:
112 # An array of Twisted plugins, whose cache is regenerated
113 # in pkg_postinst() and pkg_postrm() phases.
114 #
115 # If no plugins are installed, set to empty array.
116 declare -p TWISTED_PLUGINS &>/dev/null || TWISTED_PLUGINS=( twisted.plugins )
117
118 # @FUNCTION: twisted-r1_python_test
119 # @DESCRIPTION:
120 # The common python_test() implementation that suffices for Twisted
121 # packages.
122 twisted-r1_python_test() {
123         local sitedir=$(python_get_sitedir)
124
125         # Copy modules of other Twisted packages from site-packages
126         # directory to the temporary directory.
127         local libdir=${BUILD_DIR}/test/lib
128         mkdir -p "${libdir}" || die
129         cp -r "${ROOT}${sitedir}"/twisted "${libdir}" || die
130         # Drop the installed module in case previous version conflicts with
131         # the new one somehow.
132         rm -fr "${libdir}/${PN/-//}" || die
133
134         distutils_install_for_testing || die
135
136         if [[ ${TEST_DIR} != ${BUILD_DIR}/test ]]; then
137                 eerror "twisted-r1 integrity check failed."
138                 eerror "TEST_DIR: ${TEST_DIR}"
139                 eerror "expected: ${BUILD_DIR}/test"
140                 die "TEST_DIR integrity check failed"
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}