From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 37022158087 for ; Sun, 6 Feb 2022 12:51:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7C07F2BC0C0; Sun, 6 Feb 2022 12:48:57 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 187092BC0B0 for ; Sun, 6 Feb 2022 12:48:55 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 07/30] python-utils-r1.eclass: Add function to run python_check_deps() Date: Sun, 6 Feb 2022 13:48:18 +0100 Message-Id: <20220206124841.1299133-8-mgorny@gentoo.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220206124841.1299133-1-mgorny@gentoo.org> References: <20220206124841.1299133-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 4b8c710f-ddf4-48cc-a3ae-9623b3e64d45 X-Archives-Hash: a2e7977cfbc4066746276e97d1f74d1d 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 --- 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: -# @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: +# @DESCRIPTION: +# Verify whether 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