Skip to content

Commit

Permalink
Drop dependency on disutils (#1544)
Browse files Browse the repository at this point in the history
* Drop dependency on distutils

While distutils is part of stdlib, it feels odd to use distutils in main application code.

I personally use a (lean)[https://hub.docker.com/r/haizaar/python-minimal/tags] Python distribution for running my applications that does not include distutils.

* Flake8 fixes

* "black" fixes

* strtobool should actually return bool
  • Loading branch information
haizaar authored and sjsadowski committed Apr 2, 2019
1 parent 3bedb22 commit 0b47692
Showing 1 changed file with 18 additions and 3 deletions.
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,))

0 comments on commit 0b47692

Please sign in to comment.