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

Contents of /eclass/python-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.53 - (show annotations) (download)
Sun Apr 7 17:02:52 2013 UTC (15 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.52: +4 -1 lines
Create temporary symlinks for executables and pkg-config files, and add them to $PATH and $PKG_CONFIG_PATH respectively. This makes it easier for broken build systems to find Python, and gives us the possibility of dropping python-wrapper.

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

  ViewVC Help
Powered by ViewVC 1.1.20