python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE
authorMichał Górny <mgorny@gentoo.org>
Sat, 12 Dec 2015 22:20:26 +0000 (23:20 +0100)
committerMichał Górny <mgorny@gentoo.org>
Tue, 22 Dec 2015 22:12:23 +0000 (23:12 +0100)
eclass/python-any-r1.eclass

index dbfededa10fc5d3d9ad8c59f11ddd9c8c18b4acd..99aac739b30288599925be7c868026611d03bf78 100644 (file)
@@ -72,6 +72,24 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
 # @CODE
 
+# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
+# @INTERNAL
+# @DESCRIPTION:
+# This variable can be used when working with ebuilds to override
+# the in-ebuild PYTHON_COMPAT. It is a string naming the implementation
+# which will be used to build the package. It needs to be specified
+# in the calling environment, and not in ebuilds.
+#
+# It should be noted that in order to preserve metadata immutability,
+# PYTHON_COMPAT_OVERRIDE does not affect dependencies. The value of
+# EPYTHON and eselect-python preferences are ignored. Dependencies need
+# to be satisfied manually.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar
+# @CODE
+
 # @ECLASS-VARIABLE: PYTHON_REQ_USE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -253,6 +271,23 @@ _python_EPYTHON_supported() {
 python_setup() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       # support developer override
+       if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
+               local impls=( ${PYTHON_COMPAT_OVERRIDE} )
+               [[ ${#impls[@]} -eq 1 ]] || die "PYTHON_COMPAT_OVERRIDE must name exactly one implementation for python-any-r1"
+
+               ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
+               ewarn "implementation will be used:"
+               ewarn
+               ewarn " ${PYTHON_COMPAT_OVERRIDE}"
+               ewarn
+               ewarn "Dependencies won't be satisfied, and EPYTHON/eselect-python will be ignored."
+
+               python_export "${impls[0]}" EPYTHON PYTHON
+               python_wrapper_setup
+               return
+       fi
+
        # first, try ${EPYTHON}... maybe it's good enough for us.
        if [[ ${EPYTHON} ]]; then
                if _python_EPYTHON_supported "${EPYTHON}"; then