From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-python <gentoo-python@lists.gentoo.org>
Subject: [gentoo-python] [PATCH] python-single-r1: add python_gen_* functions
Date: Sun, 28 Dec 2014 18:41:32 +0100 [thread overview]
Message-ID: <20141228184132.2fd0dbf0@pomiot.lan> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 299 bytes --]
Hi,
A quick patch that adds python_gen_usedep, python_gen_useflags
and python_gen_cond_dep. It's pretty much copy-paste from python-r1
with the small changes necessary for python-single-r1 :).
Please review quickly so that we can fill in the API gaps.
--
Best regards,
Michał Górny
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: python-single-r1.eclass.diff --]
[-- Type: text/x-patch, Size: 4593 bytes --]
Index: python-single-r1.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v
retrieving revision 1.29
diff -u -B -r1.29 python-single-r1.eclass
--- python-single-r1.eclass 7 Nov 2014 18:11:58 -0000 1.29
+++ python-single-r1.eclass 28 Dec 2014 17:40:21 -0000
@@ -228,6 +228,150 @@
}
_python_single_set_globals
+# @FUNCTION: python_gen_usedep
+# @USAGE: <pattern> [...]
+# @DESCRIPTION:
+# Output a USE dependency string for Python implementations which
+# are both in PYTHON_COMPAT and match any of the patterns passed
+# as parameters to the function.
+#
+# Remember to escape or quote the patterns to premature evaluation
+# as a file name glob.
+#
+# When all implementations are requested, please use ${PYTHON_USEDEP}
+# instead. Please also remember to set an appropriate REQUIRED_USE
+# to avoid ineffective USE flags.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT=( python{2_7,3_4} )
+# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
+# @CODE
+#
+# It will cause the dependency to look like:
+# @CODE
+# DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7(-)?,...] )"
+# @CODE
+python_gen_usedep() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local impl pattern
+ local matches=()
+
+ for impl in "${PYTHON_COMPAT[@]}"; do
+ _python_impl_supported "${impl}" || continue
+
+ for pattern; do
+ if [[ ${impl} == ${pattern} ]]; then
+ matches+=(
+ "python_targets_${impl}(-)?"
+ "python_single_target_${impl}(+)?"
+ )
+ break
+ fi
+ done
+ done
+
+ [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
+
+ local out=${matches[@]}
+ echo "${out// /,}"
+}
+
+# @FUNCTION: python_gen_useflags
+# @USAGE: <pattern> [...]
+# @DESCRIPTION:
+# Output a list of USE flags for Python implementations which
+# are both in PYTHON_COMPAT and match any of the patterns passed
+# as parameters to the function.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT=( python{2_7,3_4} )
+# REQUIRED_USE="doc? ( ^^ ( $(python_gen_useflags 'python2*') ) )"
+# @CODE
+#
+# It will cause the variable to look like:
+# @CODE
+# REQUIRED_USE="doc? ( ^^ ( python_single_target_python2_7 ) )"
+# @CODE
+python_gen_useflags() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local impl pattern
+ local matches=()
+
+ for impl in "${PYTHON_COMPAT[@]}"; do
+ _python_impl_supported "${impl}" || continue
+
+ for pattern; do
+ if [[ ${impl} == ${pattern} ]]; then
+ matches+=( "python_single_target_${impl}" )
+ break
+ fi
+ done
+ done
+
+ echo "${matches[@]}"
+}
+
+# @FUNCTION: python_gen_cond_dep
+# @USAGE: <dependency> <pattern> [...]
+# @DESCRIPTION:
+# Output a list of <dependency>-ies made conditional to USE flags
+# of Python implementations which are both in PYTHON_COMPAT and match
+# any of the patterns passed as the remaining parameters.
+#
+# In order to enforce USE constraints on the packages, verbatim
+# '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
+# specification. It will get expanded within the function into a proper
+# USE dependency string.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT=( python{2_5,2_6,2_7} )
+# RDEPEND="$(python_gen_cond_dep \
+# 'dev-python/unittest2[${PYTHON_USEDEP}]' python{2_5,2_6})"
+# @CODE
+#
+# It will cause the variable to look like:
+# @CODE
+# RDEPEND="python_single_target_python2_5? (
+# dev-python/unittest2[python_targets_python2_5(-)?,...] )
+# python_single_target_python2_6? (
+# dev-python/unittest2[python_targets_python2_6(-)?,...] )"
+# @CODE
+python_gen_cond_dep() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local impl pattern
+ local matches=()
+
+ local dep=${1}
+ shift
+
+ for impl in "${PYTHON_COMPAT[@]}"; do
+ _python_impl_supported "${impl}" || continue
+
+ for pattern; do
+ if [[ ${impl} == ${pattern} ]]; then
+ # substitute ${PYTHON_USEDEP} if used
+ # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
+ # the code is run at most once)
+ if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
+ local PYTHON_USEDEP=$(python_gen_usedep "${@}")
+ dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
+ fi
+
+ matches+=( "python_single_target_${impl}? ( ${dep} )" )
+ break
+ fi
+ done
+ done
+
+ echo "${matches[@]}"
+}
+
# @FUNCTION: python_setup
# @DESCRIPTION:
# Determine what the selected Python implementation is and set
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]
next reply other threads:[~2014-12-28 18:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-28 17:41 Michał Górny [this message]
2014-12-28 20:17 ` [gentoo-python] [PATCH] python-single-r1: add python_gen_* functions Mike Gilbert
2014-12-28 22:55 ` 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=20141228184132.2fd0dbf0@pomiot.lan \
--to=mgorny@gentoo.org \
--cc=gentoo-python@lists.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