diff --git a/kirovy/utils/settings_utils.py b/kirovy/utils/settings_utils.py index 19b6299..2a5dbd8 100644 --- a/kirovy/utils/settings_utils.py +++ b/kirovy/utils/settings_utils.py @@ -5,8 +5,8 @@ import os from collections.abc import Callable +from functools import lru_cache -from distutils.util import strtobool from typing import Any, Type from kirovy import exceptions @@ -107,3 +107,28 @@ def run_environment_valid(key: str, value: str) -> None: key, f"Not a valid run environment: options={[x.value for x in settings_constants.RunEnvironment]}, {value=}", ) + + +@lru_cache() +def strtobool(value: str) -> bool: + """Convert a string to a boolean. + + Replicates ``_ + + :param value: + A string, likely from the environment variables. + :return: + A bool matching the ``value`` string, if found. + :raise ValueError: + Raised when the ``value`` string doesn't represent a boolean. + """ + truthy = {"y", "yes", "t", "true", "on", "1"} + falsey = {"n", "no", "f", "false", "off", "0"} + value = value.strip().lower() + + if value in truthy: + return True + if value in falsey: + return False + + raise ValueError(f'"{value}" does not represent a bool') diff --git a/requirements-dev.txt b/requirements-dev.txt index 6c5647f..c6f3814 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,5 +5,4 @@ black==24.* pre-commit==3.* pytest-django==4.* markdown>=3.4.4, <=4.0 -setuptools drf-spectacular[sidecar]