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 1/3] python-utils-r1.eclass: Allow -2/-3 as impl-patterns for py2/py3
Date: Wed, 10 May 2017 18:53:55
Message-Id: 20170510185333.6423-1-mgorny@gentoo.org
1 Allow two special values in the implementation patterns for
2 _python_impl_matches(): -2 to indicate all Python 2-compatible
3 implementations, and -3 to indicate all Python 3-compatible
4 implementations. Both of those values are implemented using
5 the python_is_python3 function.
6
7 This is mostly meant to make it easier and more fool-proof to write
8 dependencies on backports to Python 2 which in most cases apply to PyPy2
9 as well.
10 ---
11 eclass/python-utils-r1.eclass | 14 +++++++++++---
12 1 file changed, 11 insertions(+), 3 deletions(-)
13
14 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
15 index 7efec083e35e..703246933acc 100644
16 --- a/eclass/python-utils-r1.eclass
17 +++ b/eclass/python-utils-r1.eclass
18 @@ -156,8 +156,10 @@ _python_set_impls() {
19 # Check whether the specified <impl> matches at least one
20 # of the patterns following it. Return 0 if it does, 1 otherwise.
21 #
22 -# <impl> should be in PYTHON_COMPAT form. The patterns are fnmatch-style
23 -# patterns.
24 +# <impl> should be in PYTHON_COMPAT form. The patterns can be either:
25 +# a) fnmatch-style patterns, e.g. 'python2*', 'pypy'...
26 +# b) '-2' to indicate all Python 2 variants (= !python_is_python3)
27 +# c) '-3' to indicate all Python 3 variants (= python_is_python3)
28 _python_impl_matches() {
29 [[ ${#} -ge 2 ]] || die "${FUNCNAME}: takes at least 2 parameters"
30
31 @@ -165,7 +167,13 @@ _python_impl_matches() {
32 shift
33
34 for pattern; do
35 - if [[ ${impl} == ${pattern} ]]; then
36 + if [[ ${pattern} == -2 ]]; then
37 + ! python_is_python3 "${impl}"
38 + return
39 + elif [[ ${pattern} == -3 ]]; then
40 + python_is_python3 "${impl}"
41 + return
42 + elif [[ ${impl} == ${pattern} ]]; then
43 return 0
44 fi
45 done
46 --
47 2.13.0

Replies