Gentoo Archives: gentoo-portage-dev

From: gmt@×××××.us
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] portage.versions: Drop support for non-EAPI "cvs." version prefix
Date: Mon, 27 Nov 2017 19:09:37
Message-Id: 20171127190927.3275-1-gmt@malth.us
1 From: "Gregory M. Turner" <gmt@×××××××.net>
2
3 This feature was introduced 12 years ago in (the cvs commit
4 corresponding to the git commit) 9f3a46665c. There are a lot of
5 reasons not to continue to support it:
6
7 o EAPI permits no such prefix
8 o Nobody uses it (perhaps nobody /ever/ used it)
9 o It treats cvs as special, which doesn't make a ton of
10 sense in 2017
11 o If this prefix /were/ added to PMS, it seems* to create
12 ambiguity between PN and V in obscure EAPIs which support
13 dots in package names
14
15 Therefore, remove it from from the version regular expression and
16 renumber the constants referring to the affected re groups.
17
18 *PMS would barely avoid true abiguity as §3.1.2 has a rule that
19 logically necessitates that any such ambiguity must be resolved in
20 favor of V. Although this appears to be by design, expecting
21 people to figure this out seems a tad optimistic.
22
23 Signed-off-by: Gregory M. Turner <gmt@×××××××.net>
24 ---
25 pym/portage/tests/versions/test_vercmp.py | 3 ---
26 pym/portage/versions.py | 38 +++++++++++++------------------
27 2 files changed, 16 insertions(+), 25 deletions(-)
28
29 diff --git a/pym/portage/tests/versions/test_vercmp.py b/pym/portage/tests/versions/test_vercmp.py
30 index 78fe7ede8..b55518f02 100644
31 --- a/pym/portage/tests/versions/test_vercmp.py
32 +++ b/pym/portage/tests/versions/test_vercmp.py
33 @@ -15,7 +15,6 @@ class VerCmpTestCase(TestCase):
34 ("6.0", "5.0"), ("5.0", "5"),
35 ("1.0-r1", "1.0-r0"),
36 ("1.0-r1", "1.0"),
37 - ("cvs.9999", "9999"),
38 ("999999999999999999999999999999", "999999999999999999999999999998"),
39 ("1.0.0", "1.0"),
40 ("1.0.0", "1.0b"),
41 @@ -36,7 +35,6 @@ class VerCmpTestCase(TestCase):
42 ("1.0_alpha2", "1.0_p2"), ("1.0_alpha1", "1.0_beta1"), ("1.0_beta3", "1.0_rc3"),
43 ("1.001000000000000000001", "1.001000000000000000002"),
44 ("1.00100000000", "1.0010000000000000001"),
45 - ("9999", "cvs.9999"),
46 ("999999999999999999999999999998", "999999999999999999999999999999"),
47 ("1.01", "1.1"),
48 ("1.0-r0", "1.0-r1"),
49 @@ -69,7 +67,6 @@ class VerCmpTestCase(TestCase):
50 tests = [
51 ("1", "2"), ("1.0_alpha", "1.0_pre"), ("1.0_beta", "1.0_alpha"),
52 ("0", "0.0"),
53 - ("cvs.9999", "9999"),
54 ("1.0-r0", "1.0-r1"),
55 ("1.0-r1", "1.0-r0"),
56 ("1.0", "1.0-r1"),
57 diff --git a/pym/portage/versions.py b/pym/portage/versions.py
58 index adfb1c3e2..7b6a57673 100644
59 --- a/pym/portage/versions.py
60 +++ b/pym/portage/versions.py
61 @@ -50,7 +50,7 @@ _pkg = {
62 "dots_allowed_in_PN": r'[\w+][\w+.-]*?',
63 }
64
65 -_v = r'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)'
66 +_v = r'(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)'
67 _rev = r'\d+'
68 _vr = _v + '(-r(' + _rev + '))?'
69
70 @@ -156,21 +156,15 @@ def vercmp(ver1, ver2, silent=1):
71 print(_("!!! syntax error in version: %s") % ver2)
72 return None
73
74 - # shortcut for cvs ebuilds (new style)
75 - if match1.group(1) and not match2.group(1):
76 - return 1
77 - elif match2.group(1) and not match1.group(1):
78 - return -1
79 -
80 # building lists of the version parts before the suffix
81 # first part is simple
82 - list1 = [int(match1.group(2))]
83 - list2 = [int(match2.group(2))]
84 + list1 = [int(match1.group(1))]
85 + list2 = [int(match2.group(1))]
86
87 # this part would greatly benefit from a fixed-length version pattern
88 - if match1.group(3) or match2.group(3):
89 - vlist1 = match1.group(3)[1:].split(".")
90 - vlist2 = match2.group(3)[1:].split(".")
91 + if match1.group(2) or match2.group(2):
92 + vlist1 = match1.group(2)[1:].split(".")
93 + vlist2 = match2.group(2)[1:].split(".")
94
95 for i in range(0, max(len(vlist1), len(vlist2))):
96 # Implcit .0 is given a value of -1, so that 1.0.0 > 1.0, since it
97 @@ -206,10 +200,10 @@ def vercmp(ver1, ver2, silent=1):
98 # may seem counter-intuitive. However, if you really think about it, it
99 # seems like it's probably safe to assume that this is the behavior that
100 # is intended by anyone who would use versions such as these.
101 - if len(match1.group(5)):
102 - list1.append(ord(match1.group(5)))
103 - if len(match2.group(5)):
104 - list2.append(ord(match2.group(5)))
105 + if len(match1.group(4)):
106 + list1.append(ord(match1.group(4)))
107 + if len(match2.group(4)):
108 + list2.append(ord(match2.group(4)))
109
110 for i in range(0, max(len(list1), len(list2))):
111 if len(list1) <= i:
112 @@ -223,8 +217,8 @@ def vercmp(ver1, ver2, silent=1):
113 return rval
114
115 # main version is equal, so now compare the _suffix part
116 - list1 = match1.group(6).split("_")[1:]
117 - list2 = match2.group(6).split("_")[1:]
118 + list1 = match1.group(5).split("_")[1:]
119 + list2 = match2.group(5).split("_")[1:]
120
121 for i in range(0, max(len(list1), len(list2))):
122 # Implicit _p0 is given a value of -1, so that 1 < 1_p0
123 @@ -257,12 +251,12 @@ def vercmp(ver1, ver2, silent=1):
124 return rval
125
126 # the suffix part is equal to, so finally check the revision
127 - if match1.group(10):
128 - r1 = int(match1.group(10))
129 + if match1.group(9):
130 + r1 = int(match1.group(9))
131 else:
132 r1 = 0
133 - if match2.group(10):
134 - r2 = int(match2.group(10))
135 + if match2.group(9):
136 + r2 = int(match2.group(9))
137 else:
138 r2 = 0
139 rval = (r1 > r2) - (r1 < r2)
140 --
141 2.15.0

Replies