Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 25/30] python-utils-r1.eclass: Support matching impls by stdlib version
Date: Sun, 06 Feb 2022 12:56:40
Message-Id: 20220206124841.1299133-26-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 00/30] One batch of Python eclass updates to rule them all by "Michał Górny"
1 Update _python_impl_matches() (used to implement python_gen*,
2 python_setup) to support specifying stdlib versions ("3.8", "3.9")
3 in addition to exact implementation names. This makes handling PyPy3
4 version changes much easier when dealing with backports.
5
6 For example, if you specify "3.8", then the spec will match python3_8
7 and pypy3, for as long as we supply PyPy3.8. Once we upgrade to PyPy3.9
8 completely, it will stop matching pypy3 and we won't have to manually
9 keep updating these deps.
10
11 Signed-off-by: Michał Górny <mgorny@g.o>
12 ---
13 eclass/distutils-r1.eclass | 5 ++---
14 eclass/python-r1.eclass | 35 ++++++++++------------------------
15 eclass/python-single-r1.eclass | 18 ++++++-----------
16 eclass/python-utils-r1.eclass | 22 +++++++++++++++++----
17 4 files changed, 36 insertions(+), 44 deletions(-)
18
19 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
20 index ea8fc7e5d165..4feb9d7177ae 100644
21 --- a/eclass/distutils-r1.eclass
22 +++ b/eclass/distutils-r1.eclass
23 @@ -333,9 +333,8 @@ unset -f _distutils_set_globals
24 # (allowing any implementation). If multiple values are specified,
25 # implementations matching any of the patterns will be accepted.
26 #
27 -# The patterns are fnmatch-style patterns (matched via bash == operator
28 -# against PYTHON_COMPAT values). Remember to escape or quote the fnmatch
29 -# patterns to prevent accidental shell filename expansion.
30 +# For the pattern syntax, please see _python_impl_matches
31 +# in python-utils-r1.eclass.
32 #
33 # If the restriction needs to apply conditionally to a USE flag,
34 # the variable should be set conditionally as well (e.g. in an early
35 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
36 index bb851e167617..bf2fd62fdcba 100644
37 --- a/eclass/python-r1.eclass
38 +++ b/eclass/python-r1.eclass
39 @@ -289,11 +289,6 @@ _python_validate_useflags() {
40 # are both in PYTHON_COMPAT and match any of the patterns passed
41 # as parameters to the function.
42 #
43 -# The patterns are fnmatch-style patterns (matched via bash
44 -# == operator against PYTHON_COMPAT values). Remember to escape
45 -# or quote the fnmatch patterns to prevent accidental shell filename
46 -# expansion.
47 -#
48 # This is an internal function used to implement python_gen_cond_dep.
49 _python_gen_usedep() {
50 debug-print-function ${FUNCNAME} "${@}"
51 @@ -322,10 +317,8 @@ _python_gen_usedep() {
52 # are both in PYTHON_COMPAT and match any of the patterns passed
53 # as parameters to the function.
54 #
55 -# The patterns are fnmatch-style patterns (matched via bash
56 -# == operator against PYTHON_COMPAT values). Remember to escape
57 -# or quote the fnmatch patterns to prevent accidental shell filename
58 -# expansion.
59 +# For the pattern syntax, please see _python_impl_matches
60 +# in python-utils-r1.eclass.
61 #
62 # Example:
63 # @CODE
64 @@ -359,10 +352,8 @@ python_gen_useflags() {
65 # of Python implementations which are both in PYTHON_COMPAT and match
66 # any of the patterns passed as the remaining parameters.
67 #
68 -# The patterns are fnmatch-style patterns (matched via bash
69 -# == operator against PYTHON_COMPAT values). Remember to escape
70 -# or quote the fnmatch patterns to prevent accidental shell filename
71 -# expansion.
72 +# For the pattern syntax, please see _python_impl_matches
73 +# in python-utils-r1.eclass.
74 #
75 # In order to enforce USE constraints on the packages, verbatim
76 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
77 @@ -423,10 +414,8 @@ python_gen_cond_dep() {
78 # patterns are passed, the output dependencies will be generated only
79 # for the implementations matching them.
80 #
81 -# The patterns are fnmatch-style patterns (matched via bash
82 -# == operator against PYTHON_COMPAT values). Remember to escape
83 -# or quote the fnmatch patterns to prevent accidental shell filename
84 -# expansion.
85 +# For the pattern syntax, please see _python_impl_matches
86 +# in python-utils-r1.eclass.
87 #
88 # Use this function when you need to request different USE flags
89 # on the Python interpreter depending on package's USE flags. If you
90 @@ -479,10 +468,8 @@ python_gen_impl_dep() {
91 #
92 # Optionally, patterns may be specified to restrict the dependency to
93 # a subset of Python implementations supported by the ebuild.
94 -# The patterns are fnmatch-style patterns (matched via bash
95 -# == operator against PYTHON_COMPAT values). Remember to escape
96 -# or quote the fnmatch patterns to prevent accidental shell filename
97 -# expansion.
98 +# For the pattern syntax, please see _python_impl_matches
99 +# in python-utils-r1.eclass.
100 #
101 # This should be used along with an appropriate python_check_deps()
102 # that checks which of the any-of blocks were matched, and python_setup
103 @@ -669,10 +656,8 @@ python_foreach_impl() {
104 # The python_check_deps() function in the any-of mode needs to be
105 # accompanied by appropriate any-of dependencies.
106 #
107 -# The patterns are fnmatch-style patterns (matched via bash
108 -# == operator against PYTHON_COMPAT values). Remember to escape
109 -# or quote the fnmatch patterns to prevent accidental shell filename
110 -# expansion.
111 +# For the pattern syntax, please see _python_impl_matches
112 +# in python-utils-r1.eclass.
113 #
114 # This function needs to be used when Python is being called outside
115 # of python_foreach_impl calls (e.g. for shared processes like doc
116 diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
117 index 0e9a16a47d0e..998e6faad841 100644
118 --- a/eclass/python-single-r1.eclass
119 +++ b/eclass/python-single-r1.eclass
120 @@ -266,10 +266,8 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
121 # are both in PYTHON_COMPAT and match any of the patterns passed
122 # as parameters to the function.
123 #
124 -# The patterns are fnmatch-style patterns (matched via bash
125 -# == operator against PYTHON_COMPAT values). Remember to escape
126 -# or quote the fnmatch patterns to prevent accidental shell filename
127 -# expansion.
128 +# For the pattern syntax, please see _python_impl_matches
129 +# in python-utils-r1.eclass.
130 #
131 # Example:
132 # @CODE
133 @@ -303,10 +301,8 @@ python_gen_useflags() {
134 # of Python implementations which are both in PYTHON_COMPAT and match
135 # any of the patterns passed as the remaining parameters.
136 #
137 -# The patterns are fnmatch-style patterns (matched via bash
138 -# == operator against PYTHON_COMPAT values). Remember to escape
139 -# or quote the fnmatch patterns to prevent accidental shell filename
140 -# expansion.
141 +# For the pattern syntax, please see _python_impl_matches
142 +# in python-utils-r1.eclass.
143 #
144 # In order to enforce USE constraints on the packages, verbatim
145 # '${PYTHON_SINGLE_USEDEP}' and '${PYTHON_USEDEP}' (quoted!) may
146 @@ -359,10 +355,8 @@ python_gen_cond_dep() {
147 # patterns are passed, the output dependencies will be generated only
148 # for the implementations matching them.
149 #
150 -# The patterns are fnmatch-style patterns (matched via bash
151 -# == operator against PYTHON_COMPAT values). Remember to escape
152 -# or quote the fnmatch patterns to prevent accidental shell filename
153 -# expansion.
154 +# For the pattern syntax, please see _python_impl_matches
155 +# in python-utils-r1.eclass.
156 #
157 # Use this function when you need to request different USE flags
158 # on the Python interpreter depending on package's USE flags. If you
159 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
160 index 1c6409add35c..291d7ce9b771 100644
161 --- a/eclass/python-utils-r1.eclass
162 +++ b/eclass/python-utils-r1.eclass
163 @@ -82,7 +82,11 @@ _python_verify_patterns() {
164
165 local impl pattern
166 for pattern; do
167 - [[ ${pattern} == -[23] ]] && continue
168 + case ${pattern} in
169 + -[23]|3.[89]|3.10)
170 + continue
171 + ;;
172 + esac
173
174 for impl in "${_PYTHON_ALL_IMPLS[@]}" "${_PYTHON_HISTORICAL_IMPLS[@]}"
175 do
176 @@ -190,12 +194,14 @@ _python_set_impls() {
177 # Matches if no patterns are provided.
178 #
179 # <impl> can be in PYTHON_COMPAT or EPYTHON form. The patterns
180 -# are fnmatch-style.
181 +# can either be fnmatch-style or stdlib versions, e.g. "3.8", "3.9".
182 +# In the latter case, pypy3 will match if there is at least one pypy3
183 +# version matching the stdlib version.
184 _python_impl_matches() {
185 [[ ${#} -ge 1 ]] || die "${FUNCNAME}: takes at least 1 parameter"
186 [[ ${#} -eq 1 ]] && return 0
187
188 - local impl=${1} pattern
189 + local impl=${1/./_} pattern
190 shift
191
192 for pattern; do
193 @@ -218,9 +224,17 @@ _python_impl_matches() {
194 fi
195 return 0
196 ;;
197 + 3.8)
198 + # the only unmasked pypy3 version is pypy3.8 atm
199 + [[ ${impl} == python${pattern/./_} || ${impl} == pypy3 ]] &&
200 + return 0
201 + ;;
202 + 3.9|3.10)
203 + [[ ${impl} == python${pattern/./_} ]] && return 0
204 + ;;
205 *)
206 # unify value style to allow lax matching
207 - [[ ${impl/./_} == ${pattern/./_} ]] && return 0
208 + [[ ${impl} == ${pattern/./_} ]] && return 0
209 ;;
210 esac
211 done
212 --
213 2.35.1