Gentoo Archives: gentoo-python

From: Mike Gilbert <floppym@g.o>
To: "Michał Górny" <mgorny@g.o>
Cc: gentoo-python@l.g.o, python@g.o
Subject: [gentoo-python] Re: [PATCH] Validate PYTHON_COMPAT, support disabling implementations.
Date: Mon, 21 Jan 2013 17:19:50
Message-Id: 50FD78AC.5050303@gentoo.org
In Reply to: [gentoo-python] [PATCH] Validate PYTHON_COMPAT, support disabling implementations. by "Michał Górny"
1 On 1/14/2013 6:03 AM, Michał Górny wrote:
2 > Now eclasses die with invalid implementations in PYTHON_COMPAT (well,
3 > except for python-any-r1 which barely looks at PYTHON_COMPAT and more
4 > relies on _PYTHON_ALL_IMPLS) and can omit the implementations which will
5 > be marked as 'removed' (for upcoming pypy1.8 cleanup).
6 > ---
7 > gx86/eclass/python-any-r1.eclass | 11 ++++-----
8 > gx86/eclass/python-r1.eclass | 49 +++++++++++++++++++++++++++++--------
9 > gx86/eclass/python-single-r1.eclass | 39 +++++++++++++++++++----------
10 > gx86/eclass/python-utils-r1.eclass | 31 +++++++++++++++++++++++
11 > 4 files changed, 101 insertions(+), 29 deletions(-)
12 >
13 > diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
14 > index 199602a..492ab27 100644
15 > --- a/gx86/eclass/python-any-r1.eclass
16 > +++ b/gx86/eclass/python-any-r1.eclass
17 > @@ -134,13 +134,13 @@ _python_build_set_globals() {
18 > }
19 > _python_build_set_globals
20 >
21 > -# @FUNCTION: _python_impl_supported
22 > +# @FUNCTION: _python_EPYTHON_supported
23 > # @USAGE: <epython>
24 > # @INTERNAL
25 > # @DESCRIPTION:
26 > # Check whether the specified implementation is supported by package
27 > # (specified in PYTHON_COMPAT).
28 > -_python_impl_supported() {
29 > +_python_EPYTHON_supported() {
30 > debug-print-function ${FUNCNAME} "${@}"
31 >
32 > local i=${1/./_}
33 > @@ -153,6 +153,7 @@ _python_impl_supported() {
34 > ;;
35 > *)
36 > ewarn "Invalid EPYTHON: ${EPYTHON}"
37 > + return 1
38 > ;;
39 > esac
40 >
41 > @@ -173,7 +174,7 @@ python-any-r1_pkg_setup() {
42 >
43 > # first, try ${EPYTHON}... maybe it's good enough for us.
44 > if [[ ${EPYTHON} ]]; then
45 > - if _python_impl_supported "${EPYTHON}"; then
46 > + if _python_EPYTHON_supported "${EPYTHON}"; then
47 > python_export EPYTHON PYTHON
48 > return
49 > fi
50 > @@ -187,7 +188,7 @@ python-any-r1_pkg_setup() {
51 > if [[ ! ${i} ]]; then
52 > # no eselect-python?
53 > break
54 > - elif _python_impl_supported "${i}"; then
55 > + elif _python_EPYTHON_supported "${i}"; then
56 > python_export "${i}" EPYTHON PYTHON
57 > return
58 > fi
59 > @@ -206,8 +207,6 @@ python-any-r1_pkg_setup() {
60 > python_export "${i}" PYTHON_PKG_DEP EPYTHON PYTHON
61 > ROOT=/ has_version "${PYTHON_PKG_DEP}" && return
62 > done
63 > -
64 > - die $EPYTHON
65 > }
66 >
67 > _PYTHON_ANY_R1=1
68 > diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
69 > index 8557727..5067931 100644
70 > --- a/gx86/eclass/python-r1.eclass
71 > +++ b/gx86/eclass/python-r1.eclass
72 > @@ -132,7 +132,23 @@ fi
73 > # @CODE
74 >
75 > _python_set_globals() {
76 > - local flags=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
77 > + local impls=() PYTHON_DEPS=
78
79 PYTHON_DEPS should be a global here. I pointed this out in IRC, just
80 stating it here for posterity.
81
82 > +
83 > + local i PYTHON_PKG_DEP
84 > + for i in "${PYTHON_COMPAT[@]}"; do
85 > + _python_impl_supported "${i}" || continue
86 > +
87 > + python_export "${i}" PYTHON_PKG_DEP
88 > + PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
89 > +
90 > + impls+=( "${i}" )
91 > + done
92 > +
93 > + if [[ ${#impls[@]} -eq 0 ]]; then
94 > + die "No supported implementation in PYTHON_COMPAT."
95 > + fi
96 > +
97 > + local flags=( "${impls[@]/#/python_targets_}" )
98 > local optflags=${flags[@]/%/?}
99 >
100 > # A nice QA trick here. Since a python-single-r1 package has to have
101 > @@ -141,7 +157,7 @@ _python_set_globals() {
102 > # it should prevent developers from mistakenly depending on packages
103 > # not supporting multiple Python implementations.
104 >
105 > - local flags_st=( "${PYTHON_COMPAT[@]/#/-python_single_target_}" )
106 > + local flags_st=( "${impls[@]/#/-python_single_target_}" )
107 > optflags+=,${flags_st[@]/%/(-)}
108 >
109 > IUSE=${flags[*]}
110 > @@ -152,12 +168,7 @@ _python_set_globals() {
111 > # but no point in making this overcomplex, BDEP doesn't hurt anyone
112 > # 2) python-exec should be built with all targets forced anyway
113 > # but if new targets were added, we may need to force a rebuild
114 > - PYTHON_DEPS="dev-python/python-exec[${PYTHON_USEDEP}]"
115 > - local i PYTHON_PKG_DEP
116 > - for i in "${PYTHON_COMPAT[@]}"; do
117 > - python_export "${i}" PYTHON_PKG_DEP
118 > - PYTHON_DEPS+=" python_targets_${i}? ( ${PYTHON_PKG_DEP} )"
119 > - done
120 > + PYTHON_DEPS+="dev-python/python-exec[${PYTHON_USEDEP}]"
121 > }
122 > _python_set_globals
123 >
124 > @@ -171,6 +182,8 @@ _python_validate_useflags() {
125 > local i
126 >
127 > for i in "${PYTHON_COMPAT[@]}"; do
128 > + _python_impl_supported "${i}" || continue
129 > +
130
131 Just a style thing: The blank line in these 2 statement for loops seems
132 odd to me. Maybe your brain works differently.
133
134 > use "python_targets_${i}" && return 0
135 > done
136 >
137 > @@ -210,6 +223,8 @@ python_gen_usedep() {
138 > local matches=()
139 >
140 > for impl in "${PYTHON_COMPAT[@]}"; do
141 > + _python_impl_supported "${impl}" || continue
142 > +
143 > for pattern; do
144 > if [[ ${impl} == ${pattern} ]]; then
145 > matches+=(
146 > @@ -249,6 +264,8 @@ python_gen_useflags() {
147 > local matches=()
148 >
149 > for impl in "${PYTHON_COMPAT[@]}"; do
150 > + _python_impl_supported "${impl}" || continue
151 > +
152 > for pattern; do
153 > if [[ ${impl} == ${pattern} ]]; then
154 > matches+=( "python_targets_${impl}" )
155 > @@ -292,6 +309,8 @@ python_gen_cond_dep() {
156 > shift
157 >
158 > for impl in "${PYTHON_COMPAT[@]}"; do
159 > + _python_impl_supported "${impl}" || continue
160 > +
161 > for pattern; do
162 > if [[ ${impl} == ${pattern} ]]; then
163 > matches+=( "python_targets_${impl}? ( ${dep} )" )
164 > @@ -337,6 +356,8 @@ python_copy_sources() {
165 > einfo "Will copy sources from ${S}"
166 > # the order is irrelevant here
167 > for impl in "${PYTHON_COMPAT[@]}"; do
168 > + _python_impl_supported "${impl}" || continue
169 > +
170 > if use "python_targets_${impl}"
171 > then
172 > local BUILD_DIR=${bdir%%/}-${impl}
173 > @@ -369,6 +390,8 @@ _python_check_USE_PYTHON() {
174 >
175 > local impl py2 py3 dis_py2 dis_py3
176 > for impl in "${PYTHON_COMPAT[@]}"; do
177 > + _python_impl_supported "${impl}" || continue
178 > +
179 > if use "python_targets_${impl}"; then
180 > case "${impl}" in
181 > python2_*)
182 > @@ -480,6 +503,8 @@ _python_check_USE_PYTHON() {
183 > local impl old=${USE_PYTHON} new=() removed=()
184 >
185 > for impl in "${PYTHON_COMPAT[@]}"; do
186 > + _python_impl_supported "${impl}" || continue
187 > +
188 > local abi
189 > case "${impl}" in
190 > python*)
191 > @@ -573,7 +598,9 @@ python_foreach_impl() {
192 >
193 > debug-print "${FUNCNAME}: bdir = ${bdir}"
194 > for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
195 > - if has "${impl}" "${PYTHON_COMPAT[@]}" && use "python_targets_${impl}"
196 > + if has "${impl}" "${PYTHON_COMPAT[@]}" \
197 > + && _python_impl_supported "${impl}" \
198 > + && use "python_targets_${impl}"
199 > then
200 > local EPYTHON PYTHON
201 > python_export "${impl}" EPYTHON PYTHON
202 > @@ -601,7 +628,9 @@ python_export_best() {
203 >
204 > local impl best
205 > for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
206 > - if has "${impl}" "${PYTHON_COMPAT[@]}" && use "python_targets_${impl}"
207 > + if has "${impl}" "${PYTHON_COMPAT[@]}" \
208 > + && _python_impl_supported "${impl}" \
209 > + && use "python_targets_${impl}"
210 > then
211 > best=${impl}
212 > fi
213 > diff --git a/gx86/eclass/python-single-r1.eclass b/gx86/eclass/python-single-r1.eclass
214 > index fe26251..774f43e 100644
215 > --- a/gx86/eclass/python-single-r1.eclass
216 > +++ b/gx86/eclass/python-single-r1.eclass
217 > @@ -134,8 +134,31 @@ fi
218 > # @CODE
219 >
220 > _python_single_set_globals() {
221 > - local flags_mt=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
222 > - local flags=( "${PYTHON_COMPAT[@]/#/python_single_target_}" )
223 > + local impls=()
224 > +
225 > + PYTHON_DEPS=
226 > + local i PYTHON_PKG_DEP
227 > + for i in "${PYTHON_COMPAT[@]}"; do
228 > + _python_impl_supported "${i}" || continue
229 > +
230 > + # The chosen targets need to be in PYTHON_TARGETS as well.
231 > + # This is in order to enforce correct dependencies on packages
232 > + # supporting multiple implementations.
233 > + #REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
234 > +
235 > + python_export "${i}" PYTHON_PKG_DEP
236 > + PYTHON_DEPS+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
237 > +
238 > + impls+=( "${i}" )
239 > + done
240 > +
241 > + if [[ ${#impls[@]} -eq 0 ]]; then
242 > + die "No supported implementation in PYTHON_COMPAT."
243 > + fi
244 > +
245 > + local flags_mt=( "${impls[@]/#/python_targets_}" )
246 > + local flags=( "${impls[@]/#/python_single_target_}" )
247 > +
248 > local optflags=${flags_mt[@]/%/?}
249 > optflags+=,${flags[@]/%/(+)?}
250 >
251 > @@ -147,17 +170,7 @@ _python_single_set_globals() {
252 > # but no point in making this overcomplex, BDEP doesn't hurt anyone
253 > # 2) python-exec should be built with all targets forced anyway
254 > # but if new targets were added, we may need to force a rebuild
255 > - PYTHON_DEPS="dev-python/python-exec[${PYTHON_USEDEP}]"
256 > - local i PYTHON_PKG_DEP
257 > - for i in "${PYTHON_COMPAT[@]}"; do
258 > - # The chosen targets need to be in PYTHON_TARGETS as well.
259 > - # This is in order to enforce correct dependencies on packages
260 > - # supporting multiple implementations.
261 > - #REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
262 > -
263 > - python_export "${i}" PYTHON_PKG_DEP
264 > - PYTHON_DEPS+=" python_single_target_${i}? ( ${PYTHON_PKG_DEP} )"
265 > - done
266 > + PYTHON_DEPS+="dev-python/python-exec[${PYTHON_USEDEP}]"
267 > }
268 > _python_single_set_globals
269 >
270 > diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
271 > index ba270b5..ab72225 100644
272 > --- a/gx86/eclass/python-utils-r1.eclass
273 > +++ b/gx86/eclass/python-utils-r1.eclass
274 > @@ -47,6 +47,37 @@ _PYTHON_ALL_IMPLS=(
275 > python2_5 python2_6 python2_7
276 > )
277 >
278 > +# @FUNCTION: _python_impl_supported
279 > +# @USAGE: <impl>
280 > +# @INTERNAL
281 > +# @DESCRIPTION:
282 > +# Check whether the implementation <impl> (PYTHON_COMPAT-form)
283 > +# is still supported.
284 > +#
285 > +# Returns 0 if the implementation is valid and supported. If it is
286 > +# unsupported, returns 1 -- and the caller should ignore the entry.
287 > +# If it is invalid, dies with an appopriate error messages.
288 > +_python_impl_supported() {
289 > + debug-print-function ${FUNCNAME} "${@}"
290 > +
291 > + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)."
292 > +
293 > + local impl=${1}
294 > +
295 > + # keep in sync with _PYTHON_ALL_IMPLS!
296 > + # (not using that list because inline patterns shall be faster)
297 > + case "${impl}" in
298 > + python2_[567]|python3_[123]|pypy1_[89]|pypy2_0|jython2_5)
299 > + return 0
300 > + ;;
301 > +# pypy1_8)
302 > +# return 1
303 > +# ;;
304 > + *)
305 > + die "Invalid implementation in PYTHON_COMPAT: ${impl}"
306 > + esac
307 > +}
308 > +
309 > # @ECLASS-VARIABLE: PYTHON
310 > # @DESCRIPTION:
311 > # The absolute path to the current Python interpreter.
312
313 Overall, looks good. It looks like you did a pretty thorough audit of
314 the eclasses for the necessary change sites, so I won't repeat that
315 unless you want me to.

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies