Gentoo Archives: gentoo-dev

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