Replace distutils

distutils module was deprecated in 3.10 and was removed in Python
3.12 .

https://docs.python.org/3.11/library/distutils.html

Closes-Bug: #2083518
Change-Id: I0e00619dbd9a5aede18517f73163ec6f1680f4b6
This commit is contained in:
Takashi Kajinami 2024-11-23 05:47:04 +09:00
parent d3f8056d69
commit bfb0281066
3 changed files with 10 additions and 4 deletions

View File

@ -15,7 +15,6 @@
import abc
from collections import abc as collections_abc
import datetime
from distutils import versionpredicate
import re
import uuid
import warnings
@ -25,6 +24,7 @@ import iso8601
import netaddr
from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import versionutils
from oslo_versionedobjects._i18n import _
from oslo_versionedobjects import _utils
@ -293,8 +293,12 @@ class SensitiveString(String):
class VersionPredicate(String):
@staticmethod
def coerce(obj, attr, value):
if not isinstance(value, str):
raise ValueError(_('Version %(val)s should be a string type, not '
'%(real_type)s') %
{'val': value, 'real_type': type(value)})
try:
versionpredicate.VersionPredicate('check (%s)' % value)
versionutils.VersionPredicate(value)
except ValueError:
raise ValueError(_('Version %(val)s is not a valid predicate in '
'field %(attr)s') %

View File

@ -188,9 +188,11 @@ class TestVersionPredicate(TestString):
super().setUp()
self.field = fields.VersionPredicateField()
self.coerce_good_values = [('>=1.0', '>=1.0'),
('>1.0', '>1.0'),
('==1.1', '==1.1'),
('<=1.1.0', '<=1.1.0'),
('<1.1.0', '<1.1.0')]
self.coerce_bad_values = ['1', 'foo', '>1', 1.0, '1.0', '=1.0']
self.coerce_bad_values = ['1', 'foo', 1.0, '1.0', '=1.0']
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]

View File

@ -7,7 +7,7 @@ oslo.config>=5.2.0 # Apache-2.0
oslo.context>=2.19.2 # Apache-2.0
oslo.messaging>=5.29.0 # Apache-2.0
oslo.serialization>=2.18.0 # Apache-2.0
oslo.utils>=4.7.0 # Apache-2.0
oslo.utils>=7.4.0 # Apache-2.0
iso8601>=0.1.11 # MIT
oslo.log>=3.36.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0