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] python-utils-r1.eclass: Inline _python_impl_supported()
Date: Fri, 01 Jan 2021 00:38:18
Message-Id: 20210101003809.297689-1-mgorny@gentoo.org
1 The _python_impl_supported() function is not used anymore in its
2 original function. It is called only once, in order to die on incorrect
3 targets in PYTHON_COMPAT. Let's inline the corresponding logic
4 in _python_set_impls() and remove the function.
5
6 While at it, add an extra check for outdated patterns. This also
7 renders the relevant tests obsolete.
8
9 Signed-off-by: Michał Górny <mgorny@g.o>
10 ---
11 eclass/python-utils-r1.eclass | 56 ++++++++++++---------------------
12 eclass/tests/python-utils-r1.sh | 18 -----------
13 2 files changed, 20 insertions(+), 54 deletions(-)
14
15 NB: I think I'll push this along with py2.7 or py3.6 disabling to avoid
16 unnecessary cache rebuilds.
17
18 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
19 index 9c8b6a14d2ac..2aa953213b6a 100644
20 --- a/eclass/python-utils-r1.eclass
21 +++ b/eclass/python-utils-r1.eclass
22 @@ -69,38 +69,6 @@ readonly _PYTHON_HISTORICAL_IMPLS
23 # which can involve revisions of this eclass that support a different
24 # set of Python implementations.
25
26 -# @FUNCTION: _python_impl_supported
27 -# @USAGE: <impl>
28 -# @INTERNAL
29 -# @DESCRIPTION:
30 -# Check whether the implementation <impl> (PYTHON_COMPAT-form)
31 -# is still supported.
32 -#
33 -# Returns 0 if the implementation is valid and supported. If it is
34 -# unsupported, returns 1 -- and the caller should ignore the entry.
35 -# If it is invalid, dies with an appopriate error messages.
36 -_python_impl_supported() {
37 - debug-print-function ${FUNCNAME} "${@}"
38 -
39 - [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)."
40 -
41 - local impl=${1}
42 -
43 - # keep in sync with _PYTHON_ALL_IMPLS!
44 - # (not using that list because inline patterns shall be faster)
45 - case "${impl}" in
46 - python2_7|python3_[6789]|pypy3)
47 - return 0
48 - ;;
49 - jython2_7|pypy|pypy1_[89]|pypy2_0|python2_[56]|python3_[12345])
50 - return 1
51 - ;;
52 - *)
53 - [[ ${PYTHON_COMPAT_NO_STRICT} ]] && return 1
54 - die "Invalid implementation in PYTHON_COMPAT: ${impl}"
55 - esac
56 -}
57 -
58 # @FUNCTION: _python_verify_patterns
59 # @USAGE: <pattern>...
60 # @INTERNAL
61 @@ -149,10 +117,26 @@ _python_set_impls() {
62 if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
63 die 'PYTHON_COMPAT must be an array.'
64 fi
65 - for i in "${PYTHON_COMPAT[@]}"; do
66 - # trigger validity checks
67 - _python_impl_supported "${i}"
68 - done
69 + if [[ ! ${PYTHON_COMPAT_NO_STRICT} ]]; then
70 + for i in "${PYTHON_COMPAT[@]}"; do
71 + # check for incorrect implementations
72 + # we're using pattern matching as an optimization
73 + # please keep them in sync with _PYTHON_ALL_IMPLS
74 + # and _PYTHON_HISTORICAL_IMPLS
75 + case ${i} in
76 + jython2_7|pypy|pypy1_[89]|pypy2_0|pypy3|python2_[5-7]|python3_[1-9])
77 + ;;
78 + *)
79 + if has "${i}" "${_PYTHON_ALL_IMPLS[@]}" \
80 + "${_PYTHON_HISTORICAL_IMPLS[@]}"
81 + then
82 + die "Mis-synced patterns in _python_set_impls: missing ${i}"
83 + else
84 + die "Invalid implementation in PYTHON_COMPAT: ${i}"
85 + fi
86 + esac
87 + done
88 + fi
89
90 local supp=() unsupp=()
91
92 diff --git a/eclass/tests/python-utils-r1.sh b/eclass/tests/python-utils-r1.sh
93 index 86b87ec173d4..eb8223ec6ac0 100755
94 --- a/eclass/tests/python-utils-r1.sh
95 +++ b/eclass/tests/python-utils-r1.sh
96 @@ -183,24 +183,6 @@ test_fix_shebang '#!/usr/bin/foo' python2.7 FAIL
97 # regression test for bug #522080
98 test_fix_shebang '#!/usr/bin/python ' python2.7 '#!/usr/bin/python2.7 '
99
100 -# make sure we don't break pattern matching
101 -test_is "_python_impl_supported python2_5" 1
102 -test_is "_python_impl_supported python2_6" 1
103 -test_is "_python_impl_supported python2_7" 0
104 -test_is "_python_impl_supported python3_1" 1
105 -test_is "_python_impl_supported python3_2" 1
106 -test_is "_python_impl_supported python3_3" 1
107 -test_is "_python_impl_supported python3_4" 1
108 -test_is "_python_impl_supported python3_5" 1
109 -test_is "_python_impl_supported python3_6" 0
110 -test_is "_python_impl_supported python3_7" 0
111 -test_is "_python_impl_supported python3_8" 0
112 -test_is "_python_impl_supported pypy1_8" 1
113 -test_is "_python_impl_supported pypy1_9" 1
114 -test_is "_python_impl_supported pypy2_0" 1
115 -test_is "_python_impl_supported pypy" 1
116 -test_is "_python_impl_supported pypy3" 0
117 -
118 # check _python_impl_matches behavior
119 test_is "_python_impl_matches python2_7 -2" 0
120 test_is "_python_impl_matches python3_6 -2" 1
121 --
122 2.30.0