Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of deprecated python 3.12 strtobool #7900

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion requirements-min.txt
Original file line number Diff line number Diff line change
@@ -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
Loading