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

Drop dependency on disutils #1544

Merged
merged 4 commits into from
Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions sanic/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import types

from distutils.util import strtobool

from sanic.exceptions import PyFileError


Expand Down Expand Up @@ -127,6 +125,23 @@ def load_environment_vars(self, prefix=SANIC_PREFIX):
self[config_key] = float(v)
except ValueError:
try:
self[config_key] = bool(strtobool(v))
self[config_key] = strtobool(v)
except ValueError:
self[config_key] = v


def strtobool(val):
"""
This function was borrowed from distutils.utils. While distutils
is part of stdlib, it feels odd to use distutils in main application code.
The function was modified to walk its talk and actually return bool
and not int.
"""
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,))