public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: python@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 3/7] python-r1.eclass: Inline implementation loop logic into python_setup
Date: Sat, 20 May 2017 15:30:40 +0200	[thread overview]
Message-ID: <20170520133044.9692-4-mgorny@gentoo.org> (raw)
In-Reply-To: <20170520133044.9692-1-mgorny@gentoo.org>

Inline the logic needed to iterate over implementations directly into
python_setup instead of using python_foreach_impl. This is mostly NFC,
except that we iterate in reverse order now -- that is, we start at
the newest implementation and stop at the first one that works for us.
Previously we (implicitly) started at the oldest implementation, checked
all implementation and used the last one (i.e. the newest) that worked.

More importantly, the new code makes it possible to alter the logic more
easily and avoid relying on implementation of python_foreach_impl().
---
 eclass/python-r1.eclass | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index ae9e3806e729..9c37a20f7c2e 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -597,16 +597,34 @@ python_foreach_impl() {
 python_setup() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	local best_impl patterns=( "${@-*}" )
-	_python_try_impl() {
-		if _python_impl_matches "${EPYTHON}" "${patterns[@]}"; then
-			best_impl=${EPYTHON}
+	_python_validate_useflags
+	local pycompat=( "${PYTHON_COMPAT[@]}" )
+	if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
+		pycompat=( ${PYTHON_COMPAT_OVERRIDE} )
+	fi
+
+	# (reverse iteration -- newest impl first)
+	local found
+	for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
+		local impl=${_PYTHON_SUPPORTED_IMPLS[i]}
+
+		# check PYTHON_COMPAT[_OVERRIDE]
+		has "${impl}" "${pycompat[@]}" || continue
+
+		# match USE flags only if override is not in effect
+		if [[ ! ${PYTHON_COMPAT_OVERRIDE} ]]; then
+			use "python_targets_${impl}" || continue
 		fi
-	}
-	python_foreach_impl _python_try_impl
-	unset -f _python_try_impl
 
-	if [[ ! ${best_impl} ]]; then
+		# check patterns
+		_python_impl_matches "${impl}" "${@-*}" || continue
+
+		python_export "${impl}" EPYTHON PYTHON
+		found=1
+		break
+	done
+
+	if [[ ! ${found} ]]; then
 		eerror "${FUNCNAME}: none of the enabled implementation matched the patterns."
 		eerror "  patterns: ${@-'(*)'}"
 		eerror "Likely a REQUIRED_USE constraint (possibly USE-conditional) is missing."
@@ -615,7 +633,6 @@ python_setup() {
 		die "${FUNCNAME}: no enabled implementation satisfy requirements"
 	fi
 
-	python_export "${best_impl}" EPYTHON PYTHON
 	python_wrapper_setup
 }
 
-- 
2.13.0



  parent reply	other threads:[~2017-05-20 13:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-20 13:30 [gentoo-dev] [PATCHES] python-r1.eclass: any-of dep API support Michał Górny
2017-05-20 13:30 ` [gentoo-dev] [PATCH 1/7] distutils-r1.eclass: Reuse python_setup for common phases Michał Górny
2017-05-20 13:30 ` [gentoo-dev] [PATCH 2/7] python-r1.eclass: Move PYTHON_COMPAT_OVERRIDE warning into flag check Michał Górny
2017-05-20 13:30 ` Michał Górny [this message]
2017-05-20 13:30 ` [gentoo-dev] [PATCH 4/7] python-r1.eclass: Support python_check_deps() in python_setup Michał Górny
2017-05-20 13:30 ` [gentoo-dev] [PATCH 5/7] python-r1.eclass: Add python_gen_any_dep, to create any-of deps Michał Górny
2017-05-20 13:30 ` [gentoo-dev] [PATCH 6/7] app-portage/gentoopm: Use any-of deps (example) Michał Górny
2017-05-20 13:30 ` [gentoo-dev] [PATCH 7/7] dev-python/backports-unittest-mock: Use any-of API for Sphinx (example) Michał Górny
2017-05-21  2:44 ` [gentoo-dev] [PATCHES] python-r1.eclass: any-of dep API support Alex Turbov
2017-05-21  7:30   ` Michał Górny
2017-05-28  3:59 ` Daniel Campbell
2017-06-06  6:59 ` Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170520133044.9692-4-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=python@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox