python-single-r1.eclass: Introduce PYTHON_{SINGLE,MULTI}_USEDEP API
[gentoo.git] / eclass / python-single-r1.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: python-single-r1.eclass
5 # @MAINTAINER:
6 # Python team <python@gentoo.org>
7 # @AUTHOR:
8 # Author: Michał Górny <mgorny@gentoo.org>
9 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
10 # @SUPPORTED_EAPIS: 5 6 7
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 and packages using foreign
16 # build systems.
17 #
18 # This eclass sets correct IUSE.  It also provides PYTHON_DEPS
19 # and PYTHON_REQUIRED_USE that need to be added to appropriate ebuild
20 # metadata variables.
21 #
22 # The eclass exports PYTHON_SINGLE_USEDEP that is suitable for depending
23 # on other packages using the eclass.  Dependencies on packages using
24 # python-r1 should be created via python_gen_cond_dep() function,
25 # using PYTHON_MULTI_USEDEP placeholder.
26 #
27 # Please note that packages support multiple Python implementations
28 # (using python-r1 eclass) can not depend on packages not supporting
29 # them (using this eclass).
30 #
31 # Please note that python-single-r1 will always inherit python-utils-r1
32 # as well. Thus, all the functions defined there can be used
33 # in the packages using python-single-r1, and there is no need ever
34 # to inherit both.
35 #
36 # For more information, please see the wiki:
37 # https://wiki.gentoo.org/wiki/Project:Python/python-single-r1
38
39 case "${EAPI:-0}" in
40         0|1|2|3|4)
41                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
42                 ;;
43         5|6|7)
44                 # EAPI=5 is required for sane USE_EXPAND dependencies
45                 ;;
46         *)
47                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
48                 ;;
49 esac
50
51 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
52
53 if [[ ${_PYTHON_R1} ]]; then
54         die 'python-single-r1.eclass can not be used with python-r1.eclass.'
55 elif [[ ${_PYTHON_ANY_R1} ]]; then
56         die 'python-single-r1.eclass can not be used with python-any-r1.eclass.'
57 fi
58
59 inherit python-utils-r1
60
61 fi
62
63 EXPORT_FUNCTIONS pkg_setup
64
65 # @ECLASS-VARIABLE: PYTHON_COMPAT
66 # @REQUIRED
67 # @DESCRIPTION:
68 # This variable contains a list of Python implementations the package
69 # supports. It must be set before the `inherit' call. It has to be
70 # an array.
71 #
72 # Example:
73 # @CODE
74 # PYTHON_COMPAT=( python2_7 python3_3 python3_4 )
75 # @CODE
76 #
77 # Please note that you can also use bash brace expansion if you like:
78 # @CODE
79 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
80 # @CODE
81
82 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
83 # @INTERNAL
84 # @DESCRIPTION:
85 # This variable can be used when working with ebuilds to override
86 # the in-ebuild PYTHON_COMPAT. It is a string naming the implementation
87 # which package will be built for. It needs to be specified
88 # in the calling environment, and not in ebuilds.
89 #
90 # It should be noted that in order to preserve metadata immutability,
91 # PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
92 # The state of PYTHON_TARGETS and PYTHON_SINGLE_TARGET is ignored,
93 # and the implementation in PYTHON_COMPAT_OVERRIDE is built instead.
94 # Dependencies need to be satisfied manually.
95 #
96 # Example:
97 # @CODE
98 # PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar
99 # @CODE
100
101 # @ECLASS-VARIABLE: PYTHON_REQ_USE
102 # @DEFAULT_UNSET
103 # @DESCRIPTION:
104 # The list of USEflags required to be enabled on the chosen Python
105 # implementations, formed as a USE-dependency string. It should be valid
106 # for all implementations in PYTHON_COMPAT, so it may be necessary to
107 # use USE defaults.
108 #
109 # This should be set before calling `inherit'.
110 #
111 # Example:
112 # @CODE
113 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
114 # @CODE
115 #
116 # It will cause the Python dependencies to look like:
117 # @CODE
118 # python_single_target_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
119 # @CODE
120
121 # @ECLASS-VARIABLE: PYTHON_DEPS
122 # @DESCRIPTION:
123 # This is an eclass-generated Python dependency string for all
124 # implementations listed in PYTHON_COMPAT.
125 #
126 # The dependency string is conditional on PYTHON_SINGLE_TARGET.
127 #
128 # Example use:
129 # @CODE
130 # RDEPEND="${PYTHON_DEPS}
131 #       dev-foo/mydep"
132 # DEPEND="${RDEPEND}"
133 # @CODE
134 #
135 # Example value:
136 # @CODE
137 # dev-lang/python-exec:=
138 # python_single_target_python2_7? ( dev-lang/python:2.7[gdbm] )
139 # python_single_target_pypy? ( virtual/pypy[gdbm] )
140 # @CODE
141
142 # @ECLASS-VARIABLE: PYTHON_USEDEP
143 # @DESCRIPTION:
144 # DEPRECATED.  Use PYTHON_SINGLE_USEDEP or python_gen_cond_dep with
145 # PYTHON_MULTI_USEDEP placeholder instead.
146 #
147 # This is an eclass-generated USE-dependency string which can be used to
148 # depend on another Python package being built for the same Python
149 # implementations.
150 #
151 # The generate USE-flag list is compatible with packages using python-r1,
152 # python-single-r1 and python-distutils-ng eclasses. It must not be used
153 # on packages using python.eclass.
154 #
155 # Example use:
156 # @CODE
157 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
158 # @CODE
159 #
160 # Example value:
161 # @CODE
162 # python_targets_python2_7(-)?,python_single_target_python3_4(+)?
163 # @CODE
164
165 # @ECLASS-VARIABLE: PYTHON_SINGLE_USEDEP
166 # @DESCRIPTION:
167 # This is an eclass-generated USE-dependency string which can be used to
168 # depend on another python-single-r1 package being built for the same
169 # Python implementations.
170 #
171 # If you need to depend on a multi-impl (python-r1) package, use
172 # python_gen_cond_dep with PYTHON_MULTI_USEDEP placeholder instead.
173 #
174 # Example use:
175 # @CODE
176 # RDEPEND="dev-python/foo[${PYTHON_SINGLE_USEDEP}]"
177 # @CODE
178 #
179 # Example value:
180 # @CODE
181 # python_single_target_python3_4(-)?
182 # @CODE
183
184 # @ECLASS-VARIABLE: PYTHON_MULTI_USEDEP
185 # @DESCRIPTION:
186 # This is a placeholder variable supported by python_gen_cond_dep,
187 # in order to depend on python-r1 packages built for the same Python
188 # implementations.
189 #
190 # Example use:
191 # @CODE
192 # RDEPEND="$(python_gen_cond_dep '
193 #     dev-python/foo[${PYTHON_MULTI_USEDEP}]
194 #   ')"
195 # @CODE
196 #
197 # Example value:
198 # @CODE
199 # python_targets_python3_4(-)
200 # @CODE
201
202 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
203 # @DESCRIPTION:
204 # This is an eclass-generated required-use expression which ensures the following
205 # when more than one python implementation is possible:
206 # 1. Exactly one PYTHON_SINGLE_TARGET value has been enabled.
207 # 2. The selected PYTHON_SINGLE_TARGET value is enabled in PYTHON_TARGETS.
208 #
209 # This expression should be utilized in an ebuild by including it in
210 # REQUIRED_USE, optionally behind a use flag.
211 #
212 # Example use:
213 # @CODE
214 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
215 # @CODE
216 #
217 # Example value:
218 # @CODE
219 # python_single_target_python2_7? ( python_targets_python2_7 )
220 # python_single_target_python3_3? ( python_targets_python3_3 )
221 # ^^ ( python_single_target_python2_7 python_single_target_python3_3 )
222 # @CODE
223
224 _python_single_set_globals() {
225         _python_set_impls
226
227         local flags_mt=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
228         local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_single_target_}" )
229         local unflags=( "${_PYTHON_UNSUPPORTED_IMPLS[@]/#/-python_single_target_}" )
230
231         if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
232                 # if only one implementation is supported, use IUSE defaults
233                 # to avoid requesting the user to enable it
234                 IUSE="+${flags_mt[0]} +${flags[0]}"
235         else
236                 IUSE="${flags_mt[*]} ${flags[*]}"
237         fi
238
239         local requse="^^ ( ${flags[*]} )"
240         local optflags="${flags_mt[@]/%/(-)?},${unflags[@]/%/(-)},${flags[@]/%/(+)?}"
241         local usedep="${optflags// /,}"
242         local single_flags="${flags[@]/%/(-)?}"
243         local single_usedep=${single_flags// /,}
244
245         local deps= i PYTHON_PKG_DEP
246         for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
247                 # The chosen targets need to be in PYTHON_TARGETS as well.
248                 # This is in order to enforce correct dependencies on packages
249                 # supporting multiple implementations.
250                 requse+=" python_single_target_${i}? ( python_targets_${i} )"
251
252                 python_export "${i}" PYTHON_PKG_DEP
253                 deps+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
254         done
255
256         # 1) well, python-exec would suffice as an RDEP
257         # but no point in making this overcomplex, BDEP doesn't hurt anyone
258         # 2) python-exec should be built with all targets forced anyway
259         # but if new targets were added, we may need to force a rebuild
260         deps+=">=dev-lang/python-exec-2:=[${usedep}]"
261
262         if [[ ${PYTHON_DEPS+1} ]]; then
263                 if [[ ${PYTHON_DEPS} != "${deps}" ]]; then
264                         eerror "PYTHON_DEPS have changed between inherits (PYTHON_REQ_USE?)!"
265                         eerror "Before: ${PYTHON_DEPS}"
266                         eerror "Now   : ${deps}"
267                         die "PYTHON_DEPS integrity check failed"
268                 fi
269
270                 # these two are formality -- they depend on PYTHON_COMPAT only
271                 if [[ ${PYTHON_REQUIRED_USE} != ${requse} ]]; then
272                         eerror "PYTHON_REQUIRED_USE have changed between inherits!"
273                         eerror "Before: ${PYTHON_REQUIRED_USE}"
274                         eerror "Now   : ${requse}"
275                         die "PYTHON_REQUIRED_USE integrity check failed"
276                 fi
277
278                 if [[ ${PYTHON_USEDEP} != "${usedep}" ]]; then
279                         eerror "PYTHON_USEDEP have changed between inherits!"
280                         eerror "Before: ${PYTHON_USEDEP}"
281                         eerror "Now   : ${usedep}"
282                         die "PYTHON_USEDEP integrity check failed"
283                 fi
284
285                 if [[ ${PYTHON_SINGLE_USEDEP} != "${single_usedep}" ]]; then
286                         eerror "PYTHON_SINGLE_USEDEP have changed between inherits!"
287                         eerror "Before: ${PYTHON_SINGLE_USEDEP}"
288                         eerror "Now   : ${single_usedep}"
289                         die "PYTHON_SINGLE_USEDEP integrity check failed"
290                 fi
291         else
292                 PYTHON_DEPS=${deps}
293                 PYTHON_REQUIRED_USE=${requse}
294                 PYTHON_USEDEP=${usedep}
295                 PYTHON_SINGLE_USEDEP=${single_usedep}
296                 readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP \
297                         PYTHON_SINGLE_USEDEP
298         fi
299 }
300 _python_single_set_globals
301 unset -f _python_single_set_globals
302
303 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
304
305 # @FUNCTION: _python_gen_usedep
306 # @INTERNAL
307 # @USAGE: <-s|-u> [<pattern>...]
308 # @DESCRIPTION:
309 # Output a USE dependency string for Python implementations which
310 # are both in PYTHON_COMPAT and match any of the patterns passed
311 # as parameters to the function.
312 #
313 # The first argument specifies USE-dependency type: '-s' for new-style
314 # PYTHON_SINGLE_USEDEP, '-u' for backwards-compatible PYTHON_USEDEP.
315 #
316 # The patterns can be either fnmatch-style patterns (matched via bash
317 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
318 # appropriately all enabled Python 2/3 implementations (alike
319 # python_is_python3). Remember to escape or quote the fnmatch patterns
320 # to prevent accidental shell filename expansion.
321 #
322 # This is an internal function used to implement python_gen_cond_dep
323 # and deprecated python_gen_usedep.
324 _python_gen_usedep() {
325         debug-print-function ${FUNCNAME} "${@}"
326
327         local mode=${1}
328         shift
329         local impl matches=()
330
331         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
332                 if _python_impl_matches "${impl}" "${@}"; then
333                         case ${mode} in
334                                 -s)
335                                         matches+=(
336                                                 "python_single_target_${impl}(-)?"
337                                         )
338                                         ;;
339                                 -u)
340                                         matches+=(
341                                                 "python_targets_${impl}(-)?"
342                                                 "python_single_target_${impl}(+)?"
343                                         )
344                                 ;;
345                         esac
346                 fi
347         done
348
349         [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
350
351         local out=${matches[@]}
352         echo "${out// /,}"
353 }
354
355 # @FUNCTION: python_gen_usedep
356 # @USAGE: <pattern> [...]
357 # @DESCRIPTION:
358 # DEPRECATED.  Please use python_gen_cond_dep instead.
359 #
360 # Output a USE dependency string for Python implementations which
361 # are both in PYTHON_COMPAT and match any of the patterns passed
362 # as parameters to the function.
363 #
364 # The patterns can be either fnmatch-style patterns (matched via bash
365 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
366 # appropriately all enabled Python 2/3 implementations (alike
367 # python_is_python3). Remember to escape or quote the fnmatch patterns
368 # to prevent accidental shell filename expansion.
369 #
370 # When all implementations are requested, please use ${PYTHON_USEDEP}
371 # instead. Please also remember to set an appropriate REQUIRED_USE
372 # to avoid ineffective USE flags.
373 #
374 # Example:
375 # @CODE
376 # PYTHON_COMPAT=( python{2_7,3_4} )
377 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
378 # @CODE
379 #
380 # It will cause the dependency to look like:
381 # @CODE
382 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7(-)?,...] )"
383 # @CODE
384 python_gen_usedep() {
385         debug-print-function ${FUNCNAME} "${@}"
386
387         # output only once, during some reasonable phase
388         # (avoid spamming cache regen runs)
389         if [[ ${EBUILD_PHASE} == setup ]]; then
390                 eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead."
391         fi
392         _python_gen_usedep -u "${@}"
393 }
394
395 # @FUNCTION: python_gen_useflags
396 # @USAGE: [<pattern>...]
397 # @DESCRIPTION:
398 # Output a list of USE flags for Python implementations which
399 # are both in PYTHON_COMPAT and match any of the patterns passed
400 # as parameters to the function.
401 #
402 # The patterns can be either fnmatch-style patterns (matched via bash
403 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
404 # appropriately all enabled Python 2/3 implementations (alike
405 # python_is_python3). Remember to escape or quote the fnmatch patterns
406 # to prevent accidental shell filename expansion.
407 #
408 # Example:
409 # @CODE
410 # PYTHON_COMPAT=( python{2_7,3_4} )
411 # REQUIRED_USE="doc? ( ^^ ( $(python_gen_useflags 'python2*') ) )"
412 # @CODE
413 #
414 # It will cause the variable to look like:
415 # @CODE
416 # REQUIRED_USE="doc? ( ^^ ( python_single_target_python2_7 ) )"
417 # @CODE
418 python_gen_useflags() {
419         debug-print-function ${FUNCNAME} "${@}"
420
421         local impl matches=()
422
423         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
424                 if _python_impl_matches "${impl}" "${@}"; then
425                         matches+=( "python_single_target_${impl}" )
426                 fi
427         done
428
429         echo "${matches[@]}"
430 }
431
432 # @FUNCTION: python_gen_cond_dep
433 # @USAGE: <dependency> [<pattern>...]
434 # @DESCRIPTION:
435 # Output a list of <dependency>-ies made conditional to USE flags
436 # of Python implementations which are both in PYTHON_COMPAT and match
437 # any of the patterns passed as the remaining parameters.
438 #
439 # The patterns can be either fnmatch-style patterns (matched via bash
440 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
441 # appropriately all enabled Python 2/3 implementations (alike
442 # python_is_python3). Remember to escape or quote the fnmatch patterns
443 # to prevent accidental shell filename expansion.
444 #
445 # In order to enforce USE constraints on the packages, verbatim
446 # '${PYTHON_USEDEP}', '${PYTHON_SINGLE_USEDEP}'
447 # and '${PYTHON_MULTI_USEDEP}' (quoted!) may be placed in the dependency
448 # specification. It will get expanded within the function into a proper
449 # USE dependency string.
450 #
451 # Example:
452 # @CODE
453 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
454 # RDEPEND="$(python_gen_cond_dep \
455 #   'dev-python/unittest2[${PYTHON_MULTI_USEDEP}]' python2_7 pypy )"
456 # @CODE
457 #
458 # It will cause the variable to look like:
459 # @CODE
460 # RDEPEND="python_single_target_python2_7? (
461 #     dev-python/unittest2[python_targets_python2_7(-)?,...] )
462 #       python_single_target_pypy? (
463 #     dev-python/unittest2[python_targets_pypy(-)?,...] )"
464 # @CODE
465 python_gen_cond_dep() {
466         debug-print-function ${FUNCNAME} "${@}"
467
468         local impl matches=()
469
470         local dep=${1}
471         shift
472
473         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
474                 if _python_impl_matches "${impl}" "${@}"; then
475                         # substitute ${PYTHON_USEDEP} if used
476                         # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
477                         #  the code is run at most once)
478                         if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
479                                 local usedep=$(_python_gen_usedep -u "${@}")
480                                 dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
481                         fi
482                         if [[ ${dep} == *'${PYTHON_SINGLE_USEDEP}'* ]]; then
483                                 local usedep=$(_python_gen_usedep -s "${@}")
484                                 dep=${dep//\$\{PYTHON_SINGLE_USEDEP\}/${usedep}}
485                         fi
486                         local multi_usedep="python_targets_${impl}(-)"
487
488                         matches+=( "python_single_target_${impl}? (
489                                 ${dep//\$\{PYTHON_MULTI_USEDEP\}/${multi_usedep}} )" )
490                 fi
491         done
492
493         echo "${matches[@]}"
494 }
495
496 # @FUNCTION: python_gen_impl_dep
497 # @USAGE: [<requested-use-flags> [<impl-pattern>...]]
498 # @DESCRIPTION:
499 # Output a dependency on Python implementations with the specified USE
500 # dependency string appended, or no USE dependency string if called
501 # without the argument (or with empty argument). If any implementation
502 # patterns are passed, the output dependencies will be generated only
503 # for the implementations matching them.
504 #
505 # The patterns can be either fnmatch-style patterns (matched via bash
506 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
507 # appropriately all enabled Python 2/3 implementations (alike
508 # python_is_python3). Remember to escape or quote the fnmatch patterns
509 # to prevent accidental shell filename expansion.
510 #
511 # Use this function when you need to request different USE flags
512 # on the Python interpreter depending on package's USE flags. If you
513 # only need a single set of interpreter USE flags, just set
514 # PYTHON_REQ_USE and use ${PYTHON_DEPS} globally.
515 #
516 # Example:
517 # @CODE
518 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
519 # RDEPEND="foo? ( $(python_gen_impl_dep 'xml(+)') )"
520 # @CODE
521 #
522 # It will cause the variable to look like:
523 # @CODE
524 # RDEPEND="foo? (
525 #   python_single_target_python2_7? (
526 #     dev-lang/python:2.7[xml(+)] )
527 #       python_single_target_pypy? (
528 #     dev-python/pypy[xml(+)] ) )"
529 # @CODE
530 python_gen_impl_dep() {
531         debug-print-function ${FUNCNAME} "${@}"
532
533         local impl
534         local matches=()
535
536         local PYTHON_REQ_USE=${1}
537         shift
538
539         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
540                 if _python_impl_matches "${impl}" "${@}"; then
541                         local PYTHON_PKG_DEP
542                         python_export "${impl}" PYTHON_PKG_DEP
543                         matches+=( "python_single_target_${impl}? ( ${PYTHON_PKG_DEP} )" )
544                 fi
545         done
546
547         echo "${matches[@]}"
548 }
549
550 # @FUNCTION: python_setup
551 # @DESCRIPTION:
552 # Determine what the selected Python implementation is and set
553 # the Python build environment up for it.
554 python_setup() {
555         debug-print-function ${FUNCNAME} "${@}"
556
557         unset EPYTHON
558
559         # support developer override
560         if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
561                 local impls=( ${PYTHON_COMPAT_OVERRIDE} )
562                 [[ ${#impls[@]} -eq 1 ]] || die "PYTHON_COMPAT_OVERRIDE must name exactly one implementation for python-single-r1"
563
564                 ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
565                 ewarn "implementation will be used:"
566                 ewarn
567                 ewarn " ${PYTHON_COMPAT_OVERRIDE}"
568                 ewarn
569                 ewarn "Dependencies won't be satisfied, and PYTHON_SINGLE_TARGET flags will be ignored."
570
571                 python_export "${impls[0]}" EPYTHON PYTHON
572                 python_wrapper_setup
573                 return
574         fi
575
576         local impl
577         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
578                 if use "python_single_target_${impl}"; then
579                         if [[ ${EPYTHON} ]]; then
580                                 eerror "Your PYTHON_SINGLE_TARGET setting lists more than a single Python"
581                                 eerror "implementation. Please set it to just one value. If you need"
582                                 eerror "to override the value for a single package, please use package.env"
583                                 eerror "or an equivalent solution (man 5 portage)."
584                                 echo
585                                 die "More than one implementation in PYTHON_SINGLE_TARGET."
586                         fi
587
588                         if ! use "python_targets_${impl}"; then
589                                 eerror "The implementation chosen as PYTHON_SINGLE_TARGET must be added"
590                                 eerror "to PYTHON_TARGETS as well. This is in order to ensure that"
591                                 eerror "dependencies are satisfied correctly. We're sorry"
592                                 eerror "for the inconvenience."
593                                 echo
594                                 die "Build target (${impl}) not in PYTHON_TARGETS."
595                         fi
596
597                         python_export "${impl}" EPYTHON PYTHON
598                         python_wrapper_setup
599                 fi
600         done
601
602         if [[ ! ${EPYTHON} ]]; then
603                 eerror "No Python implementation selected for the build. Please set"
604                 eerror "the PYTHON_SINGLE_TARGET variable in your make.conf to one"
605                 eerror "of the following values:"
606                 eerror
607                 eerror "${_PYTHON_SUPPORTED_IMPLS[@]}"
608                 echo
609                 die "No supported Python implementation in PYTHON_SINGLE_TARGET/PYTHON_TARGETS."
610         fi
611 }
612
613 # @FUNCTION: python-single-r1_pkg_setup
614 # @DESCRIPTION:
615 # Runs python_setup.
616 python-single-r1_pkg_setup() {
617         debug-print-function ${FUNCNAME} "${@}"
618
619         [[ ${MERGE_TYPE} != binary ]] && python_setup
620 }
621
622 _PYTHON_SINGLE_R1=1
623 fi