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 v2] python*-r1.eclass: Deprecate python_gen_usedep
Date: Sat, 30 Nov 2019 10:08:40
Message-Id: 20191130100807.64406-1-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH] python*-r1.eclass: Deprecate python_gen_usedep by "Michał Górny"
1 Deprecate python_gen_usedep() in favor of python_gen_cond_dep().
2 The latter is a newer API that generates full USE-conditional blocks
3 rather than pure USE-dependency strings. As such, it can replace all
4 uses of the former, and is safer to use in general. In particular:
5
6 dev-python/foo[$(python_gen_usedep -2)]
7 dev-python/bar[$(python_gen_usedep -2)]
8
9 installs the dependency (with no implementation match enforced) even
10 if there's no python2 implementation enabled, while:
11
12 $(python_gen_cond_dep '
13 dev-python/foo[${PYTHON_USEDEP}]
14 dev-python/bar[${PYTHON_USEDEP}]
15 ' -2)
16
17 installs it only if there's at least one implementation requiring it.
18
19 Since the functions are used in global scope only, a deprecation warning
20 is emitted only once, during the sourcing for pkg_setup phase. This
21 avoids having it output during metadata cache regeneration.
22
23 Signed-off-by: Michał Górny <mgorny@g.o>
24 ---
25 eclass/python-r1.eclass | 61 +++++++++++++++++++++++++---------
26 eclass/python-single-r1.eclass | 61 +++++++++++++++++++++++++---------
27 2 files changed, 90 insertions(+), 32 deletions(-)
28
29 Changes in v2:
30 - call _python_gen_usedep in python_gen_cond_dep
31
32 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
33 index 335ae9fe6370..ea4d1e3d4e41 100644
34 --- a/eclass/python-r1.eclass
35 +++ b/eclass/python-r1.eclass
36 @@ -276,9 +276,47 @@ _python_validate_useflags() {
37 die "No supported Python implementation in PYTHON_TARGETS."
38 }
39
40 +# @FUNCTION: _python_gen_usedep
41 +# @INTERNAL
42 +# @USAGE: <pattern> [...]
43 +# @DESCRIPTION:
44 +# Output a USE dependency string for Python implementations which
45 +# are both in PYTHON_COMPAT and match any of the patterns passed
46 +# as parameters to the function.
47 +#
48 +# The patterns can be either fnmatch-style patterns (matched via bash
49 +# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
50 +# appropriately all enabled Python 2/3 implementations (alike
51 +# python_is_python3). Remember to escape or quote the fnmatch patterns
52 +# to prevent accidental shell filename expansion.
53 +#
54 +# This is an internal function used to implement python_gen_cond_dep
55 +# and deprecated python_gen_usedep.
56 +_python_gen_usedep() {
57 + debug-print-function ${FUNCNAME} "${@}"
58 +
59 + local impl matches=()
60 +
61 + for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
62 + if _python_impl_matches "${impl}" "${@}"; then
63 + matches+=(
64 + "python_targets_${impl}(-)?"
65 + "-python_single_target_${impl}(-)"
66 + )
67 + fi
68 + done
69 +
70 + [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
71 +
72 + local out=${matches[@]}
73 + echo "${out// /,}"
74 +}
75 +
76 # @FUNCTION: python_gen_usedep
77 # @USAGE: <pattern> [...]
78 # @DESCRIPTION:
79 +# DEPRECATED. Please use python_gen_cond_dep instead.
80 +#
81 # Output a USE dependency string for Python implementations which
82 # are both in PYTHON_COMPAT and match any of the patterns passed
83 # as parameters to the function.
84 @@ -306,21 +344,12 @@ _python_validate_useflags() {
85 python_gen_usedep() {
86 debug-print-function ${FUNCNAME} "${@}"
87
88 - local impl matches=()
89 -
90 - for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
91 - if _python_impl_matches "${impl}" "${@}"; then
92 - matches+=(
93 - "python_targets_${impl}(-)?"
94 - "-python_single_target_${impl}(-)"
95 - )
96 - fi
97 - done
98 -
99 - [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
100 -
101 - local out=${matches[@]}
102 - echo "${out// /,}"
103 + # output only once, during some reasonable phase
104 + # (avoid spamming cache regen runs)
105 + if [[ ${EBUILD_PHASE} == setup ]]; then
106 + eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead."
107 + fi
108 + _python_gen_usedep "${@}"
109 }
110
111 # @FUNCTION: python_gen_useflags
112 @@ -405,7 +434,7 @@ python_gen_cond_dep() {
113 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
114 # the code is run at most once)
115 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
116 - local usedep=$(python_gen_usedep "${@}")
117 + local usedep=$(_python_gen_usedep "${@}")
118 dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
119 fi
120
121 diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
122 index 8ac17b7815e2..47176f79e6ad 100644
123 --- a/eclass/python-single-r1.eclass
124 +++ b/eclass/python-single-r1.eclass
125 @@ -265,9 +265,47 @@ unset -f _python_single_set_globals
126
127 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
128
129 +# @FUNCTION: _python_gen_usedep
130 +# @INTERNAL
131 +# @USAGE: <pattern> [...]
132 +# @DESCRIPTION:
133 +# Output a USE dependency string for Python implementations which
134 +# are both in PYTHON_COMPAT and match any of the patterns passed
135 +# as parameters to the function.
136 +#
137 +# The patterns can be either fnmatch-style patterns (matched via bash
138 +# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
139 +# appropriately all enabled Python 2/3 implementations (alike
140 +# python_is_python3). Remember to escape or quote the fnmatch patterns
141 +# to prevent accidental shell filename expansion.
142 +#
143 +# This is an internal function used to implement python_gen_cond_dep
144 +# and deprecated python_gen_usedep.
145 +_python_gen_usedep() {
146 + debug-print-function ${FUNCNAME} "${@}"
147 +
148 + local impl matches=()
149 +
150 + for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
151 + if _python_impl_matches "${impl}" "${@}"; then
152 + matches+=(
153 + "python_targets_${impl}(-)?"
154 + "python_single_target_${impl}(+)?"
155 + )
156 + fi
157 + done
158 +
159 + [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
160 +
161 + local out=${matches[@]}
162 + echo "${out// /,}"
163 +}
164 +
165 # @FUNCTION: python_gen_usedep
166 # @USAGE: <pattern> [...]
167 # @DESCRIPTION:
168 +# DEPRECATED. Please use python_gen_cond_dep instead.
169 +#
170 # Output a USE dependency string for Python implementations which
171 # are both in PYTHON_COMPAT and match any of the patterns passed
172 # as parameters to the function.
173 @@ -295,21 +333,12 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
174 python_gen_usedep() {
175 debug-print-function ${FUNCNAME} "${@}"
176
177 - local impl matches=()
178 -
179 - for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
180 - if _python_impl_matches "${impl}" "${@}"; then
181 - matches+=(
182 - "python_targets_${impl}(-)?"
183 - "python_single_target_${impl}(+)?"
184 - )
185 - fi
186 - done
187 -
188 - [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
189 -
190 - local out=${matches[@]}
191 - echo "${out// /,}"
192 + # output only once, during some reasonable phase
193 + # (avoid spamming cache regen runs)
194 + if [[ ${EBUILD_PHASE} == setup ]]; then
195 + eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead."
196 + fi
197 + _python_gen_usedep "${@}"
198 }
199
200 # @FUNCTION: python_gen_useflags
201 @@ -407,7 +436,7 @@ python_gen_cond_dep() {
202 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
203 # the code is run at most once)
204 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
205 - local usedep=$(python_gen_usedep "${@}")
206 + local usedep=$(_python_gen_usedep "${@}")
207 dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
208 fi
209
210 --
211 2.24.0