summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-12-12 23:06:33 +0100
committerMichał Górny <mgorny@gentoo.org>2015-12-22 23:12:23 +0100
commit33380ad5e121a47375442de08fd9239b9102b1fa (patch)
tree1acd1d623815425130f5a8a6cb44dbd9a6471d27 /eclass/python-utils-r1.eclass
parentdev-python/flask-socketio: add pypy and pypy3 to PYTHON_COMPAT (diff)
downloadgentoo-33380ad5e121a47375442de08fd9239b9102b1fa.tar.gz
gentoo-33380ad5e121a47375442de08fd9239b9102b1fa.tar.bz2
gentoo-33380ad5e121a47375442de08fd9239b9102b1fa.zip
python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result
Introduce a common _python_set_impls function in python-utils-r1.eclass that validates and processes PYTHON_COMPAT, then stores the result in _PYTHON_SUPPORTED_IMPLS and _PYTHON_UNSUPPORTED_IMPLS variables. Reuse those variables in all python-r1 suite eclasses, effectively reducing code duplication and providing cache for repeated implementation support checks.
Diffstat (limited to 'eclass/python-utils-r1.eclass')
-rw-r--r--eclass/python-utils-r1.eclass49
1 files changed, 49 insertions, 0 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 7830323abc0..89a7cbf2a18 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -84,6 +84,55 @@ _python_impl_supported() {
esac
}
+# @FUNCTION: _python_set_impls
+# @INTERNAL
+# @DESCRIPTION:
+# Check PYTHON_COMPAT for well-formedness and validity, then set
+# two global variables:
+#
+# - _PYTHON_SUPPORTED_IMPLS containing valid implementations supported
+# by the ebuild (PYTHON_COMPAT - dead implementations),
+#
+# - and _PYTHON_UNSUPPORTED_IMPLS containing valid implementations that
+# are not supported by the ebuild.
+#
+# Implementations in both variables are ordered using the pre-defined
+# eclass implementation ordering.
+#
+# This function must be called once in global scope by an eclass
+# utilizing PYTHON_COMPAT.
+_python_set_impls() {
+ local i
+
+ if ! declare -p PYTHON_COMPAT &>/dev/null; then
+ die 'PYTHON_COMPAT not declared.'
+ fi
+ if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
+ die 'PYTHON_COMPAT must be an array.'
+ fi
+ for i in "${PYTHON_COMPAT[@]}"; do
+ # trigger validity checks
+ _python_impl_supported "${i}"
+ done
+
+ _PYTHON_SUPPORTED_IMPLS=()
+ _PYTHON_UNSUPPORTED_IMPLS=()
+
+ for i in "${_PYTHON_ALL_IMPLS[@]}"; do
+ if has "${i}" "${PYTHON_COMPAT[@]}"; then
+ _PYTHON_SUPPORTED_IMPLS+=( "${i}" )
+ else
+ _PYTHON_UNSUPPORTED_IMPLS+=( "${i}" )
+ fi
+ done
+
+ if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 0 ]]; then
+ die "No supported implementation in PYTHON_COMPAT."
+ fi
+
+ readonly _PYTHON_SUPPORTED_IMPLS _PYTHON_UNSUPPORTED_IMPLS
+}
+
# @ECLASS-VARIABLE: PYTHON
# @DEFAULT_UNSET
# @DESCRIPTION: