6
6
7
7
def clean_tag (tag : str ) -> str :
8
8
"""Clean a tag name returning only the numeric part separated by dots."""
9
- return re .sub (
10
- r"^[a-zA-Z]+|[a-zA-Z]+$" ,
11
- "" ,
12
- "." .join (
13
- [n for n in re .split (r"[^0-9a-zA-Z]+" , tag ) if not n .isalpha ()]
14
- # bool(re.search(r"\d", n))
15
- ),
16
- )
9
+ return re .sub (r"[^0-9a-zA-Z]+" , "." , tag , flags = re .IGNORECASE )
10
+ # return re.sub(
11
+ # r"^[a-zA-Z]+|[a-zA-Z]+$",
12
+ # "",
13
+ # ".".join(
14
+ # [n for n in re.split(r"[^0-9a-zA-Z]+", tag) if not n.isalpha()]
15
+ # # bool(re.search(r"\d", n))
16
+ # ),
17
+ # )
17
18
18
19
19
20
def get_possible_missing_tag (
@@ -37,27 +38,48 @@ def get_possible_missing_tag(
37
38
38
39
def get_possible_tags (tags : list [str ], versions : str ):
39
40
"""Given a list of tags and a version interval, return the possible tag interval that matches."""
40
- tags_mapping : dict [str , list [str ]] = dict ()
41
- # Create a mapping between cleaned tags and the original tags (one stripped tag can match multiple tags)
42
- for tag in tags :
43
- stripped_tag = clean_tag (tag )
44
- if stripped_tag not in tags_mapping :
45
- tags_mapping [stripped_tag ] = [tag ]
46
- else :
47
- tags_mapping [stripped_tag ].append (tag )
41
+ prev_version , next_version = versions .split (":" )
48
42
49
- tags_mapping .pop ("" , None )
43
+ prev_tag = [
44
+ tag
45
+ for tag in tags
46
+ if prev_version in clean_tag (tag )
47
+ and not bool (re .search (r"rc\d+|\d{9,}" , tag , flags = re .IGNORECASE ))
48
+ ]
49
+ next_tag = [
50
+ tag
51
+ for tag in tags
52
+ if next_version in clean_tag (tag )
53
+ and not bool (re .search (r"rc\d+|\d{9,}" , tag , flags = re .IGNORECASE ))
54
+ ]
55
+ # TODO: Remove this print
56
+ print (prev_tag , next_tag )
57
+ # if len(prev_tag) == 0 or len(next_tag) == 0:
58
+ # tags_mapping: dict[str, list[str]] = dict()
59
+ # # Create a mapping between cleaned tags and the original tags (one stripped tag can match multiple tags)
60
+ # for tag in tags:
61
+ # stripped_tag = clean_tag(tag)
62
+
63
+ # if stripped_tag not in tags_mapping:
64
+ # tags_mapping[stripped_tag] = [tag]
65
+ # else:
66
+ # tags_mapping[stripped_tag].append(tag)
67
+
68
+ # tags_mapping.pop("", None)
69
+ # if len(prev_tag) == 0:
70
+ # prev_tag = tags_mapping.get(prev_version, [])
71
+ # if len(next_tag) == 0:
72
+ # next_tag = tags_mapping.get(next_version, [])
50
73
51
- prev_version , next_version = versions .split (":" )
52
- prev_tag = tags_mapping .get (prev_version , [])
53
- next_tag = tags_mapping .get (next_version , [])
54
74
# If there are two exact matches, return them
55
75
if len (prev_tag ) == 1 and len (next_tag ) == 1 :
56
76
return prev_tag [0 ], next_tag [0 ]
57
77
# If there is one exact match, and multiple candidates for the other tag, return the most similar
58
78
elif len (prev_tag ) == 1 and len (next_tag ) > 1 :
79
+ next_tag = [tag for tag in next_tag if tag > prev_tag [0 ]]
59
80
return prev_tag [0 ], difflib .get_close_matches (prev_tag [0 ], next_tag , n = 1 )[0 ]
60
81
elif len (prev_tag ) > 1 and len (next_tag ) == 1 :
82
+ prev_tag = [tag for tag in prev_tag if tag < next_tag [0 ]]
61
83
return difflib .get_close_matches (next_tag [0 ], prev_tag , n = 1 )[0 ], next_tag [0 ]
62
84
# If there is one exact match but no candidates for the other tag, exit and hint the user with possible candidates
63
85
elif len (prev_tag ) == 0 and len (next_tag ) == 1 :
0 commit comments