/[gentoo-x86]/eclass/python-single-r1.eclass
Gentoo

Contents of /eclass/python-single-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.39 - (show annotations) (download)
Sat Jul 4 15:26:17 2015 UTC (3 years, 9 months ago) by floppym
Branch: MAIN
CVS Tags: HEAD
Changes since 1.38: +3 -3 lines
Replace links to python-r1 dev guide with links to the wiki.

1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.38 2015/03/22 13:41:16 mgorny Exp $
4
5 # @ECLASS: python-single-r1
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: An eclass for Python packages not installed for multiple implementations.
12 # @DESCRIPTION:
13 # An extension of the python-r1 eclass suite for packages which
14 # don't support being installed for multiple Python implementations.
15 # This mostly includes tools embedding Python.
16 #
17 # This eclass extends the IUSE and REQUIRED_USE set by python-r1
18 # to request the PYTHON_SINGLE_TARGET when the inheriting ebuild
19 # can be supported by more than one Python implementation. It also
20 # replaces PYTHON_USEDEP and PYTHON_DEPS with a more suitable form.
21 #
22 # Please note that packages support multiple Python implementations
23 # (using python-r1 eclass) can not depend on packages not supporting
24 # them (using this eclass).
25 #
26 # Please note that python-single-r1 will always inherit python-utils-r1
27 # as well. Thus, all the functions defined there can be used
28 # in the packages using python-single-r1, and there is no need ever
29 # to inherit both.
30 #
31 # For more information, please see the wiki:
32 # https://wiki.gentoo.org/wiki/Project:Python/python-single-r1
33
34 case "${EAPI:-0}" in
35 0|1|2|3)
36 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
37 ;;
38 4)
39 # EAPI=4 is only allowed on legacy packages
40 if [[ ${CATEGORY}/${P} == app-arch/threadzip-1.2 ]]; then
41 :
42 elif [[ ${CATEGORY}/${P} == media-libs/lv2-1.8.0 ]]; then
43 :
44 elif [[ ${CATEGORY}/${P} == media-libs/lv2-1.10.0 ]]; then
45 :
46 elif [[ ${CATEGORY}/${P} == sys-apps/paludis-1* ]]; then
47 :
48 elif [[ ${CATEGORY}/${P} == sys-apps/paludis-2.[02].0 ]]; then
49 :
50 elif [[ ${CATEGORY}/${P} == sys-apps/util-linux-2.2[456]* ]]; then
51 :
52 elif [[ ${CATEGORY}/${P} == */gdb-7.[78]* ]]; then
53 :
54 else
55 die "Unsupported EAPI=${EAPI:-4} (too old, allowed only on restricted set of packages) for ${ECLASS}"
56 fi
57 ;;
58 5)
59 # EAPI=5 is required for sane USE_EXPAND dependencies
60 ;;
61 *)
62 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
63 ;;
64 esac
65
66 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
67
68 if [[ ${_PYTHON_R1} ]]; then
69 die 'python-single-r1.eclass can not be used with python-r1.eclass.'
70 elif [[ ${_PYTHON_ANY_R1} ]]; then
71 die 'python-single-r1.eclass can not be used with python-any-r1.eclass.'
72 fi
73
74 inherit python-utils-r1
75
76 fi
77
78 EXPORT_FUNCTIONS pkg_setup
79
80 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
81
82 # @ECLASS-VARIABLE: PYTHON_COMPAT
83 # @REQUIRED
84 # @DESCRIPTION:
85 # This variable contains a list of Python implementations the package
86 # supports. It must be set before the `inherit' call. It has to be
87 # an array.
88 #
89 # Example:
90 # @CODE
91 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
92 # @CODE
93 if ! declare -p PYTHON_COMPAT &>/dev/null; then
94 die 'PYTHON_COMPAT not declared.'
95 fi
96
97 # @ECLASS-VARIABLE: PYTHON_REQ_USE
98 # @DEFAULT_UNSET
99 # @DESCRIPTION:
100 # The list of USEflags required to be enabled on the chosen Python
101 # implementations, formed as a USE-dependency string. It should be valid
102 # for all implementations in PYTHON_COMPAT, so it may be necessary to
103 # use USE defaults.
104 #
105 # This should be set before calling `inherit'.
106 #
107 # Example:
108 # @CODE
109 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
110 # @CODE
111 #
112 # It will cause the Python dependencies to look like:
113 # @CODE
114 # python_single_target_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
115 # @CODE
116
117 # @ECLASS-VARIABLE: PYTHON_DEPS
118 # @DESCRIPTION:
119 # This is an eclass-generated Python dependency string for all
120 # implementations listed in PYTHON_COMPAT.
121 #
122 # The dependency string is conditional on PYTHON_SINGLE_TARGET.
123 #
124 # Example use:
125 # @CODE
126 # RDEPEND="${PYTHON_DEPS}
127 # dev-foo/mydep"
128 # DEPEND="${RDEPEND}"
129 # @CODE
130 #
131 # Example value:
132 # @CODE
133 # dev-lang/python-exec:=
134 # python_single_target_python2_6? ( dev-lang/python:2.6[gdbm] )
135 # python_single_target_python2_7? ( dev-lang/python:2.7[gdbm] )
136 # @CODE
137
138 # @ECLASS-VARIABLE: PYTHON_USEDEP
139 # @DESCRIPTION:
140 # This is an eclass-generated USE-dependency string which can be used to
141 # depend on another Python package being built for the same Python
142 # implementations.
143 #
144 # The generate USE-flag list is compatible with packages using python-r1,
145 # python-single-r1 and python-distutils-ng eclasses. It must not be used
146 # on packages using python.eclass.
147 #
148 # Example use:
149 # @CODE
150 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
151 # @CODE
152 #
153 # Example value:
154 # @CODE
155 # python_targets_python2_7(-)?,python_single_target_python2_7(+)?
156 # @CODE
157
158 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
159 # @DESCRIPTION:
160 # This is an eclass-generated required-use expression which ensures the following
161 # when more than one python implementation is possible:
162 # 1. Exactly one PYTHON_SINGLE_TARGET value has been enabled.
163 # 2. The selected PYTHON_SINGLE_TARGET value is enabled in PYTHON_TARGETS.
164 #
165 # This expression should be utilized in an ebuild by including it in
166 # REQUIRED_USE, optionally behind a use flag.
167 #
168 # Example use:
169 # @CODE
170 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
171 # @CODE
172 #
173 # Example value:
174 # @CODE
175 # python_single_target_python2_6? ( python_targets_python2_6 )
176 # python_single_target_python2_7? ( python_targets_python2_7 )
177 # ^^ ( python_single_target_python2_6 python_single_target_python2_7 )
178 # @CODE
179
180 _python_single_set_globals() {
181 local impls=()
182 local unimpls=()
183
184 PYTHON_DEPS=
185 local i PYTHON_PKG_DEP
186 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
187 has "${i}" "${PYTHON_COMPAT[@]}" \
188 && impls+=( "${i}" ) \
189 || unimpls+=( "${i}" )
190 done
191
192 if [[ ${#impls[@]} -eq 0 ]]; then
193 die "No supported implementation in PYTHON_COMPAT."
194 fi
195
196 local flags_mt=( "${impls[@]/#/python_targets_}" )
197 local flags=( "${impls[@]/#/python_single_target_}" )
198 local unflags=( "${unimpls[@]/#/-python_single_target_}" )
199
200 local optflags=${flags_mt[@]/%/(-)?},${unflags[@]/%/(-)}
201
202 IUSE="${flags_mt[*]}"
203
204 if [[ ${#impls[@]} -eq 1 ]]; then
205 # There is only one supported implementation; set IUSE and other
206 # variables without PYTHON_SINGLE_TARGET.
207 PYTHON_REQUIRED_USE="${flags_mt[*]}"
208 python_export "${impls[0]}" PYTHON_PKG_DEP
209 PYTHON_DEPS="${PYTHON_PKG_DEP} "
210 # Force on the python_single_target_* flag for this impl, so
211 # that any dependencies that inherit python-single-r1 and
212 # happen to have multiple implementations will still need
213 # to bound by the implementation used by this package.
214 optflags+=,${flags[0]/%/(+)}
215 else
216 # Multiple supported implementations; honor PYTHON_SINGLE_TARGET.
217 IUSE+=" ${flags[*]}"
218 PYTHON_REQUIRED_USE="^^ ( ${flags[*]} )"
219 # Ensure deps honor the same python_single_target_* flag as is set
220 # on this package.
221 optflags+=,${flags[@]/%/(+)?}
222
223 for i in "${impls[@]}"; do
224 # The chosen targets need to be in PYTHON_TARGETS as well.
225 # This is in order to enforce correct dependencies on packages
226 # supporting multiple implementations.
227 PYTHON_REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
228
229 python_export "${i}" PYTHON_PKG_DEP
230 PYTHON_DEPS+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
231 done
232 fi
233 PYTHON_USEDEP=${optflags// /,}
234
235 # 1) well, python-exec would suffice as an RDEP
236 # but no point in making this overcomplex, BDEP doesn't hurt anyone
237 # 2) python-exec should be built with all targets forced anyway
238 # but if new targets were added, we may need to force a rebuild
239 # 3) use whichever python-exec slot installed in EAPI 5. For EAPI 4,
240 # just fix :2 since := deps are not supported.
241 if [[ ${_PYTHON_WANT_PYTHON_EXEC2} == 0 ]]; then
242 die "python-exec:0 is no longer supported, please fix your ebuild to work with python-exec:2"
243 elif [[ ${EAPI} != 4 ]]; then
244 PYTHON_DEPS+=">=dev-lang/python-exec-2:=[${PYTHON_USEDEP}]"
245 else
246 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
247 fi
248 }
249 _python_single_set_globals
250
251 # @FUNCTION: python_gen_usedep
252 # @USAGE: <pattern> [...]
253 # @DESCRIPTION:
254 # Output a USE dependency string for Python implementations which
255 # are both in PYTHON_COMPAT and match any of the patterns passed
256 # as parameters to the function.
257 #
258 # Remember to escape or quote the patterns to prevent shell filename
259 # expansion.
260 #
261 # When all implementations are requested, please use ${PYTHON_USEDEP}
262 # instead. Please also remember to set an appropriate REQUIRED_USE
263 # to avoid ineffective USE flags.
264 #
265 # Example:
266 # @CODE
267 # PYTHON_COMPAT=( python{2_7,3_4} )
268 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
269 # @CODE
270 #
271 # It will cause the dependency to look like:
272 # @CODE
273 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7(-)?,...] )"
274 # @CODE
275 python_gen_usedep() {
276 debug-print-function ${FUNCNAME} "${@}"
277
278 local impl pattern
279 local matches=()
280
281 for impl in "${PYTHON_COMPAT[@]}"; do
282 _python_impl_supported "${impl}" || continue
283
284 for pattern; do
285 if [[ ${impl} == ${pattern} ]]; then
286 matches+=(
287 "python_targets_${impl}(-)?"
288 "python_single_target_${impl}(+)?"
289 )
290 break
291 fi
292 done
293 done
294
295 [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
296
297 local out=${matches[@]}
298 echo "${out// /,}"
299 }
300
301 # @FUNCTION: python_gen_useflags
302 # @USAGE: <pattern> [...]
303 # @DESCRIPTION:
304 # Output a list of USE flags for Python implementations which
305 # are both in PYTHON_COMPAT and match any of the patterns passed
306 # as parameters to the function.
307 #
308 # Example:
309 # @CODE
310 # PYTHON_COMPAT=( python{2_7,3_4} )
311 # REQUIRED_USE="doc? ( ^^ ( $(python_gen_useflags 'python2*') ) )"
312 # @CODE
313 #
314 # It will cause the variable to look like:
315 # @CODE
316 # REQUIRED_USE="doc? ( ^^ ( python_single_target_python2_7 ) )"
317 # @CODE
318 python_gen_useflags() {
319 debug-print-function ${FUNCNAME} "${@}"
320
321 local impl pattern
322 local matches=()
323
324 for impl in "${PYTHON_COMPAT[@]}"; do
325 _python_impl_supported "${impl}" || continue
326
327 for pattern; do
328 if [[ ${impl} == ${pattern} ]]; then
329 matches+=( "python_single_target_${impl}" )
330 break
331 fi
332 done
333 done
334
335 echo "${matches[@]}"
336 }
337
338 # @FUNCTION: python_gen_cond_dep
339 # @USAGE: <dependency> <pattern> [...]
340 # @DESCRIPTION:
341 # Output a list of <dependency>-ies made conditional to USE flags
342 # of Python implementations which are both in PYTHON_COMPAT and match
343 # any of the patterns passed as the remaining parameters.
344 #
345 # In order to enforce USE constraints on the packages, verbatim
346 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
347 # specification. It will get expanded within the function into a proper
348 # USE dependency string.
349 #
350 # Example:
351 # @CODE
352 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
353 # RDEPEND="$(python_gen_cond_dep \
354 # 'dev-python/unittest2[${PYTHON_USEDEP}]' python{2_5,2_6})"
355 # @CODE
356 #
357 # It will cause the variable to look like:
358 # @CODE
359 # RDEPEND="python_single_target_python2_5? (
360 # dev-python/unittest2[python_targets_python2_5(-)?,...] )
361 # python_single_target_python2_6? (
362 # dev-python/unittest2[python_targets_python2_6(-)?,...] )"
363 # @CODE
364 python_gen_cond_dep() {
365 debug-print-function ${FUNCNAME} "${@}"
366
367 local impl pattern
368 local matches=()
369
370 local dep=${1}
371 shift
372
373 for impl in "${PYTHON_COMPAT[@]}"; do
374 _python_impl_supported "${impl}" || continue
375
376 for pattern; do
377 if [[ ${impl} == ${pattern} ]]; then
378 # substitute ${PYTHON_USEDEP} if used
379 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
380 # the code is run at most once)
381 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
382 local PYTHON_USEDEP=$(python_gen_usedep "${@}")
383 dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
384 fi
385
386 matches+=( "python_single_target_${impl}? ( ${dep} )" )
387 break
388 fi
389 done
390 done
391
392 echo "${matches[@]}"
393 }
394
395 # @FUNCTION: python_setup
396 # @DESCRIPTION:
397 # Determine what the selected Python implementation is and set
398 # the Python build environment up for it.
399 python_setup() {
400 debug-print-function ${FUNCNAME} "${@}"
401
402 unset EPYTHON
403
404 local impl impls=()
405 for impl in "${PYTHON_COMPAT[@]}"; do
406 _python_impl_supported "${impl}" || continue
407 impls+=( "${impl}" )
408 done
409
410 if [[ ${#impls[@]} -eq 1 ]]; then
411 if use "python_targets_${impls[0]}"; then
412 # Only one supported implementation, enable it explicitly
413 python_export "${impls[0]}" EPYTHON PYTHON
414 python_wrapper_setup
415 fi
416 else
417 for impl in "${impls[@]}"; do
418 if use "python_single_target_${impl}"; then
419 if [[ ${EPYTHON} ]]; then
420 eerror "Your PYTHON_SINGLE_TARGET setting lists more than a single Python"
421 eerror "implementation. Please set it to just one value. If you need"
422 eerror "to override the value for a single package, please use package.env"
423 eerror "or an equivalent solution (man 5 portage)."
424 echo
425 die "More than one implementation in PYTHON_SINGLE_TARGET."
426 fi
427
428 if ! use "python_targets_${impl}"; then
429 eerror "The implementation chosen as PYTHON_SINGLE_TARGET must be added"
430 eerror "to PYTHON_TARGETS as well. This is in order to ensure that"
431 eerror "dependencies are satisfied correctly. We're sorry"
432 eerror "for the inconvenience."
433 echo
434 die "Build target (${impl}) not in PYTHON_TARGETS."
435 fi
436
437 python_export "${impl}" EPYTHON PYTHON
438 python_wrapper_setup
439 fi
440 done
441 fi
442
443 if [[ ! ${EPYTHON} ]]; then
444 eerror "No Python implementation selected for the build. Please set"
445 if [[ ${#impls[@]} -eq 1 ]]; then
446 eerror "the PYTHON_TARGETS variable in your make.conf to include one"
447 else
448 eerror "the PYTHON_SINGLE_TARGET variable in your make.conf to one"
449 fi
450 eerror "of the following values:"
451 eerror
452 eerror "${impls[@]}"
453 echo
454 die "No supported Python implementation in PYTHON_SINGLE_TARGET/PYTHON_TARGETS."
455 fi
456 }
457
458 # @FUNCTION: python-single-r1_pkg_setup
459 # @DESCRIPTION:
460 # Runs python_setup.
461 python-single-r1_pkg_setup() {
462 debug-print-function ${FUNCNAME} "${@}"
463
464 [[ ${MERGE_TYPE} != binary ]] && python_setup
465 }
466
467 _PYTHON_SINGLE_R1=1
468 fi

  ViewVC Help
Powered by ViewVC 1.1.20