EAPI=6 support; removed support befor media-video/vdr-2
[gentoo.git] / eclass / python-r1.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: python-r1.eclass
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: A common, simple eclass for Python packages.
12 # @DESCRIPTION:
13 # A common eclass providing helper functions to build and install
14 # packages supporting being installed for multiple Python
15 # implementations.
16 #
17 # This eclass sets correct IUSE. Modification of REQUIRED_USE has to
18 # be done by the author of the ebuild (but PYTHON_REQUIRED_USE is
19 # provided for convenience, see below). python-r1 exports PYTHON_DEPS
20 # and PYTHON_USEDEP so you can create correct dependencies for your
21 # package easily. It also provides methods to easily run a command for
22 # each enabled Python implementation and duplicate the sources for them.
23 #
24 # Please note that python-r1 will always inherit python-utils-r1 as
25 # well. Thus, all the functions defined there can be used
26 # in the packages using python-r1, and there is no need ever to inherit
27 # both.
28 #
29 # For more information, please see the wiki:
30 # https://wiki.gentoo.org/wiki/Project:Python/python-r1
31
32 case "${EAPI:-0}" in
33         0|1|2|3)
34                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
35                 ;;
36         4)
37                 # EAPI=4 is only allowed on legacy packages
38                 if [[ ${CATEGORY}/${P} == dev-python/pyelftools-0.2[123] ]]; then
39                         :
40                 elif [[ ${CATEGORY}/${P} == sys-apps/file-5.22 ]]; then
41                         :
42                 elif [[ ${CATEGORY}/${P} == sys-apps/i2c-tools-3.1.1 ]]; then
43                         :
44                 elif [[ ${CATEGORY}/${P} == sys-libs/cracklib-2.9.[12] ]]; then
45                         :
46                 else
47                         die "Unsupported EAPI=${EAPI:-4} (too old, allowed only on restricted set of packages) for ${ECLASS}"
48                 fi
49                 ;;
50         5|6)
51                 # EAPI=5 is required for sane USE_EXPAND dependencies
52                 ;;
53         *)
54                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
55                 ;;
56 esac
57
58 if [[ ! ${_PYTHON_R1} ]]; then
59
60 if [[ ${_PYTHON_SINGLE_R1} ]]; then
61         die 'python-r1.eclass can not be used with python-single-r1.eclass.'
62 elif [[ ${_PYTHON_ANY_R1} ]]; then
63         die 'python-r1.eclass can not be used with python-any-r1.eclass.'
64 fi
65
66 [[ ${EAPI} == [45] ]] && inherit eutils
67 inherit multibuild python-utils-r1
68
69 # @ECLASS-VARIABLE: PYTHON_COMPAT
70 # @REQUIRED
71 # @DESCRIPTION:
72 # This variable contains a list of Python implementations the package
73 # supports. It must be set before the `inherit' call. It has to be
74 # an array.
75 #
76 # Example:
77 # @CODE
78 # PYTHON_COMPAT=( python2_7 python3_3 python3_4} )
79 # @CODE
80 #
81 # Please note that you can also use bash brace expansion if you like:
82 # @CODE
83 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
84 # @CODE
85
86 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
87 # @INTERNAL
88 # @DESCRIPTION:
89 # This variable can be used when working with ebuilds to override
90 # the in-ebuild PYTHON_COMPAT. It is a string listing all
91 # the implementations which package will be built for. It need be
92 # specified in the calling environment, and not in ebuilds.
93 #
94 # It should be noted that in order to preserve metadata immutability,
95 # PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
96 # The state of PYTHON_TARGETS is ignored, and all the implementations
97 # in PYTHON_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
98 # manually.
99 #
100 # Example:
101 # @CODE
102 # PYTHON_COMPAT_OVERRIDE='pypy python3_3' emerge -1v dev-python/foo
103 # @CODE
104
105 # @ECLASS-VARIABLE: PYTHON_REQ_USE
106 # @DEFAULT_UNSET
107 # @DESCRIPTION:
108 # The list of USEflags required to be enabled on the chosen Python
109 # implementations, formed as a USE-dependency string. It should be valid
110 # for all implementations in PYTHON_COMPAT, so it may be necessary to
111 # use USE defaults.
112 #
113 # This should be set before calling `inherit'.
114 #
115 # Example:
116 # @CODE
117 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
118 # @CODE
119 #
120 # It will cause the Python dependencies to look like:
121 # @CODE
122 # python_targets_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
123 # @CODE
124
125 # @ECLASS-VARIABLE: PYTHON_DEPS
126 # @DESCRIPTION:
127 # This is an eclass-generated Python dependency string for all
128 # implementations listed in PYTHON_COMPAT.
129 #
130 # Example use:
131 # @CODE
132 # RDEPEND="${PYTHON_DEPS}
133 #       dev-foo/mydep"
134 # DEPEND="${RDEPEND}"
135 # @CODE
136 #
137 # Example value:
138 # @CODE
139 # dev-lang/python-exec:=
140 # python_targets_python2_7? ( dev-lang/python:2.7[gdbm] )
141 # python_targets_pypy? ( virtual/pypy[gdbm] )
142 # @CODE
143
144 # @ECLASS-VARIABLE: PYTHON_USEDEP
145 # @DESCRIPTION:
146 # This is an eclass-generated USE-dependency string which can be used to
147 # depend on another Python package being built for the same Python
148 # implementations.
149 #
150 # The generate USE-flag list is compatible with packages using python-r1
151 # and python-distutils-ng eclasses. It must not be used on packages
152 # using python.eclass.
153 #
154 # Example use:
155 # @CODE
156 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
157 # @CODE
158 #
159 # Example value:
160 # @CODE
161 # python_targets_python2_7(-)?,python_targets_python3_4(-)?
162 # @CODE
163
164 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
165 # @DESCRIPTION:
166 # This is an eclass-generated required-use expression which ensures at
167 # least one Python implementation has been enabled.
168 #
169 # This expression should be utilized in an ebuild by including it in
170 # REQUIRED_USE, optionally behind a use flag.
171 #
172 # Example use:
173 # @CODE
174 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
175 # @CODE
176 #
177 # Example value:
178 # @CODE
179 # || ( python_targets_python2_7 python_targets_python3_4 )
180 # @CODE
181
182 _python_set_globals() {
183         PYTHON_DEPS=
184         local i PYTHON_PKG_DEP
185
186         _python_set_impls
187
188         for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
189                 python_export "${i}" PYTHON_PKG_DEP
190                 PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
191         done
192
193         local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
194         local optflags=${flags[@]/%/(-)?}
195
196         # A nice QA trick here. Since a python-single-r1 package has to have
197         # at least one PYTHON_SINGLE_TARGET enabled (REQUIRED_USE),
198         # the following check will always fail on those packages. Therefore,
199         # it should prevent developers from mistakenly depending on packages
200         # not supporting multiple Python implementations.
201
202         local flags_st=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/-python_single_target_}" )
203         optflags+=,${flags_st[@]/%/(-)}
204
205         IUSE=${flags[*]}
206         PYTHON_REQUIRED_USE="|| ( ${flags[*]} )"
207         PYTHON_USEDEP=${optflags// /,}
208
209         # 1) well, python-exec would suffice as an RDEP
210         # but no point in making this overcomplex, BDEP doesn't hurt anyone
211         # 2) python-exec should be built with all targets forced anyway
212         # but if new targets were added, we may need to force a rebuild
213         # 3) use whichever python-exec slot installed in EAPI 5. For EAPI 4,
214         # just fix :2 since := deps are not supported.
215         if [[ ${_PYTHON_WANT_PYTHON_EXEC2} == 0 ]]; then
216                 die "python-exec:0 is no longer supported, please fix your ebuild to work with python-exec:2"
217         elif [[ ${EAPI} != 4 ]]; then
218                 PYTHON_DEPS+=">=dev-lang/python-exec-2:=[${PYTHON_USEDEP}]"
219         else
220                 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
221         fi
222         readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP
223 }
224 _python_set_globals
225 unset -f _python_set_globals
226
227 # @FUNCTION: _python_validate_useflags
228 # @INTERNAL
229 # @DESCRIPTION:
230 # Enforce the proper setting of PYTHON_TARGETS.
231 _python_validate_useflags() {
232         debug-print-function ${FUNCNAME} "${@}"
233
234         local i
235
236         for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
237                 use "python_targets_${i}" && return 0
238         done
239
240         eerror "No Python implementation selected for the build. Please add one"
241         eerror "of the following values to your PYTHON_TARGETS (in make.conf):"
242         eerror
243         eerror "${PYTHON_COMPAT[@]}"
244         echo
245         die "No supported Python implementation in PYTHON_TARGETS."
246 }
247
248 # @FUNCTION: python_gen_usedep
249 # @USAGE: <pattern> [...]
250 # @DESCRIPTION:
251 # Output a USE dependency string for Python implementations which
252 # are both in PYTHON_COMPAT and match any of the patterns passed
253 # as parameters to the function.
254 #
255 # Remember to escape or quote the patterns to prevent shell filename
256 # expansion.
257 #
258 # When all implementations are requested, please use ${PYTHON_USEDEP}
259 # instead. Please also remember to set an appropriate REQUIRED_USE
260 # to avoid ineffective USE flags.
261 #
262 # Example:
263 # @CODE
264 # PYTHON_COMPAT=( python{2_7,3_4} )
265 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
266 # @CODE
267 #
268 # It will cause the dependency to look like:
269 # @CODE
270 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
271 # @CODE
272 python_gen_usedep() {
273         debug-print-function ${FUNCNAME} "${@}"
274
275         local impl pattern
276         local matches=()
277
278         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
279                 for pattern; do
280                         if [[ ${impl} == ${pattern} ]]; then
281                                 matches+=(
282                                         "python_targets_${impl}(-)?"
283                                         "-python_single_target_${impl}(-)"
284                                 )
285                                 break
286                         fi
287                 done
288         done
289
290         [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
291
292         local out=${matches[@]}
293         echo "${out// /,}"
294 }
295
296 # @FUNCTION: python_gen_useflags
297 # @USAGE: <pattern> [...]
298 # @DESCRIPTION:
299 # Output a list of USE flags for Python implementations which
300 # are both in PYTHON_COMPAT and match any of the patterns passed
301 # as parameters to the function.
302 #
303 # Example:
304 # @CODE
305 # PYTHON_COMPAT=( python{2_7,3_4} )
306 # REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
307 # @CODE
308 #
309 # It will cause the variable to look like:
310 # @CODE
311 # REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
312 # @CODE
313 python_gen_useflags() {
314         debug-print-function ${FUNCNAME} "${@}"
315
316         local impl pattern
317         local matches=()
318
319         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
320                 for pattern; do
321                         if [[ ${impl} == ${pattern} ]]; then
322                                 matches+=( "python_targets_${impl}" )
323                                 break
324                         fi
325                 done
326         done
327
328         echo "${matches[@]}"
329 }
330
331 # @FUNCTION: python_gen_cond_dep
332 # @USAGE: <dependency> <pattern> [...]
333 # @DESCRIPTION:
334 # Output a list of <dependency>-ies made conditional to USE flags
335 # of Python implementations which are both in PYTHON_COMPAT and match
336 # any of the patterns passed as the remaining parameters.
337 #
338 # In order to enforce USE constraints on the packages, verbatim
339 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
340 # specification. It will get expanded within the function into a proper
341 # USE dependency string.
342 #
343 # Example:
344 # @CODE
345 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
346 # RDEPEND="$(python_gen_cond_dep \
347 #   'dev-python/unittest2[${PYTHON_USEDEP}]' python2_7 pypy )"
348 # @CODE
349 #
350 # It will cause the variable to look like:
351 # @CODE
352 # RDEPEND="python_targets_python2_7? (
353 #     dev-python/unittest2[python_targets_python2_7?] )
354 #       python_targets_pypy? (
355 #     dev-python/unittest2[python_targets_pypy?] )"
356 # @CODE
357 python_gen_cond_dep() {
358         debug-print-function ${FUNCNAME} "${@}"
359
360         local impl pattern
361         local matches=()
362
363         local dep=${1}
364         shift
365
366         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
367                 for pattern; do
368                         if [[ ${impl} == ${pattern} ]]; then
369                                 # substitute ${PYTHON_USEDEP} if used
370                                 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
371                                 #  the code is run at most once)
372                                 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
373                                         local usedep=$(python_gen_usedep "${@}")
374                                         dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
375                                 fi
376
377                                 matches+=( "python_targets_${impl}? ( ${dep} )" )
378                                 break
379                         fi
380                 done
381         done
382
383         echo "${matches[@]}"
384 }
385
386 # @FUNCTION: python_gen_impl_dep
387 # @USAGE: [<requested-use-flags> [<impl-pattern>...]]
388 # @DESCRIPTION:
389 # Output a dependency on Python implementations with the specified USE
390 # dependency string appended, or no USE dependency string if called
391 # without the argument (or with empty argument). If any implementation
392 # patterns are passed, the output dependencies will be generated only
393 # for the implementations matching them.
394 #
395 # Use this function when you need to request different USE flags
396 # on the Python interpreter depending on package's USE flags. If you
397 # only need a single set of interpreter USE flags, just set
398 # PYTHON_REQ_USE and use ${PYTHON_DEPS} globally.
399 #
400 # Example:
401 # @CODE
402 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
403 # RDEPEND="foo? ( $(python_gen_impl_dep 'xml(+)') )"
404 # @CODE
405 #
406 # It will cause the variable to look like:
407 # @CODE
408 # RDEPEND="foo? (
409 #   python_targets_python2_7? (
410 #     dev-lang/python:2.7[xml(+)] )
411 #       python_targets_pypy? (
412 #     dev-python/pypy[xml(+)] ) )"
413 # @CODE
414 python_gen_impl_dep() {
415         debug-print-function ${FUNCNAME} "${@}"
416
417         local impl pattern
418         local matches=()
419
420         local PYTHON_REQ_USE=${1}
421         shift
422
423         local patterns=( "${@-*}" )
424         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
425                 for pattern in "${patterns[@]}"; do
426                         if [[ ${impl} == ${pattern} ]]; then
427                                 local PYTHON_PKG_DEP
428                                 python_export "${impl}" PYTHON_PKG_DEP
429                                 matches+=( "python_targets_${impl}? ( ${PYTHON_PKG_DEP} )" )
430                                 break
431                         fi
432                 done
433         done
434
435         echo "${matches[@]}"
436 }
437
438 # @ECLASS-VARIABLE: BUILD_DIR
439 # @DESCRIPTION:
440 # The current build directory. In global scope, it is supposed to
441 # contain an initial build directory; if unset, it defaults to ${S}.
442 #
443 # In functions run by python_foreach_impl(), the BUILD_DIR is locally
444 # set to an implementation-specific build directory. That path is
445 # created through appending a hyphen and the implementation name
446 # to the final component of the initial BUILD_DIR.
447 #
448 # Example value:
449 # @CODE
450 # ${WORKDIR}/foo-1.3-python2_7
451 # @CODE
452
453 # @FUNCTION: python_copy_sources
454 # @DESCRIPTION:
455 # Create a single copy of the package sources for each enabled Python
456 # implementation.
457 #
458 # The sources are always copied from initial BUILD_DIR (or S if unset)
459 # to implementation-specific build directory matching BUILD_DIR used by
460 # python_foreach_abi().
461 python_copy_sources() {
462         debug-print-function ${FUNCNAME} "${@}"
463
464         local MULTIBUILD_VARIANTS
465         _python_obtain_impls
466
467         multibuild_copy_sources
468 }
469
470 # @FUNCTION: _python_obtain_impls
471 # @INTERNAL
472 # @DESCRIPTION:
473 # Set up the enabled implementation list.
474 _python_obtain_impls() {
475         if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
476                 if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
477                         ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
478                         ewarn "implementations will be enabled:"
479                         ewarn
480                         ewarn " ${PYTHON_COMPAT_OVERRIDE}"
481                         ewarn
482                         ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
483                         _PYTHON_COMPAT_OVERRIDE_WARNED=1
484                 fi
485
486                 MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
487                 return
488         fi
489
490         _python_validate_useflags
491
492         MULTIBUILD_VARIANTS=()
493
494         for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
495                 has "${impl}" "${PYTHON_COMPAT[@]}" && \
496                 use "python_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
497         done
498 }
499
500 # @FUNCTION: _python_multibuild_wrapper
501 # @USAGE: <command> [<args>...]
502 # @INTERNAL
503 # @DESCRIPTION:
504 # Initialize the environment for Python implementation selected
505 # for multibuild.
506 _python_multibuild_wrapper() {
507         debug-print-function ${FUNCNAME} "${@}"
508
509         local -x EPYTHON PYTHON
510         local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
511         python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
512         python_wrapper_setup
513
514         "${@}"
515 }
516
517 # @FUNCTION: python_foreach_impl
518 # @USAGE: <command> [<args>...]
519 # @DESCRIPTION:
520 # Run the given command for each of the enabled Python implementations.
521 # If additional parameters are passed, they will be passed through
522 # to the command.
523 #
524 # The function will return 0 status if all invocations succeed.
525 # Otherwise, the return code from first failing invocation will
526 # be returned.
527 #
528 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
529 # locally, and the former two are exported to the command environment.
530 python_foreach_impl() {
531         debug-print-function ${FUNCNAME} "${@}"
532
533         local MULTIBUILD_VARIANTS
534         _python_obtain_impls
535
536         multibuild_foreach_variant _python_multibuild_wrapper "${@}"
537 }
538
539 # @FUNCTION: python_parallel_foreach_impl
540 # @USAGE: <command> [<args>...]
541 # @DESCRIPTION:
542 # Run the given command for each of the enabled Python implementations.
543 # If additional parameters are passed, they will be passed through
544 # to the command.
545 #
546 # The function will return 0 status if all invocations succeed.
547 # Otherwise, the return code from first failing invocation will
548 # be returned.
549 #
550 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
551 # locally, and the former two are exported to the command environment.
552 #
553 # This command used to be the parallel variant of python_foreach_impl.
554 # However, the parallel run support has been removed to simplify
555 # the eclasses and make them more predictable and therefore it is now
556 # only a deprecated alias to python_foreach_impl.
557 python_parallel_foreach_impl() {
558         debug-print-function ${FUNCNAME} "${@}"
559
560         [[ ${EAPI} == [45] ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}"
561
562         if [[ ! ${_PYTHON_PARALLEL_WARNED} ]]; then
563                 eqawarn "python_parallel_foreach_impl() is no longer meaningful. All runs"
564                 eqawarn "are non-parallel now. Please replace the call with python_foreach_impl."
565
566                 _PYTHON_PARALLEL_WARNED=1
567         fi
568
569         local MULTIBUILD_VARIANTS
570         _python_obtain_impls
571         multibuild_foreach_variant _python_multibuild_wrapper "${@}"
572 }
573
574 # @FUNCTION: python_setup
575 # @USAGE: [<impl-pattern>...]
576 # @DESCRIPTION:
577 # Find the best (most preferred) Python implementation that is enabled
578 # and matches at least one of the patterns passed (or '*' if no patterns
579 # passed). Set the Python build environment up for that implementation.
580 #
581 # This function needs to be used when Python is being called outside
582 # of python_foreach_impl calls (e.g. for shared processes like doc
583 # building). python_foreach_impl sets up the build environment itself.
584 #
585 # If the specific commands support only a subset of Python
586 # implementations, patterns need to be passed to restrict the allowed
587 # implementations.
588 #
589 # Example:
590 # @CODE
591 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
592 #
593 # src_compile() {
594 #   #...
595 #   if use doc; then
596 #     python_setup 'python2*'
597 #     make doc
598 #   fi
599 # }
600 # @CODE
601 python_setup() {
602         debug-print-function ${FUNCNAME} "${@}"
603
604         local best_impl patterns=( "${@-*}" )
605         _python_try_impl() {
606                 local pattern
607                 for pattern in "${patterns[@]}"; do
608                         if [[ ${EPYTHON} == ${pattern} ]]; then
609                                 best_impl=${EPYTHON}
610                         fi
611                 done
612         }
613         python_foreach_impl _python_try_impl
614         unset -f _python_try_impl
615
616         if [[ ! ${best_impl} ]]; then
617                 eerror "${FUNCNAME}: none of the enabled implementation matched the patterns."
618                 eerror "  patterns: ${@-'(*)'}"
619                 eerror "Likely a REQUIRED_USE constraint (possibly USE-conditional) is missing."
620                 eerror "  suggested: || ( \$(python_gen_useflags ${@}) )"
621                 eerror "(remember to quote all the patterns with '')"
622                 die "${FUNCNAME}: no enabled implementation satisfy requirements"
623         fi
624
625         python_export "${best_impl}" EPYTHON PYTHON
626         python_wrapper_setup
627 }
628
629 # @FUNCTION: python_export_best
630 # @USAGE: [<variable>...]
631 # @DESCRIPTION:
632 # Find the best (most preferred) Python implementation enabled
633 # and export given variables for it. If no variables are provided,
634 # EPYTHON & PYTHON will be exported.
635 python_export_best() {
636         debug-print-function ${FUNCNAME} "${@}"
637
638         [[ ${EAPI} == [45] ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}"
639
640         eqawarn "python_export_best() is deprecated. Please use python_setup instead,"
641         eqawarn "combined with python_export if necessary."
642
643         [[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
644
645         local best MULTIBUILD_VARIANTS
646         _python_obtain_impls
647
648         _python_set_best() {
649                 best=${MULTIBUILD_VARIANT}
650         }
651         multibuild_for_best_variant _python_set_best
652         unset -f _python_set_best
653
654         debug-print "${FUNCNAME}: Best implementation is: ${best}"
655         python_export "${best}" "${@}"
656         python_wrapper_setup
657 }
658
659 # @FUNCTION: python_replicate_script
660 # @USAGE: <path>...
661 # @DESCRIPTION:
662 # Copy the given script to variants for all enabled Python
663 # implementations, then replace it with a symlink to the wrapper.
664 #
665 # All specified files must start with a 'python' shebang. A file not
666 # having a matching shebang will be refused.
667 python_replicate_script() {
668         debug-print-function ${FUNCNAME} "${@}"
669
670         _python_replicate_script() {
671                 local _PYTHON_FIX_SHEBANG_QUIET=1
672
673                 local PYTHON_SCRIPTDIR
674                 python_export PYTHON_SCRIPTDIR
675
676                 (
677                         exeinto "${PYTHON_SCRIPTDIR#${EPREFIX}}"
678                         doexe "${files[@]}"
679                 )
680
681                 python_fix_shebang -q \
682                         "${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}"
683         }
684
685         local files=( "${@}" )
686         python_foreach_impl _python_replicate_script
687         unset -f _python_replicate_script
688
689         # install the wrappers
690         local f
691         for f; do
692                 _python_ln_rel "${ED%/}/usr/lib/python-exec/python-exec2" "${f}" || die
693         done
694 }
695
696 _PYTHON_R1=1
697 fi