You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
994 B
Python
48 lines
994 B
Python
2 years ago
|
import os
|
||
|
import pathlib
|
||
|
from functools import lru_cache
|
||
|
|
||
|
|
||
|
class BaseConfig:
|
||
|
BASE_DIR: pathlib.Path = pathlib.Path(__file__).parent.parent
|
||
|
|
||
|
DATABASE_URL: str = os.environ.get(
|
||
|
"DATABASE_URL", f"sqlite:///{BASE_DIR}/db.sqlite3"
|
||
|
)
|
||
|
DATABASE_CONNECT_DICT: dict = {}
|
||
|
|
||
|
CELERY_BROKER_URL: str = os.environ.get(
|
||
|
"CELERY_BROKER_URL", "redis://127.0.0.1:6379/0"
|
||
|
)
|
||
|
CELERY_RESULT_BACKEND: str = os.environ.get(
|
||
|
"CELERY_RESULT_BACKEND", "redis://127.0.0.1:6379/0"
|
||
|
)
|
||
|
|
||
|
|
||
|
class DevelopmentConfig(BaseConfig):
|
||
|
pass
|
||
|
|
||
|
|
||
|
class ProductionConfig(BaseConfig):
|
||
|
pass
|
||
|
|
||
|
|
||
|
class TestingConfig(BaseConfig):
|
||
|
pass
|
||
|
|
||
|
|
||
|
@lru_cache()
|
||
|
def get_settings():
|
||
|
config_cls_dict = {
|
||
|
"development": DevelopmentConfig,
|
||
|
"production": ProductionConfig,
|
||
|
"testing": TestingConfig,
|
||
|
}
|
||
|
|
||
|
config_name = os.environ.get("FASTAPI_CONFIG", "development")
|
||
|
config_cls = config_cls_dict[config_name]
|
||
|
return config_cls()
|
||
|
|
||
|
|
||
|
settings = get_settings()
|