[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH 1/2] p-d-ng: split out default impl selection logic.
From:       Michał Górny <mgorny () gentoo ! org>
Date:       2012-09-24 21:49:38
Message-ID: 1348523379-16610-1-git-send-email-mgorny () gentoo ! org
[Download RAW message or body]

Move the logic out of doscript() to make it reusable. Also, use
_PYTHON_ALL_IMPLS[@] instead of hardcoding the preference list.
---
 gx86/eclass/python-distutils-ng.eclass | 38 +++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index 33d183c..ab13ffc 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -160,6 +160,29 @@ python-distutils-ng_doscript() {
 	python-distutils-ng_newscript "${1}" "$(basename "${1}")" "${2}"
 }
 
+# Get the preferred implementation for the symlink.
+_python-distutils-ng_get_best_impl() {
+	local defimpl=${PYTHON_DEFAULT_IMPLEMENTATION}
+
+	if [[ ${defimpl} ]]; then
+		if use ${defimpl}; then
+			echo ${defimpl}
+		else
+			die "default implementation ${defimpl} not enabled."
+		fi
+	else
+		local impl
+		for impl in ${_PYTHON_ALL_IMPLS[@]}; do
+			if use python_targets_${impl}; then
+				echo "${impl}"
+				return
+			fi
+		done
+	fi
+
+	die "unable to find a default Python implementation."
+}
+
 # @FUNCTION: python-distutils-ng_newscript
 # @USAGE: script_file_name new_file_name [destination_directory]
 # @DESCRIPTION:
@@ -184,7 +207,7 @@ python-distutils-ng_newscript() {
 	[[ -n "${2}" ]] || die "Missing destination file name"
 	local source_file="${1}"
 	local destination_file="${2}"
-	local default_impl="${PYTHON_DEFAULT_IMPLEMENTATION}"
+	local default_impl=$(_python-distutils-ng_get_best_impl)
 	local enabled_impls=0
 	local destination_directory="/usr/bin"
 	[[ -n "${3}" ]] && destination_directory="${3}"
@@ -194,19 +217,6 @@ python-distutils-ng_newscript() {
 		enabled_impls=$((enabled_impls + 1))
 	done
 
-	if [[ -z "${default_impl}" ]]; then
-		for impl in python{2_7,2_6,2_5,3_2,3_1} pypy{1_9,1_8,1_7} jython2_5; do
-			use "python_targets_${impl}" || continue
-			default_impl="${impl}"
-			break
-		done
-	else
-		use "python_targets_${default_impl}" || \
-			die "default implementation ${default_impl} not enabled"
-	fi
-
-	[[ -n "${default_impl}" ]] || die "Could not select default implementation"
-
 	dodir "${destination_directory}"
 	insinto "${destination_directory}"
 	if [[ "${enabled_impls}" = "1" ]]; then
-- 
1.7.12


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic