public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-python] [PATCH] Respect user preferences in python-any-r1 if possible.
@ 2012-12-01 22:41 Michał Górny
  2012-12-06 17:22 ` [gentoo-python] " Mike Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Górny @ 2012-12-01 22:41 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

---
 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



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

* [gentoo-python] Re: [PATCH] Respect user preferences in python-any-r1 if possible.
  2012-12-01 22:41 [gentoo-python] [PATCH] Respect user preferences in python-any-r1 if possible Michał Górny
@ 2012-12-06 17:22 ` Mike Gilbert
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Gilbert @ 2012-12-06 17:22 UTC (permalink / raw
  To: Michał Górny; +Cc: gentoo-python, python

On Sat, Dec 1, 2012 at 5:41 PM, Michał Górny <mgorny@gentoo.org> wrote:
> ---
>  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
>

Looks ok.


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

end of thread, other threads:[~2012-12-06 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-01 22:41 [gentoo-python] [PATCH] Respect user preferences in python-any-r1 if possible Michał Górny
2012-12-06 17:22 ` [gentoo-python] " Mike Gilbert

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