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:
parent
f40890c972
commit
2a3922dee7
@ -70,7 +70,7 @@ class TestVersion(base.BaseTestCase):
|
|||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
ValueError,
|
ValueError,
|
||||||
'Operation or argument is not supported',
|
'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):
|
def test_check_decorator(self):
|
||||||
fake_api = mock.Mock()
|
fake_api = mock.Mock()
|
||||||
|
@ -10,8 +10,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from distutils.version import StrictVersion
|
import functools
|
||||||
import operator
|
import operator
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
NEGOTIATE_VERSIONS = [
|
NEGOTIATE_VERSIONS = [
|
||||||
@ -60,8 +61,29 @@ SUPPORTED_VERSIONS = SUPPORTED_MICROVERSIONS + NEGOTIATE_VERSIONS
|
|||||||
MAX_VERSION_NO_GAP = '1.29'
|
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):
|
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):
|
def lt(b):
|
||||||
|
Loading…
Reference in New Issue
Block a user