Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Mon, 29 May 2017 21:54:13
Message-Id: 1496094826.49c5d62485286040dd227d7f63200284da01a3af.mgorny@gentoo
1 commit: 49c5d62485286040dd227d7f63200284da01a3af
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 19 18:17:57 2017 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Mon May 29 21:53:46 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=49c5d624
7
8 python-r1.eclass: Support python_check_deps() in python_setup
9
10 Provide an alternate mode for python_setup() that behaves similarly to
11 python-any-r1 eclass. If python_check_deps() function is declared
12 by the ebuild, the python_setup logic switches to accepting any
13 implementation that is in PYTHON_COMPAT, installed and satisfies
14 python_check_deps() independently of USE flags.
15
16 This new logic makes it possible to replace some of the existing
17 REQUIRED_USE constraints for build-time dependencies with more friendly
18 any-of dependencies. For example, if a package supports both Python 2 &
19 Python 3 but has a purely Python 2 build-time dependency (e.g. for
20 building documentation) we had to force Python 2 being enabled via
21 REQUIRED_USE. Using python_check_deps() with appropriate any-of
22 dependency, we can use Python 2 for this task without actually forcing
23 the user to change USE flags or install the package for Python 2.
24
25 eclass/python-r1.eclass | 48 ++++++++++++++++++++++++++++++++++++++----------
26 1 file changed, 38 insertions(+), 10 deletions(-)
27
28 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
29 index 9c37a20f7c2..2992f603cf8 100644
30 --- a/eclass/python-r1.eclass
31 +++ b/eclass/python-r1.eclass
32 @@ -231,7 +231,7 @@ _python_set_globals() {
33 PYTHON_DEPS=${deps}
34 PYTHON_REQUIRED_USE=${requse}
35 PYTHON_USEDEP=${usedep}
36 - readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP
37 + readonly PYTHON_DEPS PYTHON_REQUIRED_USE
38 fi
39 }
40 _python_set_globals
41 @@ -563,9 +563,27 @@ python_foreach_impl() {
42 # @FUNCTION: python_setup
43 # @USAGE: [<impl-pattern>...]
44 # @DESCRIPTION:
45 -# Find the best (most preferred) Python implementation that is enabled
46 -# and matches at least one of the patterns passed (or '*' if no patterns
47 -# passed). Set the Python build environment up for that implementation.
48 +# Find the best (most preferred) Python implementation that is suitable
49 +# for running common Python code. Set the Python build environment up
50 +# for that implementation. This function has two modes of operation:
51 +# pure and any-of dep.
52 +#
53 +# The pure mode is used if python_check_deps() function is not declared.
54 +# In this case, an implementation is considered suitable if it is
55 +# supported (in PYTHON_COMPAT), enabled (via USE flags) and matches
56 +# at least one of the patterns passed (or '*' if no patterns passed).
57 +#
58 +# Implementation restrictions in the pure mode need to be accompanied
59 +# by appropriate REQUIRED_USE constraints. Otherwise, the eclass may
60 +# fail at build time due to unsatisfied dependencies.
61 +#
62 +# The any-of dep mode is used if python_check_deps() is declared.
63 +# In this mode, an implementation is considered suitable if it is
64 +# supported, matches at least one of the patterns and python_check_deps()
65 +# has successful return code. USE flags are not considered.
66 +#
67 +# The python_check_deps() function in the any-of mode needs to be
68 +# accompanied by appropriate any-of dependencies.
69 #
70 # The patterns can be either fnmatch-style patterns (matched via bash
71 # == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate
72 @@ -577,11 +595,7 @@ python_foreach_impl() {
73 # of python_foreach_impl calls (e.g. for shared processes like doc
74 # building). python_foreach_impl sets up the build environment itself.
75 #
76 -# If the specific commands support only a subset of Python
77 -# implementations, patterns need to be passed to restrict the allowed
78 -# implementations.
79 -#
80 -# Example:
81 +# Pure mode example:
82 # @CODE
83 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
84 # REQUIRED_USE="doc? ( $(python_gen_useflags 'python2*') )"
85 @@ -603,6 +617,9 @@ python_setup() {
86 pycompat=( ${PYTHON_COMPAT_OVERRIDE} )
87 fi
88
89 + local has_check_deps
90 + declare -f python_check_deps >/dev/null && has_check_deps=1
91 +
92 # (reverse iteration -- newest impl first)
93 local found
94 for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
95 @@ -612,7 +629,8 @@ python_setup() {
96 has "${impl}" "${pycompat[@]}" || continue
97
98 # match USE flags only if override is not in effect
99 - if [[ ! ${PYTHON_COMPAT_OVERRIDE} ]]; then
100 + # and python_check_deps() is not defined
101 + if [[ ! ${PYTHON_COMPAT_OVERRIDE} && ! ${has_check_deps} ]]; then
102 use "python_targets_${impl}" || continue
103 fi
104
105 @@ -620,6 +638,16 @@ python_setup() {
106 _python_impl_matches "${impl}" "${@-*}" || continue
107
108 python_export "${impl}" EPYTHON PYTHON
109 +
110 + # if python_check_deps() is declared, switch into any-of mode
111 + if [[ ${has_check_deps} ]]; then
112 + # first check if the interpreter is installed
113 + python_is_installed "${impl}" || continue
114 + # then run python_check_deps
115 + local PYTHON_USEDEP="python_targets_${impl}(-),python_single_target_${impl}(+)"
116 + python_check_deps || continue
117 + fi
118 +
119 found=1
120 break
121 done