Re: [gentoo-dev] [PATCH python-r1] Support '${PYTHON_USEDEP}' in python_gen_cond_dep.

2014-04-19 Thread Michał Górny
Committed as r1.72.

-- 
Best regards,
Michał Górny


signature.asc
Description: PGP signature


[gentoo-dev] [PATCH python-r1] Support '${PYTHON_USEDEP}' in python_gen_cond_dep.

2014-04-09 Thread Michał Górny
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