versionutil: Remove trailing alpha/beta/rc suffix

Sometimes we have to use the latest code instead of the latest release
to test upcoming changes (eg. sqlalchemy). In such case the version
string might contain its development status such as beta, and causes
failure while parsing the version string.

This makes the parse logic ignore the development status suffix to
avoid the failure.

Closes-Bug: #2042886
Change-Id: I27c14ede026c5600173047b1a0892a02a54dbb06
This commit is contained in:
Takashi Kajinami 2023-11-08 02:01:55 +09:00
parent a122f5c065
commit 0588ba20d9
2 changed files with 12 additions and 0 deletions

View File

@ -83,3 +83,13 @@ class IsCompatibleTestCase(test_base.BaseTestCase):
def test_convert_version_to_tuple(self):
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0'))
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0a1'))
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0alpha1'))
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0b1'))
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0beta1'))
self.assertEqual((6, 7, 0),
versionutils.convert_version_to_tuple('6.7.0rc1'))

View File

@ -20,6 +20,7 @@ Helpers for comparing version strings.
"""
import functools
import re
import packaging.version
@ -87,4 +88,5 @@ def convert_version_to_tuple(version_str):
.. versionadded:: 2.0
"""
version_str = re.sub(r'(\d+)(a|alpha|b|beta|rc)\d+$', '\\1', version_str)
return tuple(int(part) for part in version_str.split('.'))