Add a function encompassing the common logic to run python_check_deps() from python-any-r1 and python-r1.
Signed-off-by: Michał Górny <mgo...@gentoo.org> --- eclass/python-any-r1.eclass | 32 ++++---------------------------- eclass/python-r1.eclass | 7 +------ eclass/python-utils-r1.eclass | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass index 4c832384ed7a..8d3af399b4be 100644 --- a/eclass/python-any-r1.eclass +++ b/eclass/python-any-r1.eclass @@ -271,31 +271,6 @@ python_gen_any_dep() { echo "|| ( ${out})" } -# @FUNCTION: _python_EPYTHON_supported -# @USAGE: <epython> -# @INTERNAL -# @DESCRIPTION: -# Check whether the specified implementation is supported by package -# (specified in PYTHON_COMPAT). Calls python_check_deps() if declared. -_python_EPYTHON_supported() { - debug-print-function ${FUNCNAME} "${@}" - - local EPYTHON=${1} - local i=${EPYTHON/./_} - - if python_is_installed "${i}"; then - if declare -f python_check_deps >/dev/null; then - local PYTHON_USEDEP="python_targets_${i}(-)" - local PYTHON_SINGLE_USEDEP="python_single_target_${i}(-)" - python_check_deps - return ${?} - fi - - return 0 - fi - return 1 -} - # @FUNCTION: python_setup # @DESCRIPTION: # Determine what the best installed (and supported) Python @@ -330,7 +305,7 @@ python_setup() { einfo "EPYTHON (${EPYTHON}) not supported by the package" elif ! has "${impl}" "${_PYTHON_ALL_IMPLS[@]}"; then ewarn "Invalid EPYTHON: ${EPYTHON}" - elif _python_EPYTHON_supported "${EPYTHON}"; then + elif _python_run_check_deps "${impl}"; then _python_export EPYTHON PYTHON _python_wrapper_setup einfo "Using ${EPYTHON} to build" @@ -341,8 +316,9 @@ python_setup() { # fallback to best installed impl. # (reverse iteration over _PYTHON_SUPPORTED_IMPLS) for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do - _python_export "${_PYTHON_SUPPORTED_IMPLS[i]}" EPYTHON PYTHON - if _python_EPYTHON_supported "${EPYTHON}"; then + local impl=${_PYTHON_SUPPORTED_IMPLS[i]} + _python_export "${impl}" EPYTHON PYTHON + if _python_run_check_deps "${impl}"; then _python_wrapper_setup einfo "Using ${EPYTHON} to build" return diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass index f9a9e9465b40..469c3014abfb 100644 --- a/eclass/python-r1.eclass +++ b/eclass/python-r1.eclass @@ -740,12 +740,7 @@ python_setup() { # if python_check_deps() is declared, switch into any-of mode if [[ ${has_check_deps} ]]; then - # first check if the interpreter is installed - python_is_installed "${impl}" || continue - # then run python_check_deps - local PYTHON_USEDEP="python_targets_${impl}(-)" - local PYTHON_SINGLE_USEDEP="python_single_target_${impl}(-)" - python_check_deps || continue + _python_run_check_deps "${impl}" || continue fi found=1 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index c8367f8065f4..f8c0c00ce919 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -1368,5 +1368,25 @@ eunittest() { return ${?} } +# @FUNCTION: _python_run_check_deps +# @INTERNAL +# @USAGE: <impl> +# @DESCRIPTION: +# Verify whether <impl> is an acceptable choice to run any-r1 style +# code. Checks whether the interpreter is installed, runs +# python_check_deps() if declared. +_python_run_check_deps() { + debug-print-function ${FUNCNAME} "${@}" + + local impl=${1} + + python_is_installed "${impl}" || return 1 + declare -f python_check_deps >/dev/null || return 0 + + local PYTHON_USEDEP="python_targets_${impl}(-)" + local PYTHON_SINGLE_USEDEP="python_single_target_${impl}(-)" + python_check_deps +} + _PYTHON_UTILS_R1=1 fi -- 2.35.1