Remove use of distutils

This has been removed in Python 3.12, which is preventing us using
osc-placement in those environments. Thankfully we only use it for
StrictVersion which we are using to parse microversions. This is
actually overkill here since we can always expect a version string like
'1.5', thus we do this parsing ourselves rather than drag in a new
library like 'microversion_parse'.

Change-Id: I2923238f8b30568bceb1799882d4468ff1d7e538
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-07-24 16:08:32 +01:00
parent f40890c972
commit 2a3922dee7
2 changed files with 25 additions and 3 deletions

View File

@ -70,7 +70,7 @@ class TestVersion(base.BaseTestCase):
self.assertRaisesRegex(
ValueError,
'Operation or argument is not supported',
version.compare, '3.1.2', version.gt('3.1.3'))
version.compare, '3.1', version.gt('3.2'))
def test_check_decorator(self):
fake_api = mock.Mock()

View File

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from distutils.version import StrictVersion
import functools
import operator
import re
NEGOTIATE_VERSIONS = [
@ -60,8 +61,29 @@ SUPPORTED_VERSIONS = SUPPORTED_MICROVERSIONS + NEGOTIATE_VERSIONS
MAX_VERSION_NO_GAP = '1.29'
@functools.total_ordering
class _Version:
_version_re = re.compile(r'^(\d) \. (\d+)$', re.VERBOSE | re.ASCII)
def __init__(self, version):
match = self._version_re.match(version)
if not match:
raise ValueError('invalid version number %s' % version)
major, minor = match.group(1, 2)
self.version = (int(major), int(minor))
def __str__(self):
return '.'.join(str(v) for v in self.version)
def __eq__(self, other):
return self.version == other.version
def __lt__(self, other):
return self.version < other.version
def _op(func, b, msg):
return lambda a: func(StrictVersion(a), StrictVersion(b)) or msg
return lambda a: func(_Version(a), _Version(b)) or msg
def lt(b):