public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-python@lists.gentoo.org
Cc: python@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-python] [PATCH] Respect user preferences in python-any-r1 if possible.
Date: Sat,  1 Dec 2012 23:41:35 +0100	[thread overview]
Message-ID: <1354401695-14926-1-git-send-email-mgorny@gentoo.org> (raw)

---
 gx86/eclass/python-any-r1.eclass | 55 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
index 7f48f20..ca97e14 100644
--- a/gx86/eclass/python-any-r1.eclass
+++ b/gx86/eclass/python-any-r1.eclass
@@ -135,6 +135,36 @@ _python_build_set_globals() {
 }
 _python_build_set_globals
 
+# @FUNCTION: _python_impl_supported
+# @USAGE: <epython>
+# @INTERNAL
+# @DESCRIPTION:
+# Check whether the specified implementation is supported by package
+# (specified in PYTHON_COMPAT).
+_python_impl_supported() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local i=${1/./_}
+
+	case "${i}" in
+		python*|jython*)
+			;;
+		pypy-c*)
+			i=${i/-c/}
+			;;
+		*)
+			ewarn "Invalid EPYTHON: ${EPYTHON}"
+			;;
+	esac
+
+	if has "${i}" "${PYTHON_COMPAT[@]}"; then
+		return 0
+	elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
+		ewarn "Invalid EPYTHON: ${EPYTHON}"
+	fi
+	return 1
+}
+
 # @FUNCTION: python-any-r1_pkg_setup
 # @DESCRIPTION:
 # Determine what the best installed (and supported) Python
@@ -142,7 +172,30 @@ _python_build_set_globals
 python-any-r1_pkg_setup() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	local i rev_impls=()
+	# first, try ${EPYTHON}... maybe it's good enough for us.
+	if [[ ${EPYTHON} ]]; then
+		if _python_impl_supported "${EPYTHON}"; then
+			python_export EPYTHON PYTHON
+			return
+		fi
+	fi
+
+	# then, try eselect-python
+	local variant i
+	for variant in '' '--python2' '--python3'; do
+		i=$(eselect python --show ${variant} 2>/dev/null)
+
+		if [[ ! ${i} ]]; then
+			# no eselect-python?
+			break
+		elif _python_impl_supported "${i}"; then
+			python_export "${i}" EPYTHON PYTHON
+			return
+		fi
+	done
+
+	# fallback to best installed impl.
+	local rev_impls=()
 	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
 		if has "${i}" "${PYTHON_COMPAT[@]}"; then
 			rev_impls=( "${i}" "${rev_impls[@]}" )
-- 
1.8.0



             reply	other threads:[~2012-12-01 22:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-01 22:41 Michał Górny [this message]
2012-12-06 17:22 ` [gentoo-python] Re: [PATCH] Respect user preferences in python-any-r1 if possible Mike Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354401695-14926-1-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-python@lists.gentoo.org \
    --cc=python@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox