diff --git a/monai/utils/misc.py b/monai/utils/misc.py index ab9fe259aa..96a59e1b35 100644 --- a/monai/utils/misc.py +++ b/monai/utils/misc.py @@ -24,7 +24,6 @@ import warnings from ast import literal_eval from collections.abc import Callable, Iterable, Sequence -from distutils.util import strtobool from math import log10 from pathlib import Path from typing import TYPE_CHECKING, Any, TypeVar, cast, overload @@ -78,6 +77,25 @@ "run_cmd", ] + +def _strtobool(val: str) -> bool: + """ + Replaces deprecated (pre python 3.12) + distutils strtobool function. + + 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 True + elif val in ("n", "no", "f", "false", "off", "0"): + return False + else: + raise ValueError(f"invalid truth value {val}") + + _seed = None _flag_deterministic = torch.backends.cudnn.deterministic _flag_cudnn_benchmark = torch.backends.cudnn.benchmark @@ -400,7 +418,7 @@ def _parse_var(s): d[key] = literal_eval(value) except ValueError: try: - d[key] = bool(strtobool(str(value))) + d[key] = bool(_strtobool(str(value))) except ValueError: d[key] = value return d diff --git a/requirements-min.txt b/requirements-min.txt index ad0bb1ef20..a091ef0568 100644 --- a/requirements-min.txt +++ b/requirements-min.txt @@ -1,5 +1,6 @@ # Requirements for minimal tests -r requirements.txt -setuptools>=50.3.0,<66.0.0,!=60.6.0 +setuptools>=50.3.0,<66.0.0,!=60.6.0 ; python_version < "3.12" +setuptools>=70.2.0; python_version >= "3.12" coverage>=5.5 parameterized