Skip to content

Commit

Permalink
Compile regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw committed Oct 14, 2023
1 parent 2d7df0d commit 4c97a45
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions req_update/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ def compare_versions(self, current: str, proposed: str) -> bool:
valid upgrade if the version structure matches and the version numbers
are greater.
"""
structure_regex = r"[0-9]+"
current_structure = re.sub(structure_regex, "", current)
proposed_structure = re.sub(structure_regex, "", proposed)
structure_regex = re.compile(r"[0-9]+")
current_structure = structure_regex.sub("", current)
proposed_structure = structure_regex.sub("", proposed)
if current_structure != proposed_structure:
return False
num_regex = r"\d+"
current_nums = re.findall(num_regex, current)
proposed_nums = re.findall(num_regex, proposed)
num_regex = re.compile(r"\d+")
current_nums = num_regex.findall(current)
proposed_nums = num_regex.findall(proposed)
for compares in zip(current_nums, proposed_nums):
if int(compares[0]) < int(compares[1]):
return True
Expand Down

0 comments on commit 4c97a45

Please sign in to comment.