Skip to content

Commit f3d1e60

Browse files
authored
Merge pull request #2116 from tchaikov/wip-drop-distutils
teuthology: remove dependency on distutils Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
2 parents 258eb62 + 6118946 commit f3d1e60

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

teuthology/describe_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import yaml
99

1010
import random
11-
from distutils.util import strtobool
12-
1311
from teuthology.exceptions import ParseError
1412
from teuthology.suite.build_matrix import \
1513
build_matrix, generate_combinations, _get_matrix
1614
from teuthology.suite import util, merge
15+
from teuthology.util.strtobool import strtobool
1716

1817
def main(args):
1918
try:

teuthology/suite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import random
88
import sys
99
import time
10-
from distutils.util import strtobool
1110

1211
import teuthology
1312
from teuthology.config import config, YamlConfig
@@ -16,6 +15,7 @@
1615

1716
from teuthology.suite.run import Run
1817
from teuthology.suite.util import schedule_fail
18+
from teuthology.util.strtobool import strtobool
1919

2020
log = logging.getLogger(__name__)
2121

teuthology/task/install/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from teuthology.parallel import parallel
1111
from teuthology.task import ansible
1212

13-
from distutils.version import LooseVersion
1413
from teuthology.task.install.util import (
1514
_get_builder_project, get_flavor, ship_utilities,
1615
)
1716

1817
from teuthology.task.install import rpm, deb, redhat
18+
from teuthology.util.version import LooseVersion
1919

2020
log = logging.getLogger(__name__)
2121

teuthology/task/install/rpm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import os.path
33
from io import StringIO
44

5-
from distutils.version import LooseVersion
6-
75
from teuthology.config import config as teuth_config
86
from teuthology.contextutil import safe_while
97
from teuthology.orchestra import run
108
from teuthology import packaging
119

1210
from teuthology.task.install.util import _get_builder_project, _get_local_dir
11+
from teuthology.util.version import LooseVersion
1312

1413
log = logging.getLogger(__name__)
1514

teuthology/util/strtobool.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def strtobool(val):
2+
"""Convert a string representation of truth to true (1) or false (0).
3+
4+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
5+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
6+
'val' is anything else.
7+
"""
8+
val = val.lower()
9+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
10+
return 1
11+
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
12+
return 0
13+
else:
14+
raise ValueError(f"invalid truth value {val!r}")

teuthology/util/version.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
from functools import total_ordering
3+
from typing import Union, List
4+
5+
6+
@total_ordering
7+
class LooseVersion:
8+
"""
9+
A flexible version comparison class that handles arbitrary version strings.
10+
Compares numeric components numerically and alphabetic components lexically.
11+
"""
12+
13+
_component_re = re.compile(r'(\d+|[a-z]+|\.)', re.IGNORECASE)
14+
15+
def __init__(self, vstring: str):
16+
self.vstring = str(vstring)
17+
self.version = self._parse(self.vstring)
18+
19+
def _parse(self, vstring: str) -> List[Union[int, str]]:
20+
"""Parse version string into comparable components."""
21+
components = []
22+
for match in self._component_re.finditer(vstring.lower()):
23+
component = match.group()
24+
if component != '.':
25+
# Try to convert to int, fall back to string
26+
try:
27+
components.append(int(component))
28+
except ValueError:
29+
components.append(component)
30+
return components
31+
32+
def __str__(self) -> str:
33+
return self.vstring
34+
35+
def __repr__(self) -> str:
36+
return f"{self.__class__.__name__}('{self.vstring}')"
37+
38+
def __eq__(self, other) -> bool:
39+
if not isinstance(other, LooseVersion):
40+
other = LooseVersion(str(other))
41+
return self.version == other.version
42+
43+
def __lt__(self, other) -> bool:
44+
if not isinstance(other, LooseVersion):
45+
other = LooseVersion(str(other))
46+
return self.version < other.version
47+
48+
def __hash__(self) -> int:
49+
return hash(tuple(self.version))

0 commit comments

Comments
 (0)