From 13f1d2cfb63a6971d6be852142a8971461b6114f Mon Sep 17 00:00:00 2001 From: mikedarcy Date: Wed, 13 Mar 2024 11:47:38 -0700 Subject: [PATCH] Remove dependency on deprecated distutils.util.strtobool function. --- bdbag/__init__.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bdbag/__init__.py b/bdbag/__init__.py index 75659d8..fac44f7 100644 --- a/bdbag/__init__.py +++ b/bdbag/__init__.py @@ -21,7 +21,6 @@ import mimetypes import shutil from datetime import datetime -from distutils.util import strtobool if sys.version_info >= (3,8): from importlib.metadata import distribution, PackageNotFoundError else: @@ -81,8 +80,21 @@ mimetypes.init() -def stob(string): - return bool(strtobool(str(string))) +# Based on strtobool function from distutils which is now deprecated. +def stob(val): + """Convert a string representation of truth to boolean True or False + + 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 = str(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!r}") def get_typed_exception(e):