1 # Copyright 1999-2018 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 # @SUPPORTED_EAPIS: 4 5
11 # @BLURB: Eclass for Twisted packages
13 # The twisted eclass defines phase functions for Twisted packages.
17 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
22 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
26 if [[ ! ${_TWISTED_R1} ]]; then
28 inherit distutils-r1 versionator
32 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
34 if [[ ! ${_TWISTED_R1} ]]; then
36 # @FUNCTION: _twisted-r1_camelcase
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() {
44 # IFS=- splits words by -.
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
51 if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
56 local w LC_COLLATE=C uc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
59 for w in "${words[@]}"; do
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.
66 [[ ${fl} == [a-z] ]] && fl=${uc:36#${fl} - 10:1}
74 # @ECLASS-VARIABLE: TWISTED_PN
76 # The real package name. Default to camel-case conversion of ${PN}.
78 # Example: TwistedCore
79 : ${TWISTED_PN:=$(_twisted-r1_camelcase ${PN})}
81 # @ECLASS-VARIABLE: TWISTED_P
83 # The real package name with version appended.
85 # It is used to build the default SRC_URI and S values.
87 # Example: TwistedCore-1.2.3
88 : ${TWISTED_P:=${TWISTED_PN}-${PV}}
90 # @ECLASS-VARIABLE: TWISTED_RELEASE
92 # The 'release' of Twisted. Defaults to the major & minor version
95 # It is used to build the default SRC_URI. It may be also used
96 # in dependencies against other Twisted packages.
99 : ${TWISTED_RELEASE:=$(get_version_component_range 1-2 ${PV})}
101 HOMEPAGE="https://www.twistedmatrix.com/trac/"
102 SRC_URI="https://twistedmatrix.com/Releases/${TWISTED_PN#Twisted}"
103 SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2"
109 S=${WORKDIR}/${TWISTED_P}
111 # @ECLASS-VARIABLE: TWISTED_PLUGINS
113 # An array of Twisted plugins, whose cache is regenerated
114 # in pkg_postinst() and pkg_postrm() phases.
116 # If no plugins are installed, set to empty array.
117 declare -p TWISTED_PLUGINS &>/dev/null || TWISTED_PLUGINS=( twisted.plugins )
119 # @FUNCTION: twisted-r1_python_test
121 # The common python_test() implementation that suffices for Twisted
123 twisted-r1_python_test() {
124 local sitedir=$(python_get_sitedir)
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
135 distutils_install_for_testing || die
137 if [[ ${TEST_DIR} != ${BUILD_DIR}/test ]]; then
138 eerror "twisted-r1 integrity check failed."
139 eerror "TEST_DIR: ${TEST_DIR}"
140 eerror "expected: ${BUILD_DIR}/test"
141 die "TEST_DIR integrity check failed"
144 cd "${TEST_DIR}"/lib || die
145 trial ${PN/-/.} || die "Tests fail with ${EPYTHON}"
148 # @FUNCTION: python_test
150 # Default python_test() for Twisted packages. If you need to override
151 # it, you can access the original implementation
152 # via twisted-r1_python_test.
154 twisted-r1_python_test
157 # @FUNCTION: twisted-r1_src_install
159 # Default src_install() for Twisted packages. Automatically handles HTML
160 # docs (unless HTML_DOCS is set explicitly) and manpages in Twisted
162 twisted-r1_src_install() {
163 [[ -d doc ]] && local HTML_DOCS=( "${HTML_DOCS[@]:-doc/.}" )
164 [[ -d doc/man ]] && doman doc/man/*.[[:digit:]]
166 distutils-r1_src_install
169 # @FUNCTION: _twisted-r1_create_caches
170 # @USAGE: <packages>...
172 # Create dropin.cache for plugins in specified packages. The packages
173 # are to be listed in standard dotted Python syntax.
174 _twisted-r1_create_caches() {
175 # http://twistedmatrix.com/documents/current/core/howto/plugin.html
178 sys.path.insert(0, '${ROOT}$(python_get_sitedir)')
183 from twisted.plugin import getPlugins, IPlugin
184 except ImportError as e:
185 if '${EBUILD_PHASE}' == 'postinst':
188 for module in sys.argv[1:]:
190 __import__(module, globals())
191 except ImportError as e:
192 if '${EBUILD_PHASE}' == 'postinst':
195 list(getPlugins(IPlugin, sys.modules[module]))
197 "${@}" || die "twisted plugin cache update failed"
200 # @FUNCTION: twisted-r1_update_plugin_cache
202 # Update and clean up plugin caches for packages listed
203 # in TWISTED_PLUGINS.
204 twisted-r1_update_plugin_cache() {
205 [[ ${TWISTED_PLUGINS[@]} ]] || return
207 local subdirs=( "${TWISTED_PLUGINS[@]//.//}" )
208 local paths=( "${subdirs[@]/#/${ROOT}$(python_get_sitedir)/}" )
209 local caches=( "${paths[@]/%//dropin.cache}" )
211 # First, delete existing (possibly stray) caches.
212 rm -f "${caches[@]}" || die
214 # Now, let's see which ones we can regenerate.
215 _twisted-r1_create_caches "${TWISTED_PLUGINS[@]}"
217 # Finally, drop empty parent directories.
218 rmdir -p "${paths[@]}" 2>/dev/null
221 # @FUNCTION: twisted-r1_pkg_postinst
223 # Post-installation hook for twisted-r1. Updates plugin caches.
224 twisted-r1_pkg_postinst() {
225 _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
228 # @FUNCTION: twisted-r1_pkg_postrm
230 # Post-removal hook for twisted-r1. Updates plugin caches.
231 twisted-r1_pkg_postrm() {
232 _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
237 fi # ! ${_TWISTED_R1}