From 4988cac5258d4067aa8754ac40a3f539074f5774 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 16 Oct 2023 12:11:13 +0200 Subject: [PATCH] fix: remove deprecated distutils (#604) --- dockertidy/utils.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dockertidy/utils.py b/dockertidy/utils.py index a9cb1c8..57aad56 100644 --- a/dockertidy/utils.py +++ b/dockertidy/utils.py @@ -1,7 +1,29 @@ #!/usr/bin/env python3 """Global utility methods and classes.""" -from distutils.util import strtobool + +def strtobool(value): + """Convert a string representation of truth to true or false.""" + + _map = { + "y": True, + "yes": True, + "t": True, + "true": True, + "on": True, + "1": True, + "n": False, + "no": False, + "f": False, + "false": False, + "off": False, + "0": False + } + + try: + return _map[str(value).lower()] + except KeyError as err: + raise ValueError(f'"{value}" is not a valid bool value') from err def to_bool(string):