1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: twisted-r1.eclass
6 # Gentoo Python Project <python@gentoo.org>
8 # Author: Michał Górny <mgorny@gentoo.org>
9 # Author: Jan Matejka <yac@gentoo.org>
10 # @BLURB: Eclass for Twisted packages
12 # The twisted eclass defines phase functions for Twisted packages.
16 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
21 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
25 if [[ ! ${_TWISTED_R1} ]]; then
27 inherit distutils-r1 versionator
31 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
33 if [[ ! ${_TWISTED_R1} ]]; then
35 # @FUNCTION: _twisted-r1_camelcase
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() {
43 # IFS=- splits words by -.
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
50 if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
55 local w LC_COLLATE=C uc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
58 for w in "${words[@]}"; do
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.
65 [[ ${fl} == [a-z] ]] && fl=${uc:36#${fl} - 10:1}
73 # @ECLASS-VARIABLE: TWISTED_PN
75 # The real package name. Default to camel-case conversion of ${PN}.
77 # Example: TwistedCore
78 : ${TWISTED_PN:=$(_twisted-r1_camelcase ${PN})}
80 # @ECLASS-VARIABLE: TWISTED_P
82 # The real package name with version appended.
84 # It is used to build the default SRC_URI and S values.
86 # Example: TwistedCore-1.2.3
87 : ${TWISTED_P:=${TWISTED_PN}-${PV}}
89 # @ECLASS-VARIABLE: TWISTED_RELEASE
91 # The 'release' of Twisted. Defaults to the major & minor version
94 # It is used to build the default SRC_URI. It may be also used
95 # in dependencies against other Twisted packages.
98 : ${TWISTED_RELEASE:=$(get_version_component_range 1-2 ${PV})}
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"
108 S=${WORKDIR}/${TWISTED_P}
110 # @ECLASS-VARIABLE: TWISTED_PLUGINS
112 # An array of Twisted plugins, whose cache is regenerated
113 # in pkg_postinst() and pkg_postrm() phases.
115 # If no plugins are installed, set to empty array.
116 declare -p TWISTED_PLUGINS &>/dev/null || TWISTED_PLUGINS=( twisted.plugins )
118 # @FUNCTION: twisted-r1_python_test
120 # The common python_test() implementation that suffices for Twisted
122 twisted-r1_python_test() {
123 local sitedir=$(python_get_sitedir)
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
134 distutils_install_for_testing || die
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"
143 cd "${TEST_DIR}"/lib || die
144 trial ${PN/-/.} || die "Tests fail with ${EPYTHON}"
147 # @FUNCTION: python_test
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.
153 twisted-r1_python_test
156 # @FUNCTION: twisted-r1_src_install
158 # Default src_install() for Twisted packages. Automatically handles HTML
159 # docs (unless HTML_DOCS is set explicitly) and manpages in Twisted
161 twisted-r1_src_install() {
162 [[ -d doc ]] && local HTML_DOCS=( "${HTML_DOCS[@]:-doc/.}" )
163 [[ -d doc/man ]] && doman doc/man/*.[[:digit:]]
165 distutils-r1_src_install
168 # @FUNCTION: _twisted-r1_create_caches
169 # @USAGE: <packages>...
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
177 sys.path.insert(0, '${ROOT}$(python_get_sitedir)')
182 from twisted.plugin import getPlugins, IPlugin
183 except ImportError as e:
184 if '${EBUILD_PHASE}' == 'postinst':
187 for module in sys.argv[1:]:
189 __import__(module, globals())
190 except ImportError as e:
191 if '${EBUILD_PHASE}' == 'postinst':
194 list(getPlugins(IPlugin, sys.modules[module]))
196 "${@}" || die "twisted plugin cache update failed"
199 # @FUNCTION: twisted-r1_update_plugin_cache
201 # Update and clean up plugin caches for packages listed
202 # in TWISTED_PLUGINS.
203 twisted-r1_update_plugin_cache() {
204 [[ ${TWISTED_PLUGINS[@]} ]] || return
206 local subdirs=( "${TWISTED_PLUGINS[@]//.//}" )
207 local paths=( "${subdirs[@]/#/${ROOT}$(python_get_sitedir)/}" )
208 local caches=( "${paths[@]/%//dropin.cache}" )
210 # First, delete existing (possibly stray) caches.
211 rm -f "${caches[@]}" || die
213 # Now, let's see which ones we can regenerate.
214 _twisted-r1_create_caches "${TWISTED_PLUGINS[@]}"
216 # Finally, drop empty parent directories.
217 rmdir -p "${paths[@]}" 2>/dev/null
220 # @FUNCTION: twisted-r1_pkg_postinst
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
227 # @FUNCTION: twisted-r1_pkg_postrm
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
236 fi # ! ${_TWISTED_R1}