Gentoo Archives: gentoo-python

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

Replies