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

Contents of /eclass/python-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.64 - (show annotations) (download)
Wed Oct 30 19:14:02 2013 UTC (9 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.63: +5 -5 lines
Switch the eclasses to use dev-lang/python-exec.

1 # Copyright 1999-2013 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.63 2013/10/22 15:16:56 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='pypy2_0 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 [[ ${EAPI} != 4 ]]; then
209 PYTHON_DEPS+="dev-lang/python-exec:=[${PYTHON_USEDEP}]"
210 else
211 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
212 fi
213 }
214 _python_set_globals
215
216 # @ECLASS-VARIABLE: DISTUTILS_JOBS
217 # @DEFAULT_UNSET
218 # @DESCRIPTION:
219 # The number of parallel jobs to run for distutils-r1 parallel builds.
220 # If unset, the job-count in ${MAKEOPTS} will be used.
221 #
222 # This variable is intended to be set in make.conf.
223
224 # @FUNCTION: _python_validate_useflags
225 # @INTERNAL
226 # @DESCRIPTION:
227 # Enforce the proper setting of PYTHON_TARGETS.
228 _python_validate_useflags() {
229 debug-print-function ${FUNCNAME} "${@}"
230
231 local i
232
233 for i in "${PYTHON_COMPAT[@]}"; do
234 _python_impl_supported "${i}" || continue
235
236 use "python_targets_${i}" && return 0
237 done
238
239 eerror "No Python implementation selected for the build. Please add one"
240 eerror "of the following values to your PYTHON_TARGETS (in make.conf):"
241 eerror
242 eerror "${PYTHON_COMPAT[@]}"
243 echo
244 die "No supported Python implementation in PYTHON_TARGETS."
245 }
246
247 # @FUNCTION: python_gen_usedep
248 # @USAGE: <pattern> [...]
249 # @DESCRIPTION:
250 # Output a USE dependency string for Python implementations which
251 # are both in PYTHON_COMPAT and match any of the patterns passed
252 # as parameters to the function.
253 #
254 # Remember to escape or quote the patterns to premature evaluation as a file
255 # name glob.
256 #
257 # When all implementations are requested, please use ${PYTHON_USEDEP}
258 # instead. Please also remember to set an appropriate REQUIRED_USE
259 # to avoid ineffective USE flags.
260 #
261 # Example:
262 # @CODE
263 # PYTHON_COMPAT=( python{2_7,3_2} )
264 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
265 # @CODE
266 #
267 # It will cause the dependency to look like:
268 # @CODE
269 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
270 # @CODE
271 python_gen_usedep() {
272 debug-print-function ${FUNCNAME} "${@}"
273
274 local impl pattern
275 local matches=()
276
277 for impl in "${PYTHON_COMPAT[@]}"; do
278 _python_impl_supported "${impl}" || continue
279
280 for pattern; do
281 if [[ ${impl} == ${pattern} ]]; then
282 matches+=(
283 "python_targets_${impl}(-)?"
284 "-python_single_target_${impl}(-)"
285 )
286 break
287 fi
288 done
289 done
290
291 local out=${matches[@]}
292 echo ${out// /,}
293 }
294
295 # @FUNCTION: python_gen_useflags
296 # @USAGE: <pattern> [...]
297 # @DESCRIPTION:
298 # Output a list of USE flags for Python implementations which
299 # are both in PYTHON_COMPAT and match any of the patterns passed
300 # as parameters to the function.
301 #
302 # Example:
303 # @CODE
304 # PYTHON_COMPAT=( python{2_7,3_2} )
305 # REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
306 # @CODE
307 #
308 # It will cause the variable to look like:
309 # @CODE
310 # REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
311 # @CODE
312 python_gen_useflags() {
313 debug-print-function ${FUNCNAME} "${@}"
314
315 local impl pattern
316 local matches=()
317
318 for impl in "${PYTHON_COMPAT[@]}"; do
319 _python_impl_supported "${impl}" || continue
320
321 for pattern; do
322 if [[ ${impl} == ${pattern} ]]; then
323 matches+=( "python_targets_${impl}" )
324 break
325 fi
326 done
327 done
328
329 echo ${matches[@]}
330 }
331
332 # @FUNCTION: python_gen_cond_dep
333 # @USAGE: <dependency> <pattern> [...]
334 # @DESCRIPTION:
335 # Output a list of <dependency>-ies made conditional to USE flags
336 # of Python implementations which are both in PYTHON_COMPAT and match
337 # any of the patterns passed as the remaining parameters.
338 #
339 # Please note that USE constraints on the package need to be enforced
340 # separately. Therefore, the dependency usually needs to use
341 # python_gen_usedep as well.
342 #
343 # Example:
344 # @CODE
345 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
346 # RDEPEND="$(python_gen_cond_dep dev-python/unittest2 python{2_5,2_6})"
347 # @CODE
348 #
349 # It will cause the variable to look like:
350 # @CODE
351 # RDEPEND="python_targets_python2_5? ( dev-python/unittest2 )
352 # python_targets_python2_6? ( dev-python/unittest2 )"
353 # @CODE
354 python_gen_cond_dep() {
355 debug-print-function ${FUNCNAME} "${@}"
356
357 local impl pattern
358 local matches=()
359
360 local dep=${1}
361 shift
362
363 for impl in "${PYTHON_COMPAT[@]}"; do
364 _python_impl_supported "${impl}" || continue
365
366 for pattern; do
367 if [[ ${impl} == ${pattern} ]]; then
368 matches+=( "python_targets_${impl}? ( ${dep} )" )
369 break
370 fi
371 done
372 done
373
374 echo ${matches[@]}
375 }
376
377 # @ECLASS-VARIABLE: BUILD_DIR
378 # @DESCRIPTION:
379 # The current build directory. In global scope, it is supposed to
380 # contain an initial build directory; if unset, it defaults to ${S}.
381 #
382 # In functions run by python_foreach_impl(), the BUILD_DIR is locally
383 # set to an implementation-specific build directory. That path is
384 # created through appending a hyphen and the implementation name
385 # to the final component of the initial BUILD_DIR.
386 #
387 # Example value:
388 # @CODE
389 # ${WORKDIR}/foo-1.3-python2_6
390 # @CODE
391
392 # @FUNCTION: python_copy_sources
393 # @DESCRIPTION:
394 # Create a single copy of the package sources for each enabled Python
395 # implementation.
396 #
397 # The sources are always copied from initial BUILD_DIR (or S if unset)
398 # to implementation-specific build directory matching BUILD_DIR used by
399 # python_foreach_abi().
400 python_copy_sources() {
401 debug-print-function ${FUNCNAME} "${@}"
402
403 local MULTIBUILD_VARIANTS
404 _python_obtain_impls
405
406 multibuild_copy_sources
407 }
408
409 # @FUNCTION: _python_check_USE_PYTHON
410 # @INTERNAL
411 # @DESCRIPTION:
412 # Check whether USE_PYTHON and PYTHON_TARGETS are in sync. Output
413 # warnings if they are not.
414 _python_check_USE_PYTHON() {
415 debug-print-function ${FUNCNAME} "${@}"
416
417 if [[ ! ${_PYTHON_USE_PYTHON_CHECKED} ]]; then
418 _PYTHON_USE_PYTHON_CHECKED=1
419
420 # python-exec has profile-forced flags.
421 if [[ ${CATEGORY}/${PN} == dev-lang/python-exec ]]; then
422 return
423 fi
424
425 _try_eselect() {
426 # The eselect solution will work only with one py2 & py3.
427
428 local impl py2 py3 dis_py2 dis_py3
429 for impl in "${PYTHON_COMPAT[@]}"; do
430 _python_impl_supported "${impl}" || continue
431
432 if use "python_targets_${impl}"; then
433 case "${impl}" in
434 python2_*)
435 if [[ ${py2+1} ]]; then
436 debug-print "${FUNCNAME}: -> more than one py2: ${py2} ${impl}"
437 return 1
438 fi
439 py2=${impl/_/.}
440 ;;
441 python3_*)
442 if [[ ${py3+1} ]]; then
443 debug-print "${FUNCNAME}: -> more than one py3: ${py3} ${impl}"
444 return 1
445 fi
446 py3=${impl/_/.}
447 ;;
448 *)
449 return 1
450 ;;
451 esac
452 else
453 case "${impl}" in
454 python2_*)
455 dis_py2=1
456 ;;
457 python3_*)
458 dis_py3=1
459 ;;
460 esac
461 fi
462 done
463
464 # The eselect solution won't work if the disabled Python version
465 # is installed.
466 if [[ ! ${py2+1} && ${dis_py2} ]]; then
467 debug-print "${FUNCNAME}: -> all py2 versions disabled"
468 if ! has python2_7 "${PYTHON_COMPAT[@]}"; then
469 debug-print "${FUNCNAME}: ---> package does not support 2.7"
470 return 0
471 fi
472 if has_version '=dev-lang/python-2*'; then
473 debug-print "${FUNCNAME}: ---> but =python-2* installed!"
474 return 1
475 fi
476 fi
477 if [[ ! ${py3+1} && ${dis_py3} ]]; then
478 debug-print "${FUNCNAME}: -> all py3 versions disabled"
479 if ! has python3_2 "${PYTHON_COMPAT[@]}"; then
480 debug-print "${FUNCNAME}: ---> package does not support 3.2"
481 return 0
482 fi
483 if has_version '=dev-lang/python-3*'; then
484 debug-print "${FUNCNAME}: ---> but =python-3* installed!"
485 return 1
486 fi
487 fi
488
489 local warned
490
491 # Now check whether the correct implementations are active.
492 if [[ ${py2+1} ]]; then
493 local sel_py2=$(eselect python show --python2)
494
495 debug-print "${FUNCNAME}: -> py2 built: ${py2}, active: ${sel_py2}"
496 if [[ ${py2} != ${sel_py2} ]]; then
497 ewarn "Building package for ${py2} only while ${sel_py2} is active."
498 ewarn "Please consider switching the active Python 2 interpreter:"
499 ewarn
500 ewarn " eselect python set --python2 ${py2}"
501 warned=1
502 fi
503 fi
504
505 if [[ ${py3+1} ]]; then
506 local sel_py3=$(eselect python show --python3)
507
508 debug-print "${FUNCNAME}: -> py3 built: ${py3}, active: ${sel_py3}"
509 if [[ ${py3} != ${sel_py3} ]]; then
510 [[ ${warned} ]] && ewarn
511 ewarn "Building package for ${py3} only while ${sel_py3} is active."
512 ewarn "Please consider switching the active Python 3 interpreter:"
513 ewarn
514 ewarn " eselect python set --python3 ${py3}"
515 warned=1
516 fi
517 fi
518
519 if [[ ${warned} ]]; then
520 ewarn
521 ewarn "Please note that after switching the active Python interpreter,"
522 ewarn "you may need to run 'python-updater' to rebuild affected packages."
523 ewarn
524 ewarn "For more information on python.eclass compatibility, please see"
525 ewarn "the appropriate python-r1 User's Guide chapter [1]."
526 ewarn
527 ewarn "[1] http://www.gentoo.org/proj/en/Python/python-r1/user-guide.xml#doc_chap2"
528 fi
529 }
530
531 # If user has no USE_PYTHON, try to avoid it.
532 if [[ ! ${USE_PYTHON} ]]; then
533 debug-print "${FUNCNAME}: trying eselect solution ..."
534 _try_eselect && return
535 fi
536
537 debug-print "${FUNCNAME}: trying USE_PYTHON solution ..."
538 debug-print "${FUNCNAME}: -> USE_PYTHON=${USE_PYTHON}"
539
540 local impl old=${USE_PYTHON} new=() removed=()
541
542 for impl in "${PYTHON_COMPAT[@]}"; do
543 _python_impl_supported "${impl}" || continue
544
545 local abi
546 case "${impl}" in
547 python*)
548 abi=${impl#python}
549 ;;
550 jython*)
551 abi=${impl#jython}-jython
552 ;;
553 pypy*)
554 abi=2.7-pypy-${impl#pypy}
555 ;;
556 *)
557 die "Unexpected Python implementation: ${impl}"
558 ;;
559 esac
560 abi=${abi/_/.}
561
562 has "${abi}" ${USE_PYTHON}
563 local has_abi=${?}
564 use "python_targets_${impl}"
565 local has_impl=${?}
566
567 # 0 = has, 1 = does not have
568 if [[ ${has_abi} == 0 && ${has_impl} == 1 ]]; then
569 debug-print "${FUNCNAME}: ---> remove ${abi}"
570 # remove from USE_PYTHON
571 old=${old/${abi}/}
572 removed+=( ${abi} )
573 elif [[ ${has_abi} == 1 && ${has_impl} == 0 ]]; then
574 debug-print "${FUNCNAME}: ---> add ${abi}"
575 # add to USE_PYTHON
576 new+=( ${abi} )
577 fi
578 done
579
580 if [[ ${removed[@]} || ${new[@]} ]]; then
581 old=( ${old} )
582
583 debug-print "${FUNCNAME}: -> old: ${old[@]}"
584 debug-print "${FUNCNAME}: -> new: ${new[@]}"
585 debug-print "${FUNCNAME}: -> removed: ${removed[@]}"
586
587 if [[ ${USE_PYTHON} ]]; then
588 ewarn "It seems that your USE_PYTHON setting lists different Python"
589 ewarn "implementations than your PYTHON_TARGETS variable. Please consider"
590 ewarn "using the following value instead:"
591 ewarn
592 ewarn " USE_PYTHON='\033[35m${old[@]}${new[@]+ \033[1m${new[@]}}\033[0m'"
593
594 if [[ ${removed[@]} ]]; then
595 ewarn
596 ewarn "(removed \033[31m${removed[@]}\033[0m)"
597 fi
598 else
599 ewarn "It seems that you need to set USE_PYTHON to make sure that legacy"
600 ewarn "packages will be built with respect to PYTHON_TARGETS correctly:"
601 ewarn
602 ewarn " USE_PYTHON='\033[35;1m${new[@]}\033[0m'"
603 fi
604
605 ewarn
606 ewarn "Please note that after changing the USE_PYTHON variable, you may need"
607 ewarn "to run 'python-updater' to rebuild affected packages."
608 ewarn
609 ewarn "For more information on python.eclass compatibility, please see"
610 ewarn "the appropriate python-r1 User's Guide chapter [1]."
611 ewarn
612 ewarn "[1] http://www.gentoo.org/proj/en/Python/python-r1/user-guide.xml#doc_chap2"
613 fi
614 fi
615 }
616
617 # @FUNCTION: _python_obtain_impls
618 # @INTERNAL
619 # @DESCRIPTION:
620 # Set up the enabled implementation list.
621 _python_obtain_impls() {
622 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
623 if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
624 ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
625 ewarn "implementations will be enabled:"
626 ewarn
627 ewarn " ${PYTHON_COMPAT_OVERRIDE}"
628 ewarn
629 ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
630 _PYTHON_COMPAT_OVERRIDE_WARNED=1
631 fi
632
633 MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
634 return
635 fi
636
637 _python_validate_useflags
638 _python_check_USE_PYTHON
639
640 MULTIBUILD_VARIANTS=()
641
642 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
643 if has "${impl}" "${PYTHON_COMPAT[@]}" \
644 && use "python_targets_${impl}"
645 then
646 MULTIBUILD_VARIANTS+=( "${impl}" )
647 fi
648 done
649 }
650
651 # @FUNCTION: _python_multibuild_wrapper
652 # @USAGE: <command> [<args>...]
653 # @INTERNAL
654 # @DESCRIPTION:
655 # Initialize the environment for Python implementation selected
656 # for multibuild.
657 _python_multibuild_wrapper() {
658 debug-print-function ${FUNCNAME} "${@}"
659
660 local -x EPYTHON PYTHON
661 local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
662 python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
663 python_wrapper_setup
664
665 "${@}"
666 }
667
668 # @FUNCTION: python_foreach_impl
669 # @USAGE: <command> [<args>...]
670 # @DESCRIPTION:
671 # Run the given command for each of the enabled Python implementations.
672 # If additional parameters are passed, they will be passed through
673 # to the command.
674 #
675 # The function will return 0 status if all invocations succeed.
676 # Otherwise, the return code from first failing invocation will
677 # be returned.
678 #
679 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
680 # locally, and the former two are exported to the command environment.
681 python_foreach_impl() {
682 debug-print-function ${FUNCNAME} "${@}"
683
684 local MULTIBUILD_VARIANTS
685 _python_obtain_impls
686
687 multibuild_foreach_variant _python_multibuild_wrapper "${@}"
688 }
689
690 # @FUNCTION: python_parallel_foreach_impl
691 # @USAGE: <command> [<args>...]
692 # @DESCRIPTION:
693 # Run the given command for each of the enabled Python implementations.
694 # If additional parameters are passed, they will be passed through
695 # to the command.
696 #
697 # The function will return 0 status if all invocations succeed.
698 # Otherwise, the return code from first failing invocation will
699 # be returned.
700 #
701 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
702 # locally, and the former two are exported to the command environment.
703 #
704 # Multiple invocations of the command will be run in parallel, up to
705 # DISTUTILS_JOBS (defaulting to '-j' option argument from MAKEOPTS).
706 python_parallel_foreach_impl() {
707 debug-print-function ${FUNCNAME} "${@}"
708
709 local MULTIBUILD_JOBS=${MULTIBUILD_JOBS:-${DISTUTILS_JOBS}}
710 local MULTIBUILD_VARIANTS
711 _python_obtain_impls
712 multibuild_parallel_foreach_variant _python_multibuild_wrapper "${@}"
713 }
714
715 # @FUNCTION: python_setup
716 # @DESCRIPTION:
717 # Find the best (most preferred) Python implementation enabled
718 # and set the Python build environment up for it.
719 #
720 # This function needs to be used when Python is being called outside
721 # of python_foreach_impl calls (e.g. for shared processes like doc
722 # building). python_foreach_impl sets up the build environment itself.
723 python_setup() {
724 debug-print-function ${FUNCNAME} "${@}"
725
726 python_export_best
727 python_wrapper_setup
728 }
729
730 # @FUNCTION: python_export_best
731 # @USAGE: [<variable>...]
732 # @DESCRIPTION:
733 # Find the best (most preferred) Python implementation enabled
734 # and export given variables for it. If no variables are provided,
735 # EPYTHON & PYTHON will be exported.
736 python_export_best() {
737 debug-print-function ${FUNCNAME} "${@}"
738
739 [[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
740
741 local best MULTIBUILD_VARIANTS
742 _python_obtain_impls
743
744 _python_set_best() {
745 best=${MULTIBUILD_VARIANT}
746 }
747 multibuild_for_best_variant _python_set_best
748
749 debug-print "${FUNCNAME}: Best implementation is: ${best}"
750 python_export "${best}" "${@}"
751 python_wrapper_setup
752 }
753
754 # @FUNCTION: python_replicate_script
755 # @USAGE: <path>...
756 # @DESCRIPTION:
757 # Copy the given script to variants for all enabled Python
758 # implementations, then replace it with a symlink to the wrapper.
759 #
760 # All specified files must start with a 'python' shebang. A file not
761 # having a matching shebang will be refused.
762 python_replicate_script() {
763 debug-print-function ${FUNCNAME} "${@}"
764
765 _python_replicate_script() {
766 if _python_want_python_exec2; then
767 local PYTHON_SCRIPTDIR
768 python_export PYTHON_SCRIPTDIR
769
770 (
771 exeinto "${PYTHON_SCRIPTDIR#${EPREFIX}}"
772 doexe "${files[@]}"
773 )
774
775 _python_rewrite_shebang "${EPYTHON}" \
776 "${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}"
777 else
778 local f
779 for f in "${files[@]}"; do
780 cp -p "${f}" "${f}-${EPYTHON}" || die
781 done
782
783 _python_rewrite_shebang "${EPYTHON}" \
784 "${files[@]/%/-${EPYTHON}}"
785 fi
786 }
787
788 local files=( "${@}" )
789 python_foreach_impl _python_replicate_script
790
791 # install the wrappers
792 local f
793 for f; do
794 _python_ln_rel "${ED%/}$(_python_get_wrapper_path)" "${f}" || die
795 done
796 }
797
798 _PYTHON_R1=1
799 fi

  ViewVC Help
Powered by ViewVC 1.1.20