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-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-r1.eclass')
-rw-r--r--eclass/python-r1.eclass47
1 files changed, 11 insertions, 36 deletions
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index fbc39dceaa8..f7a8541f9b7 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -82,12 +82,6 @@ inherit multibuild python-utils-r1
# @CODE
# PYTHON_COMPAT=( python2_7 python3_{3,4} )
# @CODE
-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
# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
# @INTERNAL
@@ -186,24 +180,17 @@ fi
# @CODE
_python_set_globals() {
- local impls=()
-
PYTHON_DEPS=
local i PYTHON_PKG_DEP
- for i in "${PYTHON_COMPAT[@]}"; do
- _python_impl_supported "${i}" || continue
+ _python_set_impls
+
+ for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
python_export "${i}" PYTHON_PKG_DEP
PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
-
- impls+=( "${i}" )
done
- if [[ ${#impls[@]} -eq 0 ]]; then
- die "No supported implementation in PYTHON_COMPAT."
- fi
-
- local flags=( "${impls[@]/#/python_targets_}" )
+ local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
local optflags=${flags[@]/%/(-)?}
# A nice QA trick here. Since a python-single-r1 package has to have
@@ -212,7 +199,7 @@ _python_set_globals() {
# it should prevent developers from mistakenly depending on packages
# not supporting multiple Python implementations.
- local flags_st=( "${impls[@]/#/-python_single_target_}" )
+ local flags_st=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/-python_single_target_}" )
optflags+=,${flags_st[@]/%/(-)}
IUSE=${flags[*]}
@@ -246,9 +233,7 @@ _python_validate_useflags() {
local i
- for i in "${PYTHON_COMPAT[@]}"; do
- _python_impl_supported "${i}" || continue
-
+ for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
use "python_targets_${i}" && return 0
done
@@ -290,9 +275,7 @@ python_gen_usedep() {
local impl pattern
local matches=()
- for impl in "${PYTHON_COMPAT[@]}"; do
- _python_impl_supported "${impl}" || continue
-
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
for pattern; do
if [[ ${impl} == ${pattern} ]]; then
matches+=(
@@ -333,9 +316,7 @@ python_gen_useflags() {
local impl pattern
local matches=()
- for impl in "${PYTHON_COMPAT[@]}"; do
- _python_impl_supported "${impl}" || continue
-
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
for pattern; do
if [[ ${impl} == ${pattern} ]]; then
matches+=( "python_targets_${impl}" )
@@ -382,9 +363,7 @@ python_gen_cond_dep() {
local dep=${1}
shift
- for impl in "${PYTHON_COMPAT[@]}"; do
- _python_impl_supported "${impl}" || continue
-
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
for pattern; do
if [[ ${impl} == ${pattern} ]]; then
# substitute ${PYTHON_USEDEP} if used
@@ -460,12 +439,8 @@ _python_obtain_impls() {
MULTIBUILD_VARIANTS=()
- for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
- if has "${impl}" "${PYTHON_COMPAT[@]}" \
- && use "python_targets_${impl}"
- then
- MULTIBUILD_VARIANTS+=( "${impl}" )
- fi
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
+ use "python_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
done
}