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

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH] python-r1: introduce PYTHON executable getter.
From:       Michał Górny <mgorny () gentoo ! org>
Date:       2012-09-24 21:11:04
Message-ID: 1348521064-31463-1-git-send-email-mgorny () gentoo ! org
[Download RAW message or body]

A semi-replacement for _python-distutils-ng_very_long_name...

Unlike the forementioned function, it returns just the binary name
and not the complete path. Thus, the executable rewrite in p-d-ng has
been changed to use #!/usr/bin/env.
---
 gx86/eclass/python-distutils-ng.eclass | 28 ++++------------------------
 gx86/eclass/python-r1.eclass           | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index 34717aa..33d183c 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -54,26 +54,6 @@ EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
 
 DEPEND="${DEPEND} !<sys-apps/portage-2.1.10.58"
 
-# @FUNCTION: _python-distutils-ng_get_binary_for_implementation
-# @USAGE: implementation
-# @RETURN: Full path to Python binary for given implementation.
-# @DESCRIPTION:
-# This function returns full path for Python binary for given implementation.
-#
-# Binary returned by this function should be used instead of simply calling
-# `python'.
-_python-distutils-ng_get_binary_for_implementation() {
-	local impl="${1/_/.}"
-	case "${impl}" in
-		python?.?|jython?.?)
-			echo "/usr/bin/${impl}" ;;
-		pypy?.?)
-			echo "/usr/bin/pypy-c${impl: -3}" ;;
-		*)
-			die "Unsupported implementation: ${1}" ;;
-	esac
-}
-
 RDEPEND=${PYTHON_DEPS}
 DEPEND=${PYTHON_DEPS}
 
@@ -90,7 +70,7 @@ _python-distutils-ng_run_for_impl() {
 	local command="${2}"
 
 	local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
-	PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
+	PYTHON="$(python_get_PYTHON "${impl}")"
 	EPYTHON="${impl/_/.}"
 
 	einfo "Running ${command} in ${S} for ${impl}"
@@ -147,10 +127,10 @@ python-distutils-ng_rewrite_hashbang() {
 	[[ -n "${1}" ]] || die "Missing file name"
 	[[ -n "${2}" ]] || die "Missing implementation"
 	local file_name="${1}"
-	local binary="$(_python-distutils-ng_get_binary_for_implementation "${2}")"
+	local binary="$(python_get_PYTHON "${2}")"
 	[[ $(head -n 1 "${file_name}") == '#!'*(python|jython|pypy-c)* ]] || \
 		die "Missing or invalid #! line in ${file_name}"
-	sed -i -e "1c#!${binary}" "${file_name}" || die
+	sed -i -e "1c#!/usr/bin/env ${binary}" "${file_name}" || die
 }
 
 # @FUNCTION: python-distutils-ng_redoscript
@@ -253,7 +233,7 @@ python-distutils-ng_src_prepare() {
 	# Try to run binary for each implementation:
 	for impl in ${PYTHON_COMPAT[@]}; do
 		use "python_targets_${impl}" ${PYTHON_COMPAT[@]} || continue
-		$(_python-distutils-ng_get_binary_for_implementation "${impl}") \
+		$(python_get_PYTHON "${impl}") \
 			-c "import sys" || die
 	done
 
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
index 68b5c38..4c4d69d 100644
--- a/gx86/eclass/python-r1.eclass
+++ b/gx86/eclass/python-r1.eclass
@@ -118,3 +118,23 @@ _python_set_globals() {
 	done
 }
 _python_set_globals
+
+# @FUNCTION: python_get_PYTHON
+# @USAGE: <impl>
+# @DESCRIPTION:
+# Get the Python executable name for the given implementation.
+python_get_PYTHON() {
+	local impl=${1/_/.}
+
+	case "${impl}" in
+		python*|jython*)
+			echo ${impl}
+			;;
+		pypy*)
+			echo pypy-c${impl#pypy}
+			;;
+		*)
+			die "Invalid argument to python_get_PYTHON: ${1}"
+			;;
+	esac
+}
-- 
1.7.12


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

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