This function can be used to obtain PYTHON & EPYTHON variables for any
Python implementation supported.
---
 gx86/eclass/distutils-r1.eclass |  2 +-
 gx86/eclass/python-r1.eclass    | 85 +++++++++++++++++++++++++++--------------
 2 files changed, 57 insertions(+), 30 deletions(-)

diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
index 1b734b2..4370b4f 100644
--- a/gx86/eclass/distutils-r1.eclass
+++ b/gx86/eclass/distutils-r1.eclass
@@ -256,7 +256,7 @@ distutils-r1_python_install_all() {
        local impl EPYTHON PYTHON
        for impl in "${PYTHON_COMPAT[@]}"; do
                if use "python_targets_${impl}"; then
-                       _python_set_PYTHON "${impl}"
+                       python_export "${impl}" EPYTHON
                        break
                fi
        done
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
index 89fc0e7..5ca51f6 100644
--- a/gx86/eclass/python-r1.eclass
+++ b/gx86/eclass/python-r1.eclass
@@ -154,34 +154,6 @@ _python_set_globals() {
 }
 _python_set_globals
 
-# @FUNCTION: _python_set_PYTHON
-# @USAGE: <impl>
-# @INTERNAL
-# @DESCRIPTION:
-# Get the Python executable name for the given implementation and set it
-# as ${PYTHON} & ${EPYTHON}. Please note that EPYTHON will contain
-# the 'basename' while PYTHON will contain the full path.
-_python_set_PYTHON() {
-       debug-print-function ${FUNCNAME} "${@}"
-
-       local impl=${1/_/.}
-
-       case "${impl}" in
-               python*|jython*)
-                       EPYTHON=${impl}
-                       ;;
-               pypy*)
-                       EPYTHON=pypy-c${impl#pypy}
-                       ;;
-               *)
-                       die "Invalid argument to _python_set_PYTHON: ${1}"
-                       ;;
-       esac
-       PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
-
-       debug-print "${FUNCNAME}: ${impl} -> ${PYTHON}"
-}
-
 # @ECLASS-VARIABLE: BUILD_DIR
 # @DESCRIPTION:
 # The current build directory. In global scope, it is supposed to
@@ -221,6 +193,61 @@ _python_set_PYTHON() {
 # python2.6
 # @CODE
 
+# @FUNCTION: python_export
+# @USAGE: [<impl>] <variables>...
+# @DESCRIPTION:
+# Set and export the Python implementation-relevant variables passed
+# as parameters.
+#
+# The optional first parameter may specify the requested Python
+# implementation (either as PYTHON_TARGETS value, e.g. python2_7,
+# or an EPYTHON one, e.g. python2.7). If no implementation passed,
+# the current one will be obtained from ${EPYTHON}.
+#
+# The variables which can be exported are: PYTHON, EPYTHON. They are
+# described more completely in the eclass variable documentation.
+python_export() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       local impl var
+
+       case "${1}" in
+               python*|jython*)
+                       impl=${1/_/.}
+                       shift
+                       ;;
+               pypy-c*)
+                       impl=${1}
+                       shift
+                       ;;
+               pypy*)
+                       local v=${1#pypy}
+                       impl=pypy-c${v/_/.}
+                       shift
+                       ;;
+               *)
+                       impl=${EPYTHON}
+                       [[ ${impl} ]] || die "python_export: no impl nor 
EPYTHON"
+                       ;;
+       esac
+       debug-print "${FUNCNAME}: implementation: ${impl}"
+
+       for var; do
+               case "${var}" in
+                       EPYTHON)
+                               export EPYTHON=${impl}
+                               debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
+                               ;;
+                       PYTHON)
+                               export PYTHON=${EPREFIX}/usr/bin/${impl}
+                               debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
+                               ;;
+                       *)
+                               die "python_export: unknown variable ${var}"
+               esac
+       done
+}
+
 # @FUNCTION: python_copy_sources
 # @DESCRIPTION:
 # Create a single copy of the package sources (${S}) for each enabled
@@ -275,7 +302,7 @@ python_foreach_impl() {
                if has "${impl}" "${PYTHON_COMPAT[@]}" && use 
"python_targets_${impl}"
                then
                        local EPYTHON PYTHON
-                       _python_set_PYTHON "${impl}"
+                       python_export "${impl}" EPYTHON PYTHON
                        local BUILD_DIR=${bdir%%/}-${impl}
                        export EPYTHON PYTHON
 
-- 
1.7.12.4


Reply via email to