1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: python-r1.eclass
6 # Python team <python@gentoo.org>
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: A common, simple eclass for Python packages.
13 # A common eclass providing helper functions to build and install
14 # packages supporting being installed for multiple Python
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.
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
29 # For more information, please see the wiki:
30 # https://wiki.gentoo.org/wiki/Project:Python/python-r1
34 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
37 # EAPI=5 is required for sane USE_EXPAND dependencies
40 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
44 if [[ ! ${_PYTHON_R1} ]]; then
46 if [[ ${_PYTHON_SINGLE_R1} ]]; then
47 die 'python-r1.eclass can not be used with python-single-r1.eclass.'
48 elif [[ ${_PYTHON_ANY_R1} ]]; then
49 die 'python-r1.eclass can not be used with python-any-r1.eclass.'
52 [[ ${EAPI} == [45] ]] && inherit eutils
53 inherit multibuild python-utils-r1
57 # @ECLASS-VARIABLE: PYTHON_COMPAT
60 # This variable contains a list of Python implementations the package
61 # supports. It must be set before the `inherit' call. It has to be
66 # PYTHON_COMPAT=( python2_7 python3_3 python3_4 )
69 # Please note that you can also use bash brace expansion if you like:
71 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
74 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
77 # This variable can be used when working with ebuilds to override
78 # the in-ebuild PYTHON_COMPAT. It is a string listing all
79 # the implementations which package will be built for. It need be
80 # specified in the calling environment, and not in ebuilds.
82 # It should be noted that in order to preserve metadata immutability,
83 # PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
84 # The state of PYTHON_TARGETS is ignored, and all the implementations
85 # in PYTHON_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
90 # PYTHON_COMPAT_OVERRIDE='pypy python3_3' emerge -1v dev-python/foo
93 # @ECLASS-VARIABLE: PYTHON_REQ_USE
96 # The list of USEflags required to be enabled on the chosen Python
97 # implementations, formed as a USE-dependency string. It should be valid
98 # for all implementations in PYTHON_COMPAT, so it may be necessary to
101 # This should be set before calling `inherit'.
105 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
108 # It will cause the Python dependencies to look like:
110 # python_targets_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
113 # @ECLASS-VARIABLE: PYTHON_DEPS
115 # This is an eclass-generated Python dependency string for all
116 # implementations listed in PYTHON_COMPAT.
120 # RDEPEND="${PYTHON_DEPS}
122 # DEPEND="${RDEPEND}"
127 # dev-lang/python-exec:=
128 # python_targets_python2_7? ( dev-lang/python:2.7[gdbm] )
129 # python_targets_pypy? ( dev-python/pypy[gdbm] )
132 # @ECLASS-VARIABLE: PYTHON_USEDEP
134 # This is an eclass-generated USE-dependency string which can be used to
135 # depend on another Python package being built for the same Python
138 # The generate USE-flag list is compatible with packages using python-r1
139 # and python-distutils-ng eclasses. It must not be used on packages
140 # using python.eclass.
144 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
149 # python_targets_python2_7(-)?,python_targets_python3_4(-)?
152 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
154 # This is an eclass-generated required-use expression which ensures at
155 # least one Python implementation has been enabled.
157 # This expression should be utilized in an ebuild by including it in
158 # REQUIRED_USE, optionally behind a use flag.
162 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
167 # || ( python_targets_python2_7 python_targets_python3_4 )
170 _python_set_globals() {
171 local deps i PYTHON_PKG_DEP
175 for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
176 python_export "${i}" PYTHON_PKG_DEP
177 deps+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
180 local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
181 local optflags=${flags[@]/%/(-)?}
183 # A nice QA trick here. Since a python-single-r1 package has to have
184 # at least one PYTHON_SINGLE_TARGET enabled (REQUIRED_USE),
185 # the following check will always fail on those packages. Therefore,
186 # it should prevent developers from mistakenly depending on packages
187 # not supporting multiple Python implementations.
189 local flags_st=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/-python_single_target_}" )
190 optflags+=,${flags_st[@]/%/(-)}
191 local requse="|| ( ${flags[*]} )"
192 local usedep=${optflags// /,}
194 # 1) well, python-exec would suffice as an RDEP
195 # but no point in making this overcomplex, BDEP doesn't hurt anyone
196 # 2) python-exec should be built with all targets forced anyway
197 # but if new targets were added, we may need to force a rebuild
198 deps+=">=dev-lang/python-exec-2:=[${usedep}]"
200 if [[ ${PYTHON_DEPS+1} ]]; then
201 # IUSE is magical, so we can't really check it
202 # (but we verify PYTHON_COMPAT already)
204 if [[ ${PYTHON_DEPS} != "${deps}" ]]; then
205 eerror "PYTHON_DEPS have changed between inherits (PYTHON_REQ_USE?)!"
206 eerror "Before: ${PYTHON_DEPS}"
207 eerror "Now : ${deps}"
208 die "PYTHON_DEPS integrity check failed"
211 # these two are formality -- they depend on PYTHON_COMPAT only
212 if [[ ${PYTHON_REQUIRED_USE} != ${requse} ]]; then
213 eerror "PYTHON_REQUIRED_USE have changed between inherits!"
214 eerror "Before: ${PYTHON_REQUIRED_USE}"
215 eerror "Now : ${requse}"
216 die "PYTHON_REQUIRED_USE integrity check failed"
219 if [[ ${PYTHON_USEDEP} != "${usedep}" ]]; then
220 eerror "PYTHON_USEDEP have changed between inherits!"
221 eerror "Before: ${PYTHON_USEDEP}"
222 eerror "Now : ${usedep}"
223 die "PYTHON_USEDEP integrity check failed"
229 PYTHON_REQUIRED_USE=${requse}
230 PYTHON_USEDEP=${usedep}
231 readonly PYTHON_DEPS PYTHON_REQUIRED_USE
235 unset -f _python_set_globals
237 if [[ ! ${_PYTHON_R1} ]]; then
239 # @FUNCTION: _python_validate_useflags
242 # Enforce the proper setting of PYTHON_TARGETS, if PYTHON_COMPAT_OVERRIDE
243 # is not in effect. If it is, just warn that the flags will be ignored.
244 _python_validate_useflags() {
245 debug-print-function ${FUNCNAME} "${@}"
247 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
248 if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
249 ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
250 ewarn "implementations will be enabled:"
252 ewarn " ${PYTHON_COMPAT_OVERRIDE}"
254 ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
255 _PYTHON_COMPAT_OVERRIDE_WARNED=1
257 # we do not use flags with PCO
263 for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
264 use "python_targets_${i}" && return 0
267 eerror "No Python implementation selected for the build. Please add one"
268 eerror "of the following values to your PYTHON_TARGETS (in make.conf):"
270 eerror "${PYTHON_COMPAT[@]}"
272 die "No supported Python implementation in PYTHON_TARGETS."
275 # @FUNCTION: _python_gen_usedep
277 # @USAGE: [<pattern>...]
279 # Output a USE dependency string for Python implementations which
280 # are both in PYTHON_COMPAT and match any of the patterns passed
281 # as parameters to the function.
283 # The patterns can be either fnmatch-style patterns (matched via bash
284 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
285 # appropriately all enabled Python 2/3 implementations (alike
286 # python_is_python3). Remember to escape or quote the fnmatch patterns
287 # to prevent accidental shell filename expansion.
289 # This is an internal function used to implement python_gen_cond_dep
290 # and deprecated python_gen_usedep.
291 _python_gen_usedep() {
292 debug-print-function ${FUNCNAME} "${@}"
294 local impl matches=()
296 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
297 if _python_impl_matches "${impl}" "${@}"; then
299 "python_targets_${impl}(-)?"
300 "-python_single_target_${impl}(-)"
305 [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
307 local out=${matches[@]}
311 # @FUNCTION: python_gen_usedep
312 # @USAGE: <pattern> [...]
314 # DEPRECATED. Please use python_gen_cond_dep instead.
316 # Output a USE dependency string for Python implementations which
317 # are both in PYTHON_COMPAT and match any of the patterns passed
318 # as parameters to the function.
320 # The patterns can be either fnmatch-style patterns (matched via bash
321 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
322 # appropriately all enabled Python 2/3 implementations (alike
323 # python_is_python3). Remember to escape or quote the fnmatch patterns
324 # to prevent accidental shell filename expansion.
326 # When all implementations are requested, please use ${PYTHON_USEDEP}
327 # instead. Please also remember to set an appropriate REQUIRED_USE
328 # to avoid ineffective USE flags.
332 # PYTHON_COMPAT=( python{2_7,3_4} )
333 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
336 # It will cause the dependency to look like:
338 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
340 python_gen_usedep() {
341 debug-print-function ${FUNCNAME} "${@}"
343 # output only once, during some reasonable phase
344 # (avoid spamming cache regen runs)
345 if [[ ${EBUILD_PHASE} == setup ]]; then
346 eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead."
348 _python_gen_usedep "${@}"
351 # @FUNCTION: python_gen_useflags
352 # @USAGE: [<pattern>...]
354 # Output a list of USE flags for Python implementations which
355 # are both in PYTHON_COMPAT and match any of the patterns passed
356 # as parameters to the function.
358 # The patterns can be either fnmatch-style patterns (matched via bash
359 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
360 # appropriately all enabled Python 2/3 implementations (alike
361 # python_is_python3). Remember to escape or quote the fnmatch patterns
362 # to prevent accidental shell filename expansion.
366 # PYTHON_COMPAT=( python{2_7,3_4} )
367 # REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
370 # It will cause the variable to look like:
372 # REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
374 python_gen_useflags() {
375 debug-print-function ${FUNCNAME} "${@}"
377 local impl matches=()
379 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
380 if _python_impl_matches "${impl}" "${@}"; then
381 matches+=( "python_targets_${impl}" )
388 # @FUNCTION: python_gen_cond_dep
389 # @USAGE: <dependency> [<pattern>...]
391 # Output a list of <dependency>-ies made conditional to USE flags
392 # of Python implementations which are both in PYTHON_COMPAT and match
393 # any of the patterns passed as the remaining parameters.
395 # The patterns can be either fnmatch-style patterns (matched via bash
396 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
397 # appropriately all enabled Python 2/3 implementations (alike
398 # python_is_python3). Remember to escape or quote the fnmatch patterns
399 # to prevent accidental shell filename expansion.
401 # In order to enforce USE constraints on the packages, verbatim
402 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
403 # specification. It will get expanded within the function into a proper
404 # USE dependency string.
408 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
409 # RDEPEND="$(python_gen_cond_dep \
410 # 'dev-python/unittest2[${PYTHON_USEDEP}]' python2_7 pypy )"
413 # It will cause the variable to look like:
415 # RDEPEND="python_targets_python2_7? (
416 # dev-python/unittest2[python_targets_python2_7?] )
417 # python_targets_pypy? (
418 # dev-python/unittest2[python_targets_pypy?] )"
420 python_gen_cond_dep() {
421 debug-print-function ${FUNCNAME} "${@}"
423 local impl matches=()
427 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
428 if _python_impl_matches "${impl}" "${@}"; then
429 # substitute ${PYTHON_USEDEP} if used
430 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
431 # the code is run at most once)
432 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
433 local usedep=$(_python_gen_usedep "${@}")
434 dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
437 matches+=( "python_targets_${impl}? ( ${dep} )" )
444 # @FUNCTION: python_gen_impl_dep
445 # @USAGE: [<requested-use-flags> [<impl-pattern>...]]
447 # Output a dependency on Python implementations with the specified USE
448 # dependency string appended, or no USE dependency string if called
449 # without the argument (or with empty argument). If any implementation
450 # patterns are passed, the output dependencies will be generated only
451 # for the implementations matching them.
453 # The patterns can be either fnmatch-style patterns (matched via bash
454 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
455 # appropriately all enabled Python 2/3 implementations (alike
456 # python_is_python3). Remember to escape or quote the fnmatch patterns
457 # to prevent accidental shell filename expansion.
459 # Use this function when you need to request different USE flags
460 # on the Python interpreter depending on package's USE flags. If you
461 # only need a single set of interpreter USE flags, just set
462 # PYTHON_REQ_USE and use ${PYTHON_DEPS} globally.
466 # PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy )
467 # RDEPEND="foo? ( $(python_gen_impl_dep 'xml(+)') )"
470 # It will cause the variable to look like:
473 # python_targets_python2_7? (
474 # dev-lang/python:2.7[xml(+)] )
475 # python_targets_pypy? (
476 # dev-python/pypy[xml(+)] ) )"
478 python_gen_impl_dep() {
479 debug-print-function ${FUNCNAME} "${@}"
481 local impl matches=()
482 local PYTHON_REQ_USE=${1}
485 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
486 if _python_impl_matches "${impl}" "${@}"; then
488 python_export "${impl}" PYTHON_PKG_DEP
489 matches+=( "python_targets_${impl}? ( ${PYTHON_PKG_DEP} )" )
496 # @FUNCTION: python_gen_any_dep
497 # @USAGE: <dependency-block> [<impl-pattern>...]
499 # Generate an any-of dependency that enforces a version match between
500 # the Python interpreter and Python packages. <dependency-block> needs
501 # to list one or more dependencies with verbatim '${PYTHON_USEDEP}'
502 # references (quoted!) that will get expanded inside the function.
503 # Optionally, patterns may be specified to restrict the dependency
504 # to a subset of Python implementations supported by the ebuild.
506 # The patterns can be either fnmatch-style patterns (matched via bash
507 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
508 # appropriately all enabled Python 2/3 implementations (alike
509 # python_is_python3). Remember to escape or quote the fnmatch patterns
510 # to prevent accidental shell filename expansion.
512 # This should be used along with an appropriate python_check_deps()
513 # that checks which of the any-of blocks were matched, and python_setup
514 # call that enables use of the matched implementation.
518 # DEPEND="$(python_gen_any_dep '
519 # dev-python/foo[${PYTHON_USEDEP}]
520 # || ( dev-python/bar[${PYTHON_USEDEP}]
521 # dev-python/baz[${PYTHON_USEDEP}] )' -2)"
523 # python_check_deps() {
524 # has_version "dev-python/foo[${PYTHON_USEDEP}]" \
525 # && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
526 # || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
530 # python_foreach_impl usual_code
532 # # some common post-build task that requires Python 2
542 # dev-lang/python:2.7
543 # dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
544 # || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
545 # dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] )
548 # dev-lang/python:3.3
549 # dev-python/foo[python_targets_python3_3(-)?,python_single_target_python3_3(+)?]
550 # || ( dev-python/bar[python_targets_python3_3(-)?,python_single_target_python3_3(+)?]
551 # dev-python/baz[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] )
555 python_gen_any_dep() {
556 debug-print-function ${FUNCNAME} "${@}"
559 [[ ${depstr} ]] || die "No dependency string provided"
562 local i PYTHON_PKG_DEP out=
563 for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
564 if _python_impl_matches "${i}" "${@}"; then
565 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
566 python_export "${i}" PYTHON_PKG_DEP
568 local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
569 # note: need to strip '=' slot operator for || deps
570 out="( ${PYTHON_PKG_DEP/:0=/:0} ${i_depstr} ) ${out}"
576 # @ECLASS-VARIABLE: BUILD_DIR
578 # The current build directory. In global scope, it is supposed to
579 # contain an initial build directory; if unset, it defaults to ${S}.
581 # In functions run by python_foreach_impl(), the BUILD_DIR is locally
582 # set to an implementation-specific build directory. That path is
583 # created through appending a hyphen and the implementation name
584 # to the final component of the initial BUILD_DIR.
588 # ${WORKDIR}/foo-1.3-python2_7
591 # @FUNCTION: python_copy_sources
593 # Create a single copy of the package sources for each enabled Python
596 # The sources are always copied from initial BUILD_DIR (or S if unset)
597 # to implementation-specific build directory matching BUILD_DIR used by
598 # python_foreach_abi().
599 python_copy_sources() {
600 debug-print-function ${FUNCNAME} "${@}"
602 local MULTIBUILD_VARIANTS
605 multibuild_copy_sources
608 # @FUNCTION: _python_obtain_impls
611 # Set up the enabled implementation list.
612 _python_obtain_impls() {
613 _python_validate_useflags
615 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
616 MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
620 MULTIBUILD_VARIANTS=()
623 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
624 has "${impl}" "${PYTHON_COMPAT[@]}" && \
625 use "python_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
629 # @FUNCTION: _python_multibuild_wrapper
630 # @USAGE: <command> [<args>...]
633 # Initialize the environment for Python implementation selected
635 _python_multibuild_wrapper() {
636 debug-print-function ${FUNCNAME} "${@}"
638 local -x EPYTHON PYTHON
639 local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
640 python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
646 # @FUNCTION: python_foreach_impl
647 # @USAGE: <command> [<args>...]
649 # Run the given command for each of the enabled Python implementations.
650 # If additional parameters are passed, they will be passed through
653 # The function will return 0 status if all invocations succeed.
654 # Otherwise, the return code from first failing invocation will
657 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
658 # locally, and the former two are exported to the command environment.
659 python_foreach_impl() {
660 debug-print-function ${FUNCNAME} "${@}"
662 local MULTIBUILD_VARIANTS
665 multibuild_foreach_variant _python_multibuild_wrapper "${@}"
668 # @FUNCTION: python_setup
669 # @USAGE: [<impl-pattern>...]
671 # Find the best (most preferred) Python implementation that is suitable
672 # for running common Python code. Set the Python build environment up
673 # for that implementation. This function has two modes of operation:
674 # pure and any-of dep.
676 # The pure mode is used if python_check_deps() function is not declared.
677 # In this case, an implementation is considered suitable if it is
678 # supported (in PYTHON_COMPAT), enabled (via USE flags) and matches
679 # at least one of the patterns passed (or '*' if no patterns passed).
681 # Implementation restrictions in the pure mode need to be accompanied
682 # by appropriate REQUIRED_USE constraints. Otherwise, the eclass may
683 # fail at build time due to unsatisfied dependencies.
685 # The any-of dep mode is used if python_check_deps() is declared.
686 # In this mode, an implementation is considered suitable if it is
687 # supported, matches at least one of the patterns and python_check_deps()
688 # has successful return code. USE flags are not considered.
690 # The python_check_deps() function in the any-of mode needs to be
691 # accompanied by appropriate any-of dependencies.
693 # The patterns can be either fnmatch-style patterns (matched via bash
694 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
695 # appropriately all enabled Python 2/3 implementations (alike
696 # python_is_python3). Remember to escape or quote the fnmatch patterns
697 # to prevent accidental shell filename expansion.
699 # This function needs to be used when Python is being called outside
700 # of python_foreach_impl calls (e.g. for shared processes like doc
701 # building). python_foreach_impl sets up the build environment itself.
705 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
706 # REQUIRED_USE="doc? ( $(python_gen_useflags 'python2*') )"
711 # python_setup 'python2*'
717 # Any-of mode example:
720 # $(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )"
722 # python_check_deps() {
723 # has_version "dev-python/epydoc[${PYTHON_USEDEP}]"
729 # python_setup 'python2*'
735 debug-print-function ${FUNCNAME} "${@}"
737 _python_validate_useflags
738 local pycompat=( "${PYTHON_COMPAT[@]}" )
739 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
740 pycompat=( ${PYTHON_COMPAT_OVERRIDE} )
744 declare -f python_check_deps >/dev/null && has_check_deps=1
746 # (reverse iteration -- newest impl first)
748 for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
749 local impl=${_PYTHON_SUPPORTED_IMPLS[i]}
751 # check PYTHON_COMPAT[_OVERRIDE]
752 has "${impl}" "${pycompat[@]}" || continue
754 # match USE flags only if override is not in effect
755 # and python_check_deps() is not defined
756 if [[ ! ${PYTHON_COMPAT_OVERRIDE} && ! ${has_check_deps} ]]; then
757 use "python_targets_${impl}" || continue
761 _python_impl_matches "${impl}" "${@}" || continue
763 python_export "${impl}" EPYTHON PYTHON
765 # if python_check_deps() is declared, switch into any-of mode
766 if [[ ${has_check_deps} ]]; then
767 # first check if the interpreter is installed
768 python_is_installed "${impl}" || continue
769 # then run python_check_deps
770 local PYTHON_USEDEP="python_targets_${impl}(-),python_single_target_${impl}(+)"
771 python_check_deps || continue
778 if [[ ! ${found} ]]; then
779 eerror "${FUNCNAME}: none of the enabled implementation matched the patterns."
780 eerror " patterns: ${@-'(*)'}"
781 eerror "Likely a REQUIRED_USE constraint (possibly USE-conditional) is missing."
782 eerror " suggested: || ( \$(python_gen_useflags ${@}) )"
783 eerror "(remember to quote all the patterns with '')"
784 die "${FUNCNAME}: no enabled implementation satisfy requirements"
790 # @FUNCTION: python_replicate_script
793 # Copy the given script to variants for all enabled Python
794 # implementations, then replace it with a symlink to the wrapper.
796 # All specified files must start with a 'python' shebang. A file not
797 # having a matching shebang will be refused.
798 python_replicate_script() {
799 debug-print-function ${FUNCNAME} "${@}"
801 _python_replicate_script() {
802 local _PYTHON_FIX_SHEBANG_QUIET=1
804 local PYTHON_SCRIPTDIR
805 python_export PYTHON_SCRIPTDIR
809 exeinto "${PYTHON_SCRIPTDIR#${EPREFIX}}"
813 python_fix_shebang -q \
814 "${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}"
817 local files=( "${@}" )
818 python_foreach_impl _python_replicate_script
819 unset -f _python_replicate_script
821 # install the wrappers
824 _python_ln_rel "${ED%/}/usr/lib/python-exec/python-exec2" "${f}" || die