Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/2] p-d-ng: split out default impl selection logic.
Date: Mon, 24 Sep 2012 21:51:18
Message-Id: 1348523379-16610-1-git-send-email-mgorny@gentoo.org
1 Move the logic out of doscript() to make it reusable. Also, use
2 _PYTHON_ALL_IMPLS[@] instead of hardcoding the preference list.
3 ---
4 gx86/eclass/python-distutils-ng.eclass | 38 +++++++++++++++++++++-------------
5 1 file changed, 24 insertions(+), 14 deletions(-)
6
7 diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
8 index 33d183c..ab13ffc 100644
9 --- a/gx86/eclass/python-distutils-ng.eclass
10 +++ b/gx86/eclass/python-distutils-ng.eclass
11 @@ -160,6 +160,29 @@ python-distutils-ng_doscript() {
12 python-distutils-ng_newscript "${1}" "$(basename "${1}")" "${2}"
13 }
14
15 +# Get the preferred implementation for the symlink.
16 +_python-distutils-ng_get_best_impl() {
17 + local defimpl=${PYTHON_DEFAULT_IMPLEMENTATION}
18 +
19 + if [[ ${defimpl} ]]; then
20 + if use ${defimpl}; then
21 + echo ${defimpl}
22 + else
23 + die "default implementation ${defimpl} not enabled."
24 + fi
25 + else
26 + local impl
27 + for impl in ${_PYTHON_ALL_IMPLS[@]}; do
28 + if use python_targets_${impl}; then
29 + echo "${impl}"
30 + return
31 + fi
32 + done
33 + fi
34 +
35 + die "unable to find a default Python implementation."
36 +}
37 +
38 # @FUNCTION: python-distutils-ng_newscript
39 # @USAGE: script_file_name new_file_name [destination_directory]
40 # @DESCRIPTION:
41 @@ -184,7 +207,7 @@ python-distutils-ng_newscript() {
42 [[ -n "${2}" ]] || die "Missing destination file name"
43 local source_file="${1}"
44 local destination_file="${2}"
45 - local default_impl="${PYTHON_DEFAULT_IMPLEMENTATION}"
46 + local default_impl=$(_python-distutils-ng_get_best_impl)
47 local enabled_impls=0
48 local destination_directory="/usr/bin"
49 [[ -n "${3}" ]] && destination_directory="${3}"
50 @@ -194,19 +217,6 @@ python-distutils-ng_newscript() {
51 enabled_impls=$((enabled_impls + 1))
52 done
53
54 - if [[ -z "${default_impl}" ]]; then
55 - for impl in python{2_7,2_6,2_5,3_2,3_1} pypy{1_9,1_8,1_7} jython2_5; do
56 - use "python_targets_${impl}" || continue
57 - default_impl="${impl}"
58 - break
59 - done
60 - else
61 - use "python_targets_${default_impl}" || \
62 - die "default implementation ${default_impl} not enabled"
63 - fi
64 -
65 - [[ -n "${default_impl}" ]] || die "Could not select default implementation"
66 -
67 dodir "${destination_directory}"
68 insinto "${destination_directory}"
69 if [[ "${enabled_impls}" = "1" ]]; then
70 --
71 1.7.12

Replies