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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E50A8139694 for ; Sat, 20 May 2017 13:33:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A591B21C130; Sat, 20 May 2017 13:30:59 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 552AF21C123 for ; Sat, 20 May 2017 13:30:59 +0000 (UTC) Received: from localhost.localdomain (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id BA4353416CB; Sat, 20 May 2017 13:30:57 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: python@gentoo.org, =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 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 Message-Id: <20170520133044.9692-5-mgorny@gentoo.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170520133044.9692-1-mgorny@gentoo.org> References: <20170520133044.9692-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-Archives-Salt: 9d5043bf-ac4a-49b7-a2d3-6f8cad59de1d X-Archives-Hash: ab35bd8a73e9973fcb60541b3fe927bb 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: [...] # @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