Gentoo Archives: gentoo-python

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

Attachments

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