Gentoo Archives: gentoo-python

From: Mike Gilbert <floppym@g.o>
To: "Michał Górny" <mgorny@g.o>
Cc: gentoo-python@l.g.o, python@g.o
Subject: [gentoo-python] Re: [PATCH] Respect user preferences in python-any-r1 if possible.
Date: Thu, 06 Dec 2012 17:22:10
Message-Id: CAJ0EP43LZa_+H9YehWPuG4yGszUBHq8MNYoLkL9_AAW2BOocEQ@mail.gmail.com
In Reply to: [gentoo-python] [PATCH] Respect user preferences in python-any-r1 if possible. by "Michał Górny"
1 On Sat, Dec 1, 2012 at 5:41 PM, Michał Górny <mgorny@g.o> wrote:
2 > ---
3 > gx86/eclass/python-any-r1.eclass | 55 +++++++++++++++++++++++++++++++++++++++-
4 > 1 file changed, 54 insertions(+), 1 deletion(-)
5 >
6 > diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
7 > index 7f48f20..ca97e14 100644
8 > --- a/gx86/eclass/python-any-r1.eclass
9 > +++ b/gx86/eclass/python-any-r1.eclass
10 > @@ -135,6 +135,36 @@ _python_build_set_globals() {
11 > }
12 > _python_build_set_globals
13 >
14 > +# @FUNCTION: _python_impl_supported
15 > +# @USAGE: <epython>
16 > +# @INTERNAL
17 > +# @DESCRIPTION:
18 > +# Check whether the specified implementation is supported by package
19 > +# (specified in PYTHON_COMPAT).
20 > +_python_impl_supported() {
21 > + debug-print-function ${FUNCNAME} "${@}"
22 > +
23 > + local i=${1/./_}
24 > +
25 > + case "${i}" in
26 > + python*|jython*)
27 > + ;;
28 > + pypy-c*)
29 > + i=${i/-c/}
30 > + ;;
31 > + *)
32 > + ewarn "Invalid EPYTHON: ${EPYTHON}"
33 > + ;;
34 > + esac
35 > +
36 > + if has "${i}" "${PYTHON_COMPAT[@]}"; then
37 > + return 0
38 > + elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
39 > + ewarn "Invalid EPYTHON: ${EPYTHON}"
40 > + fi
41 > + return 1
42 > +}
43 > +
44 > # @FUNCTION: python-any-r1_pkg_setup
45 > # @DESCRIPTION:
46 > # Determine what the best installed (and supported) Python
47 > @@ -142,7 +172,30 @@ _python_build_set_globals
48 > python-any-r1_pkg_setup() {
49 > debug-print-function ${FUNCNAME} "${@}"
50 >
51 > - local i rev_impls=()
52 > + # first, try ${EPYTHON}... maybe it's good enough for us.
53 > + if [[ ${EPYTHON} ]]; then
54 > + if _python_impl_supported "${EPYTHON}"; then
55 > + python_export EPYTHON PYTHON
56 > + return
57 > + fi
58 > + fi
59 > +
60 > + # then, try eselect-python
61 > + local variant i
62 > + for variant in '' '--python2' '--python3'; do
63 > + i=$(eselect python --show ${variant} 2>/dev/null)
64 > +
65 > + if [[ ! ${i} ]]; then
66 > + # no eselect-python?
67 > + break
68 > + elif _python_impl_supported "${i}"; then
69 > + python_export "${i}" EPYTHON PYTHON
70 > + return
71 > + fi
72 > + done
73 > +
74 > + # fallback to best installed impl.
75 > + local rev_impls=()
76 > for i in "${_PYTHON_ALL_IMPLS[@]}"; do
77 > if has "${i}" "${PYTHON_COMPAT[@]}"; then
78 > rev_impls=( "${i}" "${rev_impls[@]}" )
79 > --
80 > 1.8.0
81 >
82
83 Looks ok.