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

Contents of /eclass/python-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.55 - (hide annotations) (download)
Tue May 21 01:31:02 2013 UTC (5 years, 2 months ago) by floppym
Branch: MAIN
Changes since 1.54: +20 -2 lines
Set PYTHON_REQUIRED_USE, and add it to REQUIRED_USE in distutils-r1.

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

  ViewVC Help
Powered by ViewVC 1.1.20