Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH 1/2] Introduce python_gen_usedep & python_gen_useflags for special deps.
Date: Wed, 19 Dec 2012 21:00:53
Message-Id: 1355950838-31624-1-git-send-email-mgorny@gentoo.org
1 For example, when a particular dependency applies only to some
2 of the supported Python implementations.
3
4 The next patch provides example use for them.
5 ---
6 gx86/eclass/python-r1.eclass | 78 ++++++++++++++++++++++++++++++++++++++++++++
7 1 file changed, 78 insertions(+)
8
9 diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
10 index aa9153e..40ce68b 100644
11 --- a/gx86/eclass/python-r1.eclass
12 +++ b/gx86/eclass/python-r1.eclass
13 @@ -177,6 +177,84 @@ _python_set_globals() {
14 }
15 _python_set_globals
16
17 +# @FUNCTION: python_gen_usedep
18 +# @USAGE: pattern [...]
19 +# @DESCRIPTION:
20 +# Output a USE dependency string for Python implementations which
21 +# are both in PYTHON_COMPAT and match any of the patterns passed
22 +# as parameters to the function.
23 +#
24 +# When all implementations are requested, please use ${PYTHON_USEDEP}
25 +# instead. Please also remember to set an appropriate REQUIRED_USE
26 +# to avoid ineffective USE flags.
27 +#
28 +# Example:
29 +# @CODE
30 +# PYTHON_COMPAT=( python{2_7,3_2} )
31 +# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep python2*)] )"
32 +# @CODE
33 +#
34 +# It will cause the dependency to look like:
35 +# @CODE
36 +# DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
37 +# @CODE
38 +python_gen_usedep() {
39 + debug-print-function ${FUNCNAME} "${@}"
40 +
41 + local impl pattern
42 + local matches=()
43 +
44 + for impl in "${PYTHON_COMPAT[@]}"; do
45 + for pattern; do
46 + if [[ ${impl} == ${pattern} ]]; then
47 + matches+=(
48 + "python_targets_${impl}?"
49 + "-python_single_target_${impl}(-)"
50 + )
51 + break
52 + fi
53 + done
54 + done
55 +
56 + local out=${matches[@]}
57 + echo ${out// /,}
58 +}
59 +
60 +# @FUNCTION: python_gen_useflags
61 +# @USAGE: pattern [...]
62 +# @DESCRIPTION:
63 +# Output a list of USE flags for Python implementations which
64 +# are both in PYTHON_COMPAT and match any of the patterns passed
65 +# as parameters to the function.
66 +#
67 +# Example:
68 +# @CODE
69 +# PYTHON_COMPAT=( python{2_7,3_2} )
70 +# REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
71 +# @CODE
72 +#
73 +# It will cause the variable to look like:
74 +# @CODE
75 +# REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
76 +# @CODE
77 +python_gen_useflags() {
78 + debug-print-function ${FUNCNAME} "${@}"
79 +
80 + local impl pattern
81 + local matches=()
82 +
83 + for impl in "${PYTHON_COMPAT[@]}"; do
84 + for pattern; do
85 + if [[ ${impl} == ${pattern} ]]; then
86 + matches+=( "python_targets_${impl}" )
87 + break
88 + fi
89 + done
90 + done
91 +
92 + echo ${matches[@]}
93 +}
94 +
95 # @ECLASS-VARIABLE: BUILD_DIR
96 # @DESCRIPTION:
97 # The current build directory. In global scope, it is supposed to
98 --
99 1.8.0.2

Replies