-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
34 lines (22 loc) · 878 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''This module configures application settings from config.yaml'''
from pyaml_env import parse_config
from dotenv import load_dotenv
from helpers.misc import AppSettings, DataFormatter
from helpers.lru_caching import timed_lru_cache
load_dotenv()
@timed_lru_cache(seconds=60)
def get_settings() -> AppSettings:
'''Set up settings in cache for the above lifetime, then refreshes it.'''
return AppSettings(config)
# project settings
config = parse_config('config.yaml')
# set up API prefix
version = config['APP']['PROJECT_VERSION']
config['API'] = {}
config['API']['PREFIX'] = f'/api/v{version.split(".")[0]}'
# set up environment
if config['APP']['ENVIRONMENT'] == 'development':
config['APP']['DEBUG'] = True
config['APP']['TESTING'] = True
# set up database
config['DATABASE']['BASE_URL'] = DataFormatter.postgresql(config['DATABASE']['BASE_URL'])