From: "Michał Górny" <mgorny@gentoo.org>
To: Gentoo Developer Mailing List <gentoo-dev@lists.gentoo.org>
Cc: python@gentoo.org
Subject: [gentoo-dev] [New eclass] twisted-r1.eclass
Date: Sat, 3 Aug 2013 17:13:03 +0200 [thread overview]
Message-ID: <20130803171303.18911eba@gentoo.org> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1328 bytes --]
Hello,
We've been working with yac for a while to get the old twisted.eclass
converted to be compliant with distutils-r1 both in design
and in spirit. This is the first version we'd like to submit for review.
A few notes:
1. The eclass aims to be less conditional than the old one. Especially
we've dropped all the ${CATEGORY}/${PN} checks. The code still sets all
the funny defaults for Twisted suite but those aren't incremental
and can easily be overrode in ebuilds. And in most cases, they simple
are (SRC_URI, LICENSE).
2. The eclass comes with a pure bash-3.2 CamelCase converter
for changing PNs like 'twisted-foo' into 'TwistedFoo'. The relevant
code can be moved to eutils as portable replacements for bash-4 ${foo^}
and friends.
3. The eclass provides a reusable twisted-r1_python_test and sets it as
default python_test. If someone needs to override it, he can still call
it using the former name.
4. Cache updating hack is based off twisted.eclass. Sadly, it's not
something we can do without postrm/postinst. Similarly to the old
eclass, TWISTED_PLUGINS needs to list the plugin locations. Since most
ebuilds install to twisted.plugins, it defaults to that. If an ebuild
does not install plugins at all, it needs to set empty TWISTED_PLUGINS.
--
Best regards,
Michał Górny
[-- Attachment #1.2: twisted-r1.eclass --]
[-- Type: text/plain, Size: 5918 bytes --]
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/eclass/twisted.eclass,v 1.10 2011/12/27 06:54:23 floppym Exp $
# @ECLASS: twisted-r1.eclass
# @MAINTAINER:
# Gentoo Python Project <python@gentoo.org>
# @AUTHOR:
# Author: MichaŠGórny <mgorny@gentoo.org>
# Author: Jan Matejka <yac@gentoo.org>
# @BLURB: Eclass for Twisted packages
# @DESCRIPTION:
# The twisted eclass defines phase functions for Twisted packages.
case "${EAPI:-0}" in
0|1|2|3)
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
;;
4|5)
;;
*)
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
;;
esac
if [[ ! ${_TWISTED_R1} ]]; then
inherit distutils-r1 versionator
fi # ! ${_TWISTED_R1}
EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
if [[ ! ${_TWISTED_R1} ]]; then
# @FUNCTION: _twisted_camelcase
# @USAGE: <package-name>
# @DESCRIPTION:
# Convert dash-separated package name to CamelCase. In pure bash.
# Really.
_twisted_camelcase() {
local pn=${1}
local save_IFS=${IFS}
local IFS=-
# IFS=- splits words by -.
local w words=( ${pn} )
local IFS=${save_IFS}
for w in "${words[@]}"; do
local fl=${w:0:1}
# obtain octal ASCII code for the first letter.
local ord=$(printf '%o' "'${fl}")
# check if it's [a-z]. ASCII codes are locale-safe.
if [[ ${ord} -ge 141 && ${ord} -le 172 ]]; then
# now substract 040 to make it upper-case.
# fun fact: in range 0141..0172, decimal '- 40' is fine.
local ord=$(( ${ord} - 40))
# and convert it back to the character.
fl=$(printf '\'${ord})
fi
echo -n "${fl}${w:1}"
done
}
# @ECLASS-VARIABLE: TWISTED_PN
# @DESCRIPTION:
# The Twisted CamelCase converted form of package name.
#
# Example: TwistedCore
TWISTED_PN=$(_twisted_camelcase ${PN})
# @ECLASS-VARIABLE: TWISTED_P
# @DESCRIPTION:
# The Twisted CamelCase package name & version.
#
# Example: TwistedCore-1.2.3
TWISTED_P=${TWISTED_PN}-${PV}
HOMEPAGE="http://www.twistedmatrix.com/"
SRC_URI="http://twistedmatrix.com/Releases/${TWISTED_PN}"
SRC_URI="${SRC_URI}/$(get_version_component_range 1-2 ${PV})"
SRC_URI="${SRC_URI}/${TWISTED_P}.tar.bz2"
LICENSE="MIT"
SLOT="0"
IUSE=""
S=${WORKDIR}/${TWISTED_P}
# @ECLASS-VARIABLE: TWISTED_PLUGINS
# @DESCRIPTION:
# An array of Twisted plugins, whose cache is regenerated
# in pkg_postinst() and pkg_postrm() phases.
#
# If no plugins are installed, set to empty array.
[[ ${TWISTED_PLUGINS[@]} ]] || TWISTED_PLUGINS=( twisted.plugins )
# @FUNCTION: twisted-r1_python_test
# @DESCRIPTION:
# The common python_test() implementation that suffices Twisted
# packages.
twisted-r1_python_test() {
local sitedir=$(python_get_sitedir)
# Copy modules of other Twisted packages from site-packages
# directory to the temporary directory.
local libdir=${BUILD_DIR}/test/lib
mkdir -p "${libdir}" || die
cp -r "${ROOT}${sitedir}"/twisted "${libdir}" || die
# Drop the installed module in case previous version conflicts with
# the new one somehow.
rm -fr "${libdir}/${PN/-//}" || die
distutils_install_for_testing || die
cd "${TEST_DIR}"/lib || die
trial ${PN/-/.} || die "Tests fail with ${EPYTHON}"
}
# @FUNCTION: python_test
# @DESCRIPTION:
# Default python_test() for Twisted packages. If you need to override
# it, you can access the original implementation
# via twisted-r1_python_test.
python_test() {
twisted-r1_python_test
}
# @FUNCTION: twisted-r1_src_install
# @DESCRIPTION:
# Default src_install() for Twisted packages. Automatically handles HTML
# docs and manpages in Twisted packages
twisted-r1_src_install() {
# TODO: doesn't this accidentially involve installing manpages? ;f
if [[ ${CATEGORY}/${PN} == dev-python/twisted* && -d doc ]]; then
local HTML_DOCS=( doc/. )
fi
distutils-r1_src_install
[[ -d doc/man ]] && doman doc/man/*.[[:digit:]]
}
# @FUNCTION: _twisted-r1_create_caches
# @USAGE: <packages>...
# @DESCRIPTION:
# Create dropin.cache for plugins in specified packages. The packages
# are to be listed in standard dotted Python syntax.
_twisted-r1_create_caches() {
# http://twistedmatrix.com/documents/current/core/howto/plugin.html
"${PYTHON}" -c \
"import sys
sys.path.insert(0, '${ROOT}$(python_get_sitedir)')
fail = False
try:
from twisted.plugin import getPlugins, IPlugin
except ImportError as e:
if '${EBUILD_PHASE}' == 'postinst':
raise
else:
for module in sys.argv[1:]:
try:
__import__(module, globals())
except ImportError as e:
if '${EBUILD_PHASE}' == 'postinst':
raise
else:
list(getPlugins(IPlugin, sys.modules[module]))
" \
"${@}" || die "twisted plugin cache update failed"
}
# @FUNCTION: twisted-r1_update_plugin_cache
# @DESCRIPTION:
# Update and clean up plugin caches for packages listed
# in TWISTED_PLUGINS.
twisted-r1_update_plugin_cache() {
local subdirs=( "${TWISTED_PLUGINS[@]//.//}" )
local paths=( "${subdirs[@]/#/${ROOT}$(python_get_sitedir)/}" )
local caches=( "${paths[@]/%//dropin.cache}" )
# First, delete existing (possibly stray) caches.
rm -f "${caches[@]}" || die
# Now, let's see which ones we can regenerate.
_twisted-r1_create_caches "${TWISTED_PLUGINS[@]}"
# Finally, drop empty parent directories.
rmdir -p "${paths[@]}" 2>/dev/null
}
# @FUNCTION: twisted-r1_pkg_postinst
# @DESCRIPTION:
# Post-installation hook for twisted-r1. Updates plugin caches.
twisted-r1_pkg_postinst() {
_distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
}
# @FUNCTION: twisted-r1_pkg_postrm
# @DESCRIPTION:
# Post-removal hook for twisted-r1. Updates plugin caches.
twisted-r1_pkg_postrm() {
_distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
}
_TWISTED_R1=1
fi # ! ${_TWISTED_R1}
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]
next reply other threads:[~2013-08-03 15:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-03 15:13 Michał Górny [this message]
2013-08-03 15:54 ` [gentoo-dev] [New eclass] twisted-r1.eclass Ulrich Mueller
2013-08-03 18:29 ` Michał Górny
2013-08-03 19:37 ` Ulrich Mueller
2013-08-03 19:42 ` Michał Górny
2013-08-03 19:37 ` Alex Xu
2013-08-03 19:47 ` Alex Xu
2013-08-03 19:49 ` Michał Górny
2013-08-03 21:57 ` Michał Górny
2013-08-03 22:28 ` Michał Górny
2013-08-04 5:15 ` [gentoo-dev] " Marien Zwart
2013-08-04 7:34 ` Michał Górny
2013-08-04 12:37 ` [gentoo-dev] " Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130803171303.18911eba@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
--cc=python@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox