From 61189460bc7d2b010b8febc71d598fbd5ee2f1d6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 18 Dec 2025 17:27:35 +0800 Subject: [PATCH] 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 --- teuthology/describe_tests.py | 3 +-- teuthology/suite/__init__.py | 2 +- teuthology/util/strtobool.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 teuthology/util/strtobool.py diff --git a/teuthology/describe_tests.py b/teuthology/describe_tests.py index c0054adc1..80c6f528d 100644 --- a/teuthology/describe_tests.py +++ b/teuthology/describe_tests.py @@ -8,12 +8,11 @@ import sys import yaml import random -from distutils.util import strtobool - from teuthology.exceptions import ParseError from teuthology.suite.build_matrix import \ build_matrix, generate_combinations, _get_matrix from teuthology.suite import util, merge +from teuthology.util.strtobool import strtobool def main(args): try: diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index 8a17cf5f1..5c87197ee 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -7,7 +7,6 @@ import os import random import sys import time -from distutils.util import strtobool import teuthology from teuthology.config import config, YamlConfig @@ -16,6 +15,7 @@ from teuthology.results import UNFINISHED_STATUSES from teuthology.suite.run import Run from teuthology.suite.util import schedule_fail +from teuthology.util.strtobool import strtobool log = logging.getLogger(__name__) diff --git a/teuthology/util/strtobool.py b/teuthology/util/strtobool.py new file mode 100644 index 000000000..b6737e86f --- /dev/null +++ b/teuthology/util/strtobool.py @@ -0,0 +1,14 @@ +def strtobool(val): + """Convert a string representation of truth to true (1) or false (0). + + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ('y', 'yes', 't', 'true', 'on', '1'): + return 1 + elif val in ('n', 'no', 'f', 'false', 'off', '0'): + return 0 + else: + raise ValueError(f"invalid truth value {val!r}") -- 2.47.3