From 89f38f6da5af41da736f361b81aad499bd9acc46 Mon Sep 17 00:00:00 2001 From: Andreas Tille Date: Sat, 23 Nov 2024 23:12:24 +0100 Subject: [PATCH] Replace distutils which is removed in Python3.12 Bug-Debian: https://bugs.debian.org/1059666 Last-Update: Thu, 08 Feb 2024 20:33:03 +0100 --- hug/api.py | 19 ++++++++++++++++++- hug/types.py | 4 ++-- setup.py | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hug/api.py b/hug/api.py index 790f0385..75af6df8 100644 --- a/hug/api.py +++ b/hug/api.py @@ -24,7 +24,24 @@ import asyncio import sys from collections import OrderedDict, namedtuple -from distutils.util import strtobool + +# Own implementation of distutils.util.strtobool +# See PEP632 for more info. +def strtobool(val) -> bool: + """Convert a string representation of truth to 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 = 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("invalid truth value %r" % (val,)) + from functools import partial from itertools import chain from types import ModuleType diff --git a/hug/types.py b/hug/types.py index acb36608..498ee50c 100644 --- a/hug/types.py +++ b/hug/types.py @@ -23,7 +23,7 @@ import uuid as native_uuid from decimal import Decimal -from distutils.version import LooseVersion +from packaging.version import Version import hug._empty as empty from hug import introspect @@ -36,7 +36,7 @@ from marshmallow import ValidationError MARSHMALLOW_MAJOR_VERSION = getattr( - marshmallow, "__version_info__", LooseVersion(marshmallow.__version__).version + marshmallow, "__version_info__", Version(marshmallow.__version__).release )[0] except ImportError: # Just define the error that is never raised so that Python does not complain. diff --git a/setup.py b/setup.py index ab302c20..b26e09df 100755 --- a/setup.py +++ b/setup.py @@ -96,7 +96,7 @@ def list_modules(dirname): entry_points={"console_scripts": ["hug = hug:development_runner.hug.interface.cli"]}, packages=["hug"], requires=["falcon", "requests"], - install_requires=["falcon==2.0.0", "requests"], + install_requires=["falcon==2.0.0", "requests", "packaging"], tests_require=["pytest", "marshmallow"], ext_modules=ext_modules, cmdclass=cmdclass,