public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/2] p-d-ng: split out default impl selection logic.
@ 2012-09-24 21:49 Michał Górny
  2012-09-24 21:49 ` [gentoo-dev] [PATCH 2/2] p-d-ng: use distutils-made scripts instead of 'redoing' them Michał Górny
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Górny @ 2012-09-24 21:49 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-dev] [PATCH 2/2] p-d-ng: use distutils-made scripts instead of 'redoing' them.
  2012-09-24 21:49 [gentoo-dev] [PATCH 1/2] p-d-ng: split out default impl selection logic Michał Górny
@ 2012-09-24 21:49 ` Michał Górny
  0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2012-09-24 21:49 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Instead of 'redoing' the installed script, just rename the ones
installed by distutils in each phase.

This also changes suffixes from -pythonX_Y to -pythonX.Y for no good
reason.
---
 gx86/eclass/python-distutils-ng.eclass | 39 +++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index ab13ffc..b478277 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -292,25 +292,48 @@ python-distutils-ng_src_test() {
 	fi
 }
 
-# Phase function: src_install
-python-distutils-ng_src_install() {
+# A wrapper necessary to 'redo' scripts.
+_python-distutils-ng_install_wrapper() {
 	if type python_install &> /dev/null; then
-		_python-distutils-ng_run_for_each_impl python_install
+		python_install "${@}"
 	else
-		_python-distutils-ng_run_for_each_impl \
-			_python-distutils-ng_default_distutils_install
+		_python-distutils-ng_default_distutils_install "${@}"
 	fi
 
+	if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
+		local f
+		# XXX: change this if we ever allow directories in bin/sbin
+		for f in "${D}"/{,usr/}{,s}bin/*; do
+			if [[ -x ${f} ]]; then
+				if [[ "$(head -n 1 "${f}")" == '#!'*${PYTHON}* ]]
+				then
+					mv "${f}" "${f}"-${EPYTHON} || die
+				fi
+			fi
+		done
+	fi
+}
+
+# Phase function: src_install
+python-distutils-ng_src_install() {
+	_python-distutils-ng_run_for_each_impl \
+		_python-distutils-ng_install_wrapper
+
 	if type python_install_all &> /dev/null; then
 		einfo "Running python_install_all in ${S} for all"
 		pushd "${S}" &> /dev/null
 		python_install_all
 		popd &> /dev/null
 	fi
-
 	if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
-		for script_file in $(find "${D}"{,usr/}{,s}bin/ -type f -executable 2> /dev/null); do
-			python-distutils-ng_redoscript "/${script_file#${D}}"
+		local best_impl=$(_python-distutils-ng_get_best_impl)
+		local f
+
+		# XXX: change this if we ever allow directories in bin/sbin
+		for f in "${D}"/{,usr/}{,s}bin/*-${best_impl/_/.}; do
+			if [[ -x ${f} ]]; then
+				ln -s "${f##*/}" "${f%-*}" || die
+			fi
 		done
 	fi
 }
-- 
1.7.12



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-24 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-24 21:49 [gentoo-dev] [PATCH 1/2] p-d-ng: split out default impl selection logic Michał Górny
2012-09-24 21:49 ` [gentoo-dev] [PATCH 2/2] p-d-ng: use distutils-made scripts instead of 'redoing' them Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox