Skip to content

Commit 6118946

Browse files
committed
teuthology: implement strtobool and use it
The distutils module was deprecated in Python 3.10 and removed in Python 3.12. This commit replaces the deprecated distutils.utils.strtobool imports with strtobool in teuthology.util module. Changes: - Add strtobool.py to teuthology/util - Replace distutils.util.strtobool with teuthology.util.strtobool.strtobool Signed-off-by: Kefu Chai <tchaikov@gmail.com>
1 parent 90ad9ba commit 6118946

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
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/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}")

0 commit comments

Comments
 (0)