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 4/7] python-r1.eclass: Support python_check_deps() in python_setup
Date: Sat, 20 May 2017 15:30:41 +0200	[thread overview]
Message-ID: <20170520133044.9692-5-mgorny@gentoo.org> (raw)
In-Reply-To: <20170520133044.9692-1-mgorny@gentoo.org>

Provide an alternate mode for python_setup() that behaves similarly to
python-any-r1 eclass. If python_check_deps() function is declared
by the ebuild, the python_setup logic switches to accepting any
implementation that is in PYTHON_COMPAT, installed and satisfies
python_check_deps() independently of USE flags.

This new logic makes it possible to replace some of the existing
REQUIRED_USE constraints for build-time dependencies with more friendly
any-of dependencies. For example, if a package supports both Python 2 &
Python 3 but has a purely Python 2 build-time dependency (e.g. for
building documentation) we had to force Python 2 being enabled via
REQUIRED_USE. Using python_check_deps() with appropriate any-of
dependency, we can use Python 2 for this task without actually forcing
the user to change USE flags or install the package for Python 2.
---
 eclass/python-r1.eclass | 48 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index 9c37a20f7c2e..2992f603cf8a 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -231,7 +231,7 @@ _python_set_globals() {
 		PYTHON_DEPS=${deps}
 		PYTHON_REQUIRED_USE=${requse}
 		PYTHON_USEDEP=${usedep}
-		readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP
+		readonly PYTHON_DEPS PYTHON_REQUIRED_USE
 	fi
 }
 _python_set_globals
@@ -563,9 +563,27 @@ python_foreach_impl() {
 # @FUNCTION: python_setup
 # @USAGE: [<impl-pattern>...]
 # @DESCRIPTION:
-# Find the best (most preferred) Python implementation that is enabled
-# and matches at least one of the patterns passed (or '*' if no patterns
-# passed). Set the Python build environment up for that implementation.
+# Find the best (most preferred) Python implementation that is suitable
+# for running common Python code. Set the Python build environment up
+# for that implementation. This function has two modes of operation:
+# pure and any-of dep.
+#
+# The pure mode is used if python_check_deps() function is not declared.
+# In this case, an implementation is considered suitable if it is
+# supported (in PYTHON_COMPAT), enabled (via USE flags) and matches
+# at least one of the patterns passed (or '*' if no patterns passed).
+#
+# Implementation restrictions in the pure mode need to be accompanied
+# by appropriate REQUIRED_USE constraints. Otherwise, the eclass may
+# fail at build time due to unsatisfied dependencies.
+#
+# The any-of dep mode is used if python_check_deps() is declared.
+# In this mode, an implementation is considered suitable if it is
+# supported, matches at least one of the patterns and python_check_deps()
+# has successful return code. USE flags are not considered.
+#
+# The python_check_deps() function in the any-of mode needs to be
+# accompanied by appropriate any-of dependencies.
 #
 # The patterns can be either fnmatch-style patterns (matched via bash
 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
@@ -577,11 +595,7 @@ python_foreach_impl() {
 # of python_foreach_impl calls (e.g. for shared processes like doc
 # building). python_foreach_impl sets up the build environment itself.
 #
-# If the specific commands support only a subset of Python
-# implementations, patterns need to be passed to restrict the allowed
-# implementations.
-#
-# Example:
+# Pure mode example:
 # @CODE
 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
 # REQUIRED_USE="doc? ( $(python_gen_useflags 'python2*') )"
@@ -603,6 +617,9 @@ python_setup() {
 		pycompat=( ${PYTHON_COMPAT_OVERRIDE} )
 	fi
 
+	local has_check_deps
+	declare -f python_check_deps >/dev/null && has_check_deps=1
+
 	# (reverse iteration -- newest impl first)
 	local found
 	for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
@@ -612,7 +629,8 @@ python_setup() {
 		has "${impl}" "${pycompat[@]}" || continue
 
 		# match USE flags only if override is not in effect
-		if [[ ! ${PYTHON_COMPAT_OVERRIDE} ]]; then
+		# and python_check_deps() is not defined
+		if [[ ! ${PYTHON_COMPAT_OVERRIDE} && ! ${has_check_deps} ]]; then
 			use "python_targets_${impl}" || continue
 		fi
 
@@ -620,6 +638,16 @@ python_setup() {
 		_python_impl_matches "${impl}" "${@-*}" || continue
 
 		python_export "${impl}" EPYTHON PYTHON
+
+		# 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}(-),python_single_target_${impl}(+)"
+			python_check_deps || continue
+		fi
+
 		found=1
 		break
 	done
-- 
2.13.0



  parent reply	other threads:[~2017-05-20 13:33 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 ` [gentoo-dev] [PATCH 3/7] python-r1.eclass: Inline implementation loop logic into python_setup Michał Górny
2017-05-20 13:30 ` Michał Górny [this message]
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-5-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