summaryrefslogtreecommitdiff
blob: 8bee592b228e644dbede2925e968c44994fc283e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From 443c0aab158e34196399073e801ae19ae0dce4dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Sun, 9 May 2021 10:59:18 +0200
Subject: [PATCH] python: Fix treating python3.10 as newer than python3.9

Fix the sorting logic to use a combined lexical-numerical sort, in order
to sort python3.10 as newer than python3.9.  This fixes
PythonCompatUpdate check.
---
 src/pkgcheck/checks/python.py                 | 25 +++++++++++++++----
 .../PythonCompatUpdate/expected.json          |  6 ++---
 .../PythonCompatUpdate/fix.patch              |  6 ++---
 .../profiles/desc/python_single_target.desc   |  1 +
 .../python/profiles/desc/python_targets.desc  |  1 +
 .../stub/python-dep1/python-dep1-0.ebuild     |  2 +-
 .../stub/python-dep2/python-dep2-0.ebuild     |  2 +-
 7 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py
index ed922215..7f0e9be4 100644
--- a/src/pkgcheck/checks/python.py
+++ b/src/pkgcheck/checks/python.py
@@ -1,4 +1,5 @@
 import itertools
+import re
 
 from pkgcore.ebuild.atom import atom
 from pkgcore.restrictions import packages, values
@@ -28,6 +29,18 @@ CHECK_EXCLUDE = frozenset(['virtual/pypy', 'virtual/pypy3'])
 IUSE_PREFIX = 'python_targets_'
 IUSE_PREFIX_S = 'python_single_target_'
 
+TARGET_SPLIT_RE = re.compile(r'([0-9]+)')
+
+
+def target_sort_key(target):
+    def iter():
+        for x in TARGET_SPLIT_RE.split(target):
+            try:
+                yield int(x)
+            except ValueError:
+                yield x
+    return tuple(iter())
+
 
 def get_python_eclass(pkg):
     eclasses = ECLASSES.intersection(pkg.inherited)
@@ -281,14 +294,14 @@ class PythonCompatCheck(Check):
         for target, _desc in repo.config.use_expand_desc.get(IUSE_PREFIX[:-1], ()):
             if target[len(IUSE_PREFIX):].startswith('python'):
                 targets.append(target[len(IUSE_PREFIX):])
-        multi_targets = tuple(sorted(targets))
+        multi_targets = tuple(sorted(targets, key=target_sort_key))
 
         # determine available PYTHON_SINGLE_TARGET use flags
         targets = []
         for target, _desc in repo.config.use_expand_desc.get(IUSE_PREFIX_S[:-1], ()):
             if target[len(IUSE_PREFIX_S):].startswith('python'):
                 targets.append(target[len(IUSE_PREFIX_S):])
-        single_targets = tuple(sorted(targets))
+        single_targets = tuple(sorted(targets, key=target_sort_key))
 
         self.params = {
             'python-r1': (multi_targets, IUSE_PREFIX, None),
@@ -327,8 +340,9 @@ class PythonCompatCheck(Check):
         try:
             # determine the latest supported python version
             latest_target = sorted(
-                f"python{x.slot.replace('.', '_')}" for x in deps
-                if x.key == 'dev-lang/python' and x.slot is not None)[-1]
+                (f"python{x.slot.replace('.', '_')}" for x in deps
+                if x.key == 'dev-lang/python' and x.slot is not None),
+                key=target_sort_key)[-1]
         except IndexError:
             # should be flagged by PythonMissingDeps
             return
@@ -355,4 +369,5 @@ class PythonCompatCheck(Check):
             except IndexError:
                 return
 
-            yield PythonCompatUpdate(sorted(targets), pkg=pkg)
+            yield PythonCompatUpdate(sorted(targets, key=target_sort_key),
+                                     pkg=pkg)
diff --git a/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/expected.json b/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/expected.json
index ab7d9b01..f3476eac 100644
--- a/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/expected.json
+++ b/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/expected.json
@@ -1,3 +1,3 @@
-{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "0", "updates": ["python3_8", "python3_9"]}
-{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "1", "updates": ["python3_9"]}
-{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "2", "updates": ["python3_9"]}
+{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "0", "updates": ["python3_8", "python3_9", "python3_10"]}
+{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "1", "updates": ["python3_9", "python3_10"]}
+{"__class__": "PythonCompatUpdate", "category": "PythonCompatCheck", "package": "PythonCompatUpdate", "version": "2", "updates": ["python3_9", "python3_10"]}
diff --git a/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/fix.patch b/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/fix.patch
index c63184e9..9be4952a 100644
--- a/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/fix.patch
+++ b/testdata/data/repos/python/PythonCompatCheck/PythonCompatUpdate/fix.patch
@@ -4,7 +4,7 @@ diff -Naur python/PythonCompatCheck/PythonCompatUpdate/PythonCompatUpdate-0.ebui
 @@ -1,5 +1,5 @@
  EAPI=7
 -PYTHON_COMPAT=( python3_7 )
-+PYTHON_COMPAT=( python3_{7..9} )
++PYTHON_COMPAT=( python3_{7..10} )
  
  inherit python-r1
  
@@ -14,7 +14,7 @@ diff -Naur python/PythonCompatCheck/PythonCompatUpdate/PythonCompatUpdate-1.ebui
 @@ -1,5 +1,5 @@
  EAPI=7
 -PYTHON_COMPAT=( python3_{7,8} )
-+PYTHON_COMPAT=( python3_{7..9} )
++PYTHON_COMPAT=( python3_{7..10} )
  
  inherit python-single-r1
  
@@ -24,7 +24,7 @@ diff -Naur python/PythonCompatCheck/PythonCompatUpdate/PythonCompatUpdate-2.ebui
 @@ -1,5 +1,5 @@
  EAPI=7
 -PYTHON_COMPAT=( python3_{7,8} )
-+PYTHON_COMPAT=( python3_{7..9} )
++PYTHON_COMPAT=( python3_{7..10} )
  
  inherit python-any-r1
  
diff --git a/testdata/repos/python/profiles/desc/python_single_target.desc b/testdata/repos/python/profiles/desc/python_single_target.desc
index da5be2fd..3c39a224 100644
--- a/testdata/repos/python/profiles/desc/python_single_target.desc
+++ b/testdata/repos/python/profiles/desc/python_single_target.desc
@@ -3,4 +3,5 @@ python2_7 - Build with Python 2.7
 python3_7 - Build with Python 3.7
 python3_8 - Build with Python 3.8
 python3_9 - Build with Python 3.9
+python3_10 - Build with Python 3.10
 pypy3 - Build for PyPy3 only
diff --git a/testdata/repos/python/profiles/desc/python_targets.desc b/testdata/repos/python/profiles/desc/python_targets.desc
index b2be59ca..8e55f2da 100644
--- a/testdata/repos/python/profiles/desc/python_targets.desc
+++ b/testdata/repos/python/profiles/desc/python_targets.desc
@@ -3,4 +3,5 @@ python2_7 - Build with Python 2.7
 python3_7 - Build with Python 3.7
 python3_8 - Build with Python 3.8
 python3_9 - Build with Python 3.9
+python3_10 - Build with Python 3.10
 pypy3 - Build for PyPy3 only
diff --git a/testdata/repos/python/stub/python-dep1/python-dep1-0.ebuild b/testdata/repos/python/stub/python-dep1/python-dep1-0.ebuild
index 9eebedfd..55c455d9 100644
--- a/testdata/repos/python/stub/python-dep1/python-dep1-0.ebuild
+++ b/testdata/repos/python/stub/python-dep1/python-dep1-0.ebuild
@@ -1,5 +1,5 @@
 EAPI=7
-PYTHON_COMPAT=( python2_7 python3_{7,8,9} )
+PYTHON_COMPAT=( python2_7 python3_{7,8,9,10} )
 
 inherit python-r1
 
diff --git a/testdata/repos/python/stub/python-dep2/python-dep2-0.ebuild b/testdata/repos/python/stub/python-dep2/python-dep2-0.ebuild
index 9eebedfd..55c455d9 100644
--- a/testdata/repos/python/stub/python-dep2/python-dep2-0.ebuild
+++ b/testdata/repos/python/stub/python-dep2/python-dep2-0.ebuild
@@ -1,5 +1,5 @@
 EAPI=7
-PYTHON_COMPAT=( python2_7 python3_{7,8,9} )
+PYTHON_COMPAT=( python2_7 python3_{7,8,9,10} )
 
 inherit python-r1
 
-- 
2.31.1