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

Contents of /eclass/python-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.72 - (show annotations) (download)
Sat Apr 19 10:29:06 2014 UTC (6 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.71: +17 -7 lines
Support substituting ${PYTHON_USEDEP} in python_gen_cond_dep().

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.71 2014/04/09 21:34:10 mgorny Exp $
4
5 # @ECLASS: python-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: 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 and REQUIRED_USE. It exports PYTHON_DEPS
18 # and PYTHON_USEDEP so you can create correct dependencies for your
19 # package easily. It also provides methods to easily run a command for
20 # each enabled Python implementation and duplicate the sources for them.
21 #
22 # Please note that python-r1 will always inherit python-utils-r1 as
23 # well. Thus, all the functions defined there can be used
24 # in the packages using python-r1, and there is no need ever to inherit
25 # both.
26 #
27 # For more information, please see the python-r1 Developer's Guide:
28 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
29
30 case "${EAPI:-0}" in
31 0|1|2|3)
32 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
33 ;;
34 4|5)
35 # EAPI=4 is required for USE default deps on USE_EXPAND flags
36 ;;
37 *)
38 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
39 ;;
40 esac
41
42 if [[ ! ${_PYTHON_R1} ]]; then
43
44 if [[ ${_PYTHON_SINGLE_R1} ]]; then
45 die 'python-r1.eclass can not be used with python-single-r1.eclass.'
46 elif [[ ${_PYTHON_ANY_R1} ]]; then
47 die 'python-r1.eclass can not be used with python-any-r1.eclass.'
48 fi
49
50 inherit multibuild python-utils-r1
51
52 # @ECLASS-VARIABLE: PYTHON_COMPAT
53 # @REQUIRED
54 # @DESCRIPTION:
55 # This variable contains a list of Python implementations the package
56 # supports. It must be set before the `inherit' call. It has to be
57 # an array.
58 #
59 # Example:
60 # @CODE
61 # PYTHON_COMPAT=( python2_5 python2_6 python2_7 )
62 # @CODE
63 #
64 # Please note that you can also use bash brace expansion if you like:
65 # @CODE
66 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
67 # @CODE
68 if ! declare -p PYTHON_COMPAT &>/dev/null; then
69 die 'PYTHON_COMPAT not declared.'
70 fi
71
72 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
73 # @INTERNAL
74 # @DESCRIPTION:
75 # This variable can be used when working with ebuilds to override
76 # the in-ebuild PYTHON_COMPAT. It is a string listing all
77 # the implementations which package will be built for. It need be
78 # specified in the calling environment, and not in ebuilds.
79 #
80 # It should be noted that in order to preserve metadata immutability,
81 # PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
82 # The state of PYTHON_TARGETS is ignored, and all the implementations
83 # in PYTHON_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
84 # manually.
85 #
86 # Example:
87 # @CODE
88 # PYTHON_COMPAT_OVERRIDE='pypy python3_3' emerge -1v dev-python/foo
89 # @CODE
90
91 # @ECLASS-VARIABLE: PYTHON_REQ_USE
92 # @DEFAULT_UNSET
93 # @DESCRIPTION:
94 # The list of USEflags required to be enabled on the chosen Python
95 # implementations, formed as a USE-dependency string. It should be valid
96 # for all implementations in PYTHON_COMPAT, so it may be necessary to
97 # use USE defaults.
98 #
99 # This should be set before calling `inherit'.
100 #
101 # Example:
102 # @CODE
103 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
104 # @CODE
105 #
106 # It will cause the Python dependencies to look like:
107 # @CODE
108 # python_targets_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
109 # @CODE
110
111 # @ECLASS-VARIABLE: PYTHON_DEPS
112 # @DESCRIPTION:
113 # This is an eclass-generated Python dependency string for all
114 # implementations listed in PYTHON_COMPAT.
115 #
116 # Example use:
117 # @CODE
118 # RDEPEND="${PYTHON_DEPS}
119 # dev-foo/mydep"
120 # DEPEND="${RDEPEND}"
121 # @CODE
122 #
123 # Example value:
124 # @CODE
125 # dev-lang/python-exec:=
126 # python_targets_python2_6? ( dev-lang/python:2.6[gdbm] )
127 # python_targets_python2_7? ( dev-lang/python:2.7[gdbm] )
128 # @CODE
129
130 # @ECLASS-VARIABLE: PYTHON_USEDEP
131 # @DESCRIPTION:
132 # This is an eclass-generated USE-dependency string which can be used to
133 # depend on another Python package being built for the same Python
134 # implementations.
135 #
136 # The generate USE-flag list is compatible with packages using python-r1
137 # and python-distutils-ng eclasses. It must not be used on packages
138 # using python.eclass.
139 #
140 # Example use:
141 # @CODE
142 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
143 # @CODE
144 #
145 # Example value:
146 # @CODE
147 # python_targets_python2_6(-)?,python_targets_python2_7(-)?
148 # @CODE
149
150 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
151 # @DESCRIPTION:
152 # This is an eclass-generated required-use expression which ensures at
153 # least one Python implementation has been enabled.
154 #
155 # This expression should be utilized in an ebuild by including it in
156 # REQUIRED_USE, optionally behind a use flag.
157 #
158 # Example use:
159 # @CODE
160 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
161 # @CODE
162 #
163 # Example value:
164 # @CODE
165 # || ( python_targets_python2_6 python_targets_python2_7 )
166 # @CODE
167
168 _python_set_globals() {
169 local impls=()
170
171 PYTHON_DEPS=
172 local i PYTHON_PKG_DEP
173 for i in "${PYTHON_COMPAT[@]}"; do
174 _python_impl_supported "${i}" || continue
175
176 python_export "${i}" PYTHON_PKG_DEP
177 PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
178
179 impls+=( "${i}" )
180 done
181
182 if [[ ${#impls[@]} -eq 0 ]]; then
183 die "No supported implementation in PYTHON_COMPAT."
184 fi
185
186 local flags=( "${impls[@]/#/python_targets_}" )
187 local optflags=${flags[@]/%/(-)?}
188
189 # A nice QA trick here. Since a python-single-r1 package has to have
190 # at least one PYTHON_SINGLE_TARGET enabled (REQUIRED_USE),
191 # the following check will always fail on those packages. Therefore,
192 # it should prevent developers from mistakenly depending on packages
193 # not supporting multiple Python implementations.
194
195 local flags_st=( "${impls[@]/#/-python_single_target_}" )
196 optflags+=,${flags_st[@]/%/(-)}
197
198 IUSE=${flags[*]}
199 PYTHON_REQUIRED_USE="|| ( ${flags[*]} )"
200 PYTHON_USEDEP=${optflags// /,}
201
202 # 1) well, python-exec would suffice as an RDEP
203 # but no point in making this overcomplex, BDEP doesn't hurt anyone
204 # 2) python-exec should be built with all targets forced anyway
205 # but if new targets were added, we may need to force a rebuild
206 # 3) use whichever python-exec slot installed in EAPI 5. For EAPI 4,
207 # just fix :2 since := deps are not supported.
208 if [[ ${_PYTHON_WANT_PYTHON_EXEC2} == 0 ]]; then
209 PYTHON_DEPS+="dev-lang/python-exec:0[${PYTHON_USEDEP}]"
210 elif [[ ${EAPI} != 4 ]]; then
211 PYTHON_DEPS+="dev-lang/python-exec:=[${PYTHON_USEDEP}]"
212 else
213 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
214 fi
215 }
216 _python_set_globals
217
218 # @ECLASS-VARIABLE: DISTUTILS_JOBS
219 # @DEFAULT_UNSET
220 # @DESCRIPTION:
221 # The number of parallel jobs to run for distutils-r1 parallel builds.
222 # If unset, the job-count in ${MAKEOPTS} will be used.
223 #
224 # This variable is intended to be set in make.conf.
225
226 # @FUNCTION: _python_validate_useflags
227 # @INTERNAL
228 # @DESCRIPTION:
229 # Enforce the proper setting of PYTHON_TARGETS.
230 _python_validate_useflags() {
231 debug-print-function ${FUNCNAME} "${@}"
232
233 local i
234
235 for i in "${PYTHON_COMPAT[@]}"; do
236 _python_impl_supported "${i}" || continue
237
238 use "python_targets_${i}" && return 0
239 done
240
241 eerror "No Python implementation selected for the build. Please add one"
242 eerror "of the following values to your PYTHON_TARGETS (in make.conf):"
243 eerror
244 eerror "${PYTHON_COMPAT[@]}"
245 echo
246 die "No supported Python implementation in PYTHON_TARGETS."
247 }
248
249 # @FUNCTION: python_gen_usedep
250 # @USAGE: <pattern> [...]
251 # @DESCRIPTION:
252 # Output a USE dependency string for Python implementations which
253 # are both in PYTHON_COMPAT and match any of the patterns passed
254 # as parameters to the function.
255 #
256 # Remember to escape or quote the patterns to premature evaluation as a file
257 # name glob.
258 #
259 # When all implementations are requested, please use ${PYTHON_USEDEP}
260 # instead. Please also remember to set an appropriate REQUIRED_USE
261 # to avoid ineffective USE flags.
262 #
263 # Example:
264 # @CODE
265 # PYTHON_COMPAT=( python{2_7,3_2} )
266 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
267 # @CODE
268 #
269 # It will cause the dependency to look like:
270 # @CODE
271 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
272 # @CODE
273 python_gen_usedep() {
274 debug-print-function ${FUNCNAME} "${@}"
275
276 local impl pattern
277 local matches=()
278
279 for impl in "${PYTHON_COMPAT[@]}"; do
280 _python_impl_supported "${impl}" || continue
281
282 for pattern; do
283 if [[ ${impl} == ${pattern} ]]; then
284 matches+=(
285 "python_targets_${impl}(-)?"
286 "-python_single_target_${impl}(-)"
287 )
288 break
289 fi
290 done
291 done
292
293 [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
294
295 local out=${matches[@]}
296 echo ${out// /,}
297 }
298
299 # @FUNCTION: python_gen_useflags
300 # @USAGE: <pattern> [...]
301 # @DESCRIPTION:
302 # Output a list of USE flags for Python implementations which
303 # are both in PYTHON_COMPAT and match any of the patterns passed
304 # as parameters to the function.
305 #
306 # Example:
307 # @CODE
308 # PYTHON_COMPAT=( python{2_7,3_2} )
309 # REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
310 # @CODE
311 #
312 # It will cause the variable to look like:
313 # @CODE
314 # REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
315 # @CODE
316 python_gen_useflags() {
317 debug-print-function ${FUNCNAME} "${@}"
318
319 local impl pattern
320 local matches=()
321
322 for impl in "${PYTHON_COMPAT[@]}"; do
323 _python_impl_supported "${impl}" || continue
324
325 for pattern; do
326 if [[ ${impl} == ${pattern} ]]; then
327 matches+=( "python_targets_${impl}" )
328 break
329 fi
330 done
331 done
332
333 echo ${matches[@]}
334 }
335
336 # @FUNCTION: python_gen_cond_dep
337 # @USAGE: <dependency> <pattern> [...]
338 # @DESCRIPTION:
339 # Output a list of <dependency>-ies made conditional to USE flags
340 # of Python implementations which are both in PYTHON_COMPAT and match
341 # any of the patterns passed as the remaining parameters.
342 #
343 # In order to enforce USE constraints on the packages, verbatim
344 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
345 # specification. It will get expanded within the function into a proper
346 # USE dependency string.
347 #
348 # Example:
349 # @CODE
350 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
351 # RDEPEND="$(python_gen_cond_dep \
352 # 'dev-python/unittest2[${PYTHON_USEDEP}]' python{2_5,2_6})"
353 # @CODE
354 #
355 # It will cause the variable to look like:
356 # @CODE
357 # RDEPEND="python_targets_python2_5? (
358 # dev-python/unittest2[python_targets_python2_5?] )
359 # python_targets_python2_6? (
360 # dev-python/unittest2[python_targets_python2_6?] )"
361 # @CODE
362 python_gen_cond_dep() {
363 debug-print-function ${FUNCNAME} "${@}"
364
365 local impl pattern
366 local matches=()
367
368 local dep=${1}
369 shift
370
371 # substitute ${PYTHON_USEDEP} if used
372 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
373 local PYTHON_USEDEP=$(python_gen_usedep "${@}")
374 dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
375 fi
376
377 for impl in "${PYTHON_COMPAT[@]}"; do
378 _python_impl_supported "${impl}" || continue
379
380 for pattern; do
381 if [[ ${impl} == ${pattern} ]]; then
382 matches+=( "python_targets_${impl}? ( ${dep} )" )
383 break
384 fi
385 done
386 done
387
388 echo ${matches[@]}
389 }
390
391 # @ECLASS-VARIABLE: BUILD_DIR
392 # @DESCRIPTION:
393 # The current build directory. In global scope, it is supposed to
394 # contain an initial build directory; if unset, it defaults to ${S}.
395 #
396 # In functions run by python_foreach_impl(), the BUILD_DIR is locally
397 # set to an implementation-specific build directory. That path is
398 # created through appending a hyphen and the implementation name
399 # to the final component of the initial BUILD_DIR.
400 #
401 # Example value:
402 # @CODE
403 # ${WORKDIR}/foo-1.3-python2_6
404 # @CODE
405
406 # @FUNCTION: python_copy_sources
407 # @DESCRIPTION:
408 # Create a single copy of the package sources for each enabled Python
409 # implementation.
410 #
411 # The sources are always copied from initial BUILD_DIR (or S if unset)
412 # to implementation-specific build directory matching BUILD_DIR used by
413 # python_foreach_abi().
414 python_copy_sources() {
415 debug-print-function ${FUNCNAME} "${@}"
416
417 local MULTIBUILD_VARIANTS
418 _python_obtain_impls
419
420 multibuild_copy_sources
421 }
422
423 # @FUNCTION: _python_check_USE_PYTHON
424 # @INTERNAL
425 # @DESCRIPTION:
426 # Check whether USE_PYTHON and PYTHON_TARGETS are in sync. Output
427 # warnings if they are not.
428 _python_check_USE_PYTHON() {
429 debug-print-function ${FUNCNAME} "${@}"
430
431 if [[ ! ${_PYTHON_USE_PYTHON_CHECKED} ]]; then
432 _PYTHON_USE_PYTHON_CHECKED=1
433
434 # python-exec has profile-forced flags.
435 if [[ ${CATEGORY}/${PN} == dev-lang/python-exec ]]; then
436 return
437 fi
438
439 _try_eselect() {
440 # The eselect solution will work only with one py2 & py3.
441
442 local impl py2 py3 dis_py2 dis_py3
443 for impl in "${PYTHON_COMPAT[@]}"; do
444 _python_impl_supported "${impl}" || continue
445
446 if use "python_targets_${impl}"; then
447 case "${impl}" in
448 python2_*)
449 if [[ ${py2+1} ]]; then
450 debug-print "${FUNCNAME}: -> more than one py2: ${py2} ${impl}"
451 return 1
452 fi
453 py2=${impl/_/.}
454 ;;
455 python3_4)
456 debug-print "${FUNCNAME}: python3.4 found, not using eselect"
457 return 1
458 ;;
459 python3_*)
460 if [[ ${py3+1} ]]; then
461 debug-print "${FUNCNAME}: -> more than one py3: ${py3} ${impl}"
462 return 1
463 fi
464 py3=${impl/_/.}
465 ;;
466 *)
467 return 1
468 ;;
469 esac
470 else
471 case "${impl}" in
472 python2_*)
473 dis_py2=1
474 ;;
475 python3_*)
476 dis_py3=1
477 ;;
478 esac
479 fi
480 done
481
482 # The eselect solution won't work if the disabled Python version
483 # is installed.
484 if [[ ! ${py2+1} && ${dis_py2} ]]; then
485 debug-print "${FUNCNAME}: -> all py2 versions disabled"
486 if ! has python2_7 "${PYTHON_COMPAT[@]}"; then
487 debug-print "${FUNCNAME}: ---> package does not support 2.7"
488 return 0
489 fi
490 if has_version '=dev-lang/python-2*'; then
491 debug-print "${FUNCNAME}: ---> but =python-2* installed!"
492 return 1
493 fi
494 fi
495 if [[ ! ${py3+1} && ${dis_py3} ]]; then
496 debug-print "${FUNCNAME}: -> all py3 versions disabled"
497 if ! has python3_2 "${PYTHON_COMPAT[@]}"; then
498 debug-print "${FUNCNAME}: ---> package does not support 3.2"
499 return 0
500 fi
501 if has_version '=dev-lang/python-3*'; then
502 debug-print "${FUNCNAME}: ---> but =python-3* installed!"
503 return 1
504 fi
505 fi
506
507 local warned
508
509 # Now check whether the correct implementations are active.
510 if [[ ${py2+1} ]]; then
511 local sel_py2=$(eselect python show --python2)
512
513 debug-print "${FUNCNAME}: -> py2 built: ${py2}, active: ${sel_py2}"
514 if [[ ${py2} != ${sel_py2} ]]; then
515 ewarn "Building package for ${py2} only while ${sel_py2} is active."
516 ewarn "Please consider switching the active Python 2 interpreter:"
517 ewarn
518 ewarn " eselect python set --python2 ${py2}"
519 warned=1
520 fi
521 fi
522
523
524 if [[ ${py3+1} ]]; then
525 local sel_py3=$(eselect python show --python3)
526
527 debug-print "${FUNCNAME}: -> py3 built: ${py3}, active: ${sel_py3}"
528 if [[ ${py3} != ${sel_py3} ]]; then
529 [[ ${warned} ]] && ewarn
530 ewarn "Building package for ${py3} only while ${sel_py3} is active."
531 ewarn "Please consider switching the active Python 3 interpreter:"
532 ewarn
533 ewarn " eselect python set --python3 ${py3}"
534 warned=1
535 fi
536 fi
537
538 if [[ ${warned} ]]; then
539 ewarn
540 ewarn "Please note that after switching the active Python interpreter,"
541 ewarn "you may need to run 'python-updater' to rebuild affected packages."
542 ewarn
543 ewarn "For more information on PYTHON_TARGETS and python.eclass"
544 ewarn "compatibility, please see the relevant Wiki article [1]."
545 ewarn
546 ewarn "[1] https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS"
547 fi
548 }
549
550 # If user has no USE_PYTHON, try to avoid it.
551 if [[ ! ${USE_PYTHON} ]]; then
552 debug-print "${FUNCNAME}: trying eselect solution ..."
553 _try_eselect && return
554 fi
555
556 debug-print "${FUNCNAME}: trying USE_PYTHON solution ..."
557 debug-print "${FUNCNAME}: -> USE_PYTHON=${USE_PYTHON}"
558
559 local impl old=${USE_PYTHON} new=() removed=()
560
561 for impl in "${PYTHON_COMPAT[@]}"; do
562 _python_impl_supported "${impl}" || continue
563
564 local abi
565 case "${impl}" in
566 pypy|python3_4)
567 # unsupported in python.eclass
568 continue
569 ;;
570 python*)
571 abi=${impl#python}
572 ;;
573 jython*)
574 abi=${impl#jython}-jython
575 ;;
576 *)
577 die "Unexpected Python implementation: ${impl}"
578 ;;
579 esac
580 abi=${abi/_/.}
581
582 has "${abi}" ${USE_PYTHON}
583 local has_abi=${?}
584 use "python_targets_${impl}"
585 local has_impl=${?}
586
587 # 0 = has, 1 = does not have
588 if [[ ${has_abi} == 0 && ${has_impl} == 1 ]]; then
589 debug-print "${FUNCNAME}: ---> remove ${abi}"
590 # remove from USE_PYTHON
591 old=${old/${abi}/}
592 removed+=( ${abi} )
593 elif [[ ${has_abi} == 1 && ${has_impl} == 0 ]]; then
594 debug-print "${FUNCNAME}: ---> add ${abi}"
595 # add to USE_PYTHON
596 new+=( ${abi} )
597 fi
598 done
599
600 if [[ ${removed[@]} || ${new[@]} ]]; then
601 old=( ${old} )
602
603 debug-print "${FUNCNAME}: -> old: ${old[@]}"
604 debug-print "${FUNCNAME}: -> new: ${new[@]}"
605 debug-print "${FUNCNAME}: -> removed: ${removed[@]}"
606
607 if [[ ${USE_PYTHON} ]]; then
608 ewarn "It seems that your USE_PYTHON setting lists different Python"
609 ewarn "implementations than your PYTHON_TARGETS variable. Please consider"
610 ewarn "using the following value instead:"
611 ewarn
612 ewarn " USE_PYTHON='\033[35m${old[@]}${new[@]+ \033[1m${new[@]}}\033[0m'"
613
614 if [[ ${removed[@]} ]]; then
615 ewarn
616 ewarn "(removed \033[31m${removed[@]}\033[0m)"
617 fi
618 else
619 ewarn "It seems that you need to set USE_PYTHON to make sure that legacy"
620 ewarn "packages will be built with respect to PYTHON_TARGETS correctly:"
621 ewarn
622 ewarn " USE_PYTHON='\033[35;1m${new[@]}\033[0m'"
623 fi
624
625 ewarn
626 ewarn "Please note that after changing the USE_PYTHON variable, you may need"
627 ewarn "to run 'python-updater' to rebuild affected packages."
628 ewarn
629 ewarn "For more information on PYTHON_TARGETS and python.eclass"
630 ewarn "compatibility, please see the relevant Wiki article [1]."
631 ewarn
632 ewarn "[1] https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS"
633 fi
634 fi
635 }
636
637 # @FUNCTION: _python_obtain_impls
638 # @INTERNAL
639 # @DESCRIPTION:
640 # Set up the enabled implementation list.
641 _python_obtain_impls() {
642 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
643 if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
644 ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
645 ewarn "implementations will be enabled:"
646 ewarn
647 ewarn " ${PYTHON_COMPAT_OVERRIDE}"
648 ewarn
649 ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
650 _PYTHON_COMPAT_OVERRIDE_WARNED=1
651 fi
652
653 MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
654 return
655 fi
656
657 _python_validate_useflags
658 _python_check_USE_PYTHON
659
660 MULTIBUILD_VARIANTS=()
661
662 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
663 if has "${impl}" "${PYTHON_COMPAT[@]}" \
664 && use "python_targets_${impl}"
665 then
666 MULTIBUILD_VARIANTS+=( "${impl}" )
667 fi
668 done
669 }
670
671 # @FUNCTION: _python_multibuild_wrapper
672 # @USAGE: <command> [<args>...]
673 # @INTERNAL
674 # @DESCRIPTION:
675 # Initialize the environment for Python implementation selected
676 # for multibuild.
677 _python_multibuild_wrapper() {
678 debug-print-function ${FUNCNAME} "${@}"
679
680 local -x EPYTHON PYTHON
681 local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
682 python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
683 python_wrapper_setup
684
685 "${@}"
686 }
687
688 # @FUNCTION: python_foreach_impl
689 # @USAGE: <command> [<args>...]
690 # @DESCRIPTION:
691 # Run the given command for each of the enabled Python implementations.
692 # If additional parameters are passed, they will be passed through
693 # to the command.
694 #
695 # The function will return 0 status if all invocations succeed.
696 # Otherwise, the return code from first failing invocation will
697 # be returned.
698 #
699 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
700 # locally, and the former two are exported to the command environment.
701 python_foreach_impl() {
702 debug-print-function ${FUNCNAME} "${@}"
703
704 local MULTIBUILD_VARIANTS
705 _python_obtain_impls
706
707 multibuild_foreach_variant _python_multibuild_wrapper "${@}"
708 }
709
710 # @FUNCTION: python_parallel_foreach_impl
711 # @USAGE: <command> [<args>...]
712 # @DESCRIPTION:
713 # Run the given command for each of the enabled Python implementations.
714 # If additional parameters are passed, they will be passed through
715 # to the command.
716 #
717 # The function will return 0 status if all invocations succeed.
718 # Otherwise, the return code from first failing invocation will
719 # be returned.
720 #
721 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
722 # locally, and the former two are exported to the command environment.
723 #
724 # Multiple invocations of the command will be run in parallel, up to
725 # DISTUTILS_JOBS (defaulting to '-j' option argument from MAKEOPTS).
726 python_parallel_foreach_impl() {
727 debug-print-function ${FUNCNAME} "${@}"
728
729 local MULTIBUILD_JOBS=${MULTIBUILD_JOBS:-${DISTUTILS_JOBS}}
730 local MULTIBUILD_VARIANTS
731 _python_obtain_impls
732 multibuild_parallel_foreach_variant _python_multibuild_wrapper "${@}"
733 }
734
735 # @FUNCTION: python_setup
736 # @DESCRIPTION:
737 # Find the best (most preferred) Python implementation enabled
738 # and set the Python build environment up for it.
739 #
740 # This function needs to be used when Python is being called outside
741 # of python_foreach_impl calls (e.g. for shared processes like doc
742 # building). python_foreach_impl sets up the build environment itself.
743 python_setup() {
744 debug-print-function ${FUNCNAME} "${@}"
745
746 python_export_best
747 python_wrapper_setup
748 }
749
750 # @FUNCTION: python_export_best
751 # @USAGE: [<variable>...]
752 # @DESCRIPTION:
753 # Find the best (most preferred) Python implementation enabled
754 # and export given variables for it. If no variables are provided,
755 # EPYTHON & PYTHON will be exported.
756 python_export_best() {
757 debug-print-function ${FUNCNAME} "${@}"
758
759 [[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
760
761 local best MULTIBUILD_VARIANTS
762 _python_obtain_impls
763
764 _python_set_best() {
765 best=${MULTIBUILD_VARIANT}
766 }
767 multibuild_for_best_variant _python_set_best
768
769 debug-print "${FUNCNAME}: Best implementation is: ${best}"
770 python_export "${best}" "${@}"
771 python_wrapper_setup
772 }
773
774 # @FUNCTION: python_replicate_script
775 # @USAGE: <path>...
776 # @DESCRIPTION:
777 # Copy the given script to variants for all enabled Python
778 # implementations, then replace it with a symlink to the wrapper.
779 #
780 # All specified files must start with a 'python' shebang. A file not
781 # having a matching shebang will be refused.
782 python_replicate_script() {
783 debug-print-function ${FUNCNAME} "${@}"
784
785 _python_replicate_script() {
786 if _python_want_python_exec2; then
787 local PYTHON_SCRIPTDIR
788 python_export PYTHON_SCRIPTDIR
789
790 (
791 exeinto "${PYTHON_SCRIPTDIR#${EPREFIX}}"
792 doexe "${files[@]}"
793 )
794
795 _python_rewrite_shebang "${EPYTHON}" \
796 "${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}"
797 else
798 local f
799 for f in "${files[@]}"; do
800 cp -p "${f}" "${f}-${EPYTHON}" || die
801 done
802
803 _python_rewrite_shebang "${EPYTHON}" \
804 "${files[@]/%/-${EPYTHON}}"
805 fi
806 }
807
808 local files=( "${@}" )
809 python_foreach_impl _python_replicate_script
810
811 # install the wrappers
812 local f
813 for f; do
814 _python_ln_rel "${ED%/}$(_python_get_wrapper_path)" "${f}" || die
815 done
816 }
817
818 _PYTHON_R1=1
819 fi

  ViewVC Help
Powered by ViewVC 1.1.20