Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated distutils.strtobool #2628

Merged
merged 2 commits into from Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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:
Expand Down Expand Up @@ -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 "
Expand Down
25 changes: 21 additions & 4 deletions setup.py
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down