|
4 | 4 |
|
5 | 5 | from __future__ import absolute_import, division, unicode_literals
|
6 | 6 | import os
|
| 7 | +import re |
7 | 8 | from time import time
|
8 | 9 | from socket import timeout
|
9 | 10 | from ssl import SSLError
|
10 | 11 | import struct
|
11 | 12 | from typing import NamedTuple
|
12 | 13 | from functools import total_ordering
|
13 | 14 |
|
14 |
| - |
15 | 15 | try: # Python 3
|
16 | 16 | from urllib.error import HTTPError, URLError
|
17 | 17 | from urllib.request import Request, urlopen
|
@@ -364,17 +364,20 @@ def remove_tree(path):
|
364 | 364 |
|
365 | 365 |
|
366 | 366 | def parse_version(vstring):
|
367 |
| - """Parse a version string and return a comparable version object""" |
368 |
| - vstring = vstring.strip('v') |
369 |
| - vstrings = vstring.split('.') |
370 |
| - try: |
371 |
| - vnums = tuple(int(v) for v in vstrings) |
372 |
| - except ValueError: |
373 |
| - log(3, f"Version string {vstring} can't be interpreted! Contains non-numerics.") |
374 |
| - return Version(0, 0, 0, 0) |
375 |
| - |
376 |
| - if len(vnums) > 4: |
377 |
| - log(3, f"Version string {vstring} can't be interpreted! Too long.") |
378 |
| - return Version(0, 0, 0, 0) |
| 367 | + """Parse a version string and return a comparable version object, properly handling non-numeric prefixes.""" |
| 368 | + vstring = vstring.strip('v').lower() |
| 369 | + parts = re.split(r'\.', vstring) # split on periods first |
| 370 | + |
| 371 | + vnums = [] |
| 372 | + for part in parts: |
| 373 | + # extract numeric part, ignoring non-numeric prefixes |
| 374 | + numeric_part = re.search(r'\d+', part) |
| 375 | + if numeric_part: |
| 376 | + vnums.append(int(numeric_part.group())) |
| 377 | + else: |
| 378 | + vnums.append(0) # default to 0 if no numeric part found |
| 379 | + |
| 380 | + # ensure the version tuple always has 4 components |
| 381 | + vnums = (vnums + [0] * 4)[:4] |
379 | 382 |
|
380 | 383 | return Version(*vnums)
|
0 commit comments