New aproach for uploading sanic app config.
This commit is contained in:
parent
ae124204dd
commit
8a51b97cb4
21
sanic/app.py
21
sanic/app.py
@ -1460,25 +1460,28 @@ class Sanic:
|
||||
# -------------------------------------------------------------------- #
|
||||
def update_config(self, config: Union[bytes, str, dict, Any]):
|
||||
"""Update app.config.
|
||||
|
||||
|
||||
Note:: only upper case settings are considered.
|
||||
|
||||
|
||||
You can upload app config by providing path to py file holding settings.
|
||||
|
||||
|
||||
# /some/py/file
|
||||
A = 1
|
||||
B = 2
|
||||
|
||||
app.update_config("/some/py/file")
|
||||
|
||||
|
||||
app.update_config("${some}/py/file")
|
||||
|
||||
Yes you can put environment variable here, but they must be provided in format: ${some_env_var},
|
||||
and mark that $some_env_var is treated as plain string.
|
||||
|
||||
You can upload app config by providing dict holding settings.
|
||||
|
||||
|
||||
d = {"A": 1, "B": 2}
|
||||
app.update_config(d)
|
||||
|
||||
|
||||
You can upload app config by providing any object holding settings,
|
||||
but in such case config.__dict__ will be used as dict holding settings.
|
||||
|
||||
|
||||
class C:
|
||||
A = 1
|
||||
B = 2
|
||||
|
@ -81,25 +81,28 @@ class Config(dict):
|
||||
|
||||
def update_config(self, config: Union[bytes, str, dict, Any]):
|
||||
"""Update app.config.
|
||||
|
||||
|
||||
Note only upper case settings are considered.
|
||||
|
||||
|
||||
You can upload app config by providing path to py file holding settings.
|
||||
|
||||
|
||||
# /some/py/file
|
||||
A = 1
|
||||
B = 2
|
||||
|
||||
config.update_config("/some/py/file")
|
||||
|
||||
|
||||
config.update_config("${some}/py/file")
|
||||
|
||||
Yes you can put environment variable here, but they must be provided in format: ${some_env_var},
|
||||
and mark that $some_env_var is treated as plain string.
|
||||
|
||||
You can upload app config by providing dict holding settings.
|
||||
|
||||
|
||||
d = {"A": 1, "B": 2}
|
||||
config.update_config(d)
|
||||
|
||||
|
||||
You can upload app config by providing any object holding settings,
|
||||
but in such case config.__dict__ will be used as dict holding settings.
|
||||
|
||||
|
||||
class C:
|
||||
A = 1
|
||||
B = 2
|
||||
@ -139,12 +142,14 @@ def strtobool(val):
|
||||
|
||||
def load_module_from_file_location(*args, **kwargs):
|
||||
"""Returns loaded module provided as a file path.
|
||||
|
||||
|
||||
:param args: look for importlib.util.spec_from_file_location parameters specification
|
||||
:param kwargs: look for importlib.util.spec_from_file_location parameters specification
|
||||
|
||||
|
||||
So for example You can:
|
||||
|
||||
some_module = load_module_from_file_location("some_module_name", "/some/path/${some_env_var})
|
||||
|
||||
Yes you can put environment variable here, but they must be provided in format: ${some_env_var},
|
||||
and mark that $some_env_var is treated as plain string."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user