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

Replies