From e978121d58b074c788b19fcbdadd5a5a9ec1fd06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jotag=C3=AA=20Sales?= Date: Wed, 26 Dec 2018 16:23:16 -0200 Subject: [PATCH] configure app from object by path string --- sanic/config.py | 4 ++++ setup.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sanic/config.py b/sanic/config.py index 0a53a607..d3b03f4f 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -1,6 +1,8 @@ import os import types +import import_string + from sanic.exceptions import PyFileError @@ -111,6 +113,8 @@ class Config(dict): :param obj: an object holding the configuration """ + if isinstance(obj, str): + obj = import_string(obj) for key in dir(obj): if key.isupper(): self[key] = getattr(obj, key) diff --git a/setup.py b/setup.py index 37164336..87de21fb 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ Sanic import codecs import os import re -from distutils.errors import DistutilsPlatformError + from distutils.util import strtobool from setuptools import setup @@ -63,6 +63,7 @@ requirements = [ 'aiofiles>=0.3.0', 'websockets>=6.0,<7.0', 'multidict>=4.0,<5.0', + 'import-string>=0.1.0' ] if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON")