From 6803b0052e80be6147d0f1aad7bff0b1d895c16c Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 16 Dec 2022 00:37:16 +0000 Subject: [PATCH 1/2] Remove deprecated strtobool --- sanic/server/loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/server/loop.py b/sanic/server/loop.py index d9be109d95..d41e605ecc 100644 --- a/sanic/server/loop.py +++ b/sanic/server/loop.py @@ -1,11 +1,11 @@ import asyncio import sys -from distutils.util import strtobool from os import getenv from sanic.compat import OS_IS_WINDOWS from sanic.log import error_logger +from sanic.utils import str_to_bool def try_use_uvloop() -> None: @@ -35,7 +35,7 @@ def try_use_uvloop() -> None: ) return - uvloop_install_removed = strtobool(getenv("SANIC_NO_UVLOOP", "no")) + uvloop_install_removed = str_to_bool(getenv("SANIC_NO_UVLOOP", "no")) if uvloop_install_removed: error_logger.info( "You are requesting to run Sanic using uvloop, but the " From 0a1a1d24d16b21f92f704e0dde04b890b7ac4051 Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 16 Dec 2022 09:38:37 +0900 Subject: [PATCH 2/2] Remove deprecated in setup.py --- setup.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 9ece8cb539..a8bd760a58 100644 --- a/setup.py +++ b/setup.py @@ -6,8 +6,6 @@ import re import sys -from distutils.util import strtobool - from setuptools import find_packages, setup from setuptools.command.test import test as TestCommand @@ -37,6 +35,25 @@ def open_local(paths, mode="r", encoding="utf8"): return codecs.open(path, mode, encoding) +def str_to_bool(val: str) -> bool: + val = val.lower() + if val in { + "y", + "yes", + "yep", + "yup", + "t", + "true", + "on", + "enable", + "enabled", + "1", + }: + return True + elif val in {"n", "no", "f", "false", "off", "disable", "disabled", "0"}: + return False + else: + raise ValueError(f"Invalid truth value {val}") with open_local(["sanic", "__version__.py"], encoding="latin1") as fp: try: @@ -131,13 +148,13 @@ def open_local(paths, mode="r", encoding="utf8"): all_require = list(set(dev_require + docs_require)) -if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): +if str_to_bool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON") requirements.remove(ujson) tests_require.remove(types_ujson) # 'nt' means windows OS -if strtobool(os.environ.get("SANIC_NO_UVLOOP", "no")): +if str_to_bool(os.environ.get("SANIC_NO_UVLOOP", "no")): print("Installing without uvLoop") requirements.remove(uvloop)