Skip to content

Commit

Permalink
Remove dependency on deprecated distutils.util.strtobool function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedarcy committed Mar 13, 2024
1 parent 15f22fb commit 13f1d2c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bdbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 13f1d2c

Please sign in to comment.