Skip to content

Commit 3930de0

Browse files
authored
Remove deprecated module usage, and remove unnecessary dependency (#28)
1 parent fa60885 commit 3930de0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

kirovy/utils/settings_utils.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import os
77
from collections.abc import Callable
8+
from functools import lru_cache
89

9-
from distutils.util import strtobool
1010
from typing import Any, Type
1111

1212
from kirovy import exceptions
@@ -107,3 +107,28 @@ def run_environment_valid(key: str, value: str) -> None:
107107
key,
108108
f"Not a valid run environment: options={[x.value for x in settings_constants.RunEnvironment]}, {value=}",
109109
)
110+
111+
112+
@lru_cache()
113+
def strtobool(value: str) -> bool:
114+
"""Convert a string to a boolean.
115+
116+
Replicates `<https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool>`_
117+
118+
:param value:
119+
A string, likely from the environment variables.
120+
:return:
121+
A bool matching the ``value`` string, if found.
122+
:raise ValueError:
123+
Raised when the ``value`` string doesn't represent a boolean.
124+
"""
125+
truthy = {"y", "yes", "t", "true", "on", "1"}
126+
falsey = {"n", "no", "f", "false", "off", "0"}
127+
value = value.strip().lower()
128+
129+
if value in truthy:
130+
return True
131+
if value in falsey:
132+
return False
133+
134+
raise ValueError(f'"{value}" does not represent a bool')

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ black==24.*
55
pre-commit==3.*
66
pytest-django==4.*
77
markdown>=3.4.4, <=4.0
8-
setuptools
98
drf-spectacular[sidecar]

0 commit comments

Comments
 (0)