Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH python-r1] Support '${PYTHON_USEDEP}' in python_gen_cond_dep.
Date: Wed, 09 Apr 2014 17:37:05
Message-Id: 1397064996-15765-1-git-send-email-mgorny@gentoo.org
1 It is common for packages using python_gen_cond_dep to reproduce a USE
2 dependency for the involved package alike:
3
4 $(python_gen_cond_dep \
5 "dev-python/futures[$(python_gen_usedep 'python2*')]" \
6 'python2*')
7
8 While this works, it is fairly long (usually requires wrapping twice)
9 and requires listing all implementations twice.
10
11 As a more friendly alternative, implement '${PYTHON_USEDEP}'
12 substitution like we do in python_gen_any_dep (python-any-r1). The idea
13 is that the USE-dependency is written as verbatim '${PYTHON_USEDEP}'
14 (with quotes to prevent immediate expansion):
15
16 $(python_gen_cond_dep 'dev-python/futures[${PYTHON_USEDEP}]' \
17 'python2*')
18
19 The function substitutes that string with USE-dependency string matching
20 the implementations passed to python_gen_cond_dep().
21
22 As with python_gen_any_dep(), the reason for choosing '${PYTHON_USEDEP}'
23 is fairly simple -- since ${} is used for parameter substitution
24 in bash, it resembles the basic syntax used everywhere else
25 in the eclass and is unlikely to become reserved in future EAPI.
26
27 The new behavior can be added without breaking backwards compatibility.
28 Ebuilds in the past were generating the USE dependency string explicitly
29 using primitives, and the code doing that will continue to work.
30 ---
31 eclass/python-r1.eclass | 22 ++++++++++++++++------
32 1 file changed, 16 insertions(+), 6 deletions(-)
33
34 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
35 index 57ae263..1875d5b 100644
36 --- a/eclass/python-r1.eclass
37 +++ b/eclass/python-r1.eclass
38 @@ -338,20 +338,24 @@ python_gen_useflags() {
39 # of Python implementations which are both in PYTHON_COMPAT and match
40 # any of the patterns passed as the remaining parameters.
41 #
42 -# Please note that USE constraints on the package need to be enforced
43 -# separately. Therefore, the dependency usually needs to use
44 -# python_gen_usedep as well.
45 +# In order to enforce USE constraints on the packages, verbatim
46 +# '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
47 +# specification. It will get expanded within the function into a proper
48 +# USE dependency string.
49 #
50 # Example:
51 # @CODE
52 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
53 -# RDEPEND="$(python_gen_cond_dep dev-python/unittest2 python{2_5,2_6})"
54 +# RDEPEND="$(python_gen_cond_dep \
55 +# 'dev-python/unittest2[${PYTHON_USEDEP}]' python{2_5,2_6})"
56 # @CODE
57 #
58 # It will cause the variable to look like:
59 # @CODE
60 -# RDEPEND="python_targets_python2_5? ( dev-python/unittest2 )
61 -# python_targets_python2_6? ( dev-python/unittest2 )"
62 +# RDEPEND="python_targets_python2_5? (
63 +# dev-python/unittest2[python_targets_python2_5?] )
64 +# python_targets_python2_6? (
65 +# dev-python/unittest2[python_targets_python2_6?] )"
66 # @CODE
67 python_gen_cond_dep() {
68 debug-print-function ${FUNCNAME} "${@}"
69 @@ -362,6 +366,12 @@ python_gen_cond_dep() {
70 local dep=${1}
71 shift
72
73 + # substitute ${PYTHON_USEDEP} if used
74 + if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
75 + local PYTHON_USEDEP=$(python_gen_usedep "${@}")
76 + dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
77 + fi
78 +
79 for impl in "${PYTHON_COMPAT[@]}"; do
80 _python_impl_supported "${impl}" || continue
81
82 --
83 1.9.1

Replies