Skip to content

Commit 4c55b65

Browse files
authored
[Setup] Remove distutils imports (#2836)
1 parent d561115 commit 4c55b65

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

torchrl/_utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import warnings
1919
from contextlib import nullcontext
2020
from copy import copy
21-
from distutils.util import strtobool
2221
from functools import wraps
2322
from importlib import import_module
2423
from typing import Any, Callable, cast, TypeVar
@@ -35,6 +34,21 @@
3534
except ImportError:
3635
from torch._dynamo import is_compiling
3736

37+
38+
def strtobool(val: Any) -> bool:
39+
"""Convert a string representation of truth to a boolean.
40+
41+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'.
42+
Raises ValueError if 'val' is anything else.
43+
"""
44+
val = val.lower()
45+
if val in ("y", "yes", "t", "true", "on", "1"):
46+
return True
47+
if val in ("n", "no", "f", "false", "off", "0"):
48+
return False
49+
raise ValueError(f"Invalid truth value {val!r}")
50+
51+
3852
LOGGING_LEVEL = os.environ.get("RL_LOGGING_LEVEL", "INFO")
3953
logger = logging.getLogger("torchrl")
4054
logger.setLevel(getattr(logging, LOGGING_LEVEL))

0 commit comments

Comments
 (0)