public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: python@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH python-r1] Support '${PYTHON_USEDEP}' in python_gen_cond_dep.
Date: Wed,  9 Apr 2014 19:36:36 +0200	[thread overview]
Message-ID: <1397064996-15765-1-git-send-email-mgorny@gentoo.org> (raw)

It is common for packages using python_gen_cond_dep to reproduce a USE
dependency for the involved package alike:

  $(python_gen_cond_dep \
    "dev-python/futures[$(python_gen_usedep 'python2*')]" \
    'python2*')

While this works, it is fairly long (usually requires wrapping twice)
and requires listing all implementations twice.

As a more friendly alternative, implement '${PYTHON_USEDEP}'
substitution like we do in python_gen_any_dep (python-any-r1). The idea
is that the USE-dependency is written as verbatim '${PYTHON_USEDEP}'
(with quotes to prevent immediate expansion):

  $(python_gen_cond_dep 'dev-python/futures[${PYTHON_USEDEP}]' \
    'python2*')

The function substitutes that string with USE-dependency string matching
the implementations passed to python_gen_cond_dep().

As with python_gen_any_dep(), the reason for choosing '${PYTHON_USEDEP}'
is fairly simple -- since ${} is used for parameter substitution
in bash, it resembles the basic syntax used everywhere else
in the eclass and is unlikely to become reserved in future EAPI.

The new behavior can be added without breaking backwards compatibility.
Ebuilds in the past were generating the USE dependency string explicitly
using primitives, and the code doing that will continue to work.
---
 eclass/python-r1.eclass | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index 57ae263..1875d5b 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -338,20 +338,24 @@ python_gen_useflags() {
 # of Python implementations which are both in PYTHON_COMPAT and match
 # any of the patterns passed as the remaining parameters.
 #
-# Please note that USE constraints on the package need to be enforced
-# separately. Therefore, the dependency usually needs to use
-# python_gen_usedep as well.
+# 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{2_5,2_6})"
+# 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_targets_python2_5? ( dev-python/unittest2 )
-#	python_targets_python2_6? ( dev-python/unittest2 )"
+# RDEPEND="python_targets_python2_5? (
+#     dev-python/unittest2[python_targets_python2_5?] )
+#	python_targets_python2_6? (
+#     dev-python/unittest2[python_targets_python2_6?] )"
 # @CODE
 python_gen_cond_dep() {
 	debug-print-function ${FUNCNAME} "${@}"
@@ -362,6 +366,12 @@ python_gen_cond_dep() {
 	local dep=${1}
 	shift
 
+	# substitute ${PYTHON_USEDEP} if used
+	if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
+		local PYTHON_USEDEP=$(python_gen_usedep "${@}")
+		dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
+	fi
+
 	for impl in "${PYTHON_COMPAT[@]}"; do
 		_python_impl_supported "${impl}" || continue
 
-- 
1.9.1



             reply	other threads:[~2014-04-09 17:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 17:36 Michał Górny [this message]
2014-04-19 10:29 ` [gentoo-dev] [PATCH python-r1] Support '${PYTHON_USEDEP}' in python_gen_cond_dep 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=1397064996-15765-1-git-send-email-mgorny@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