-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.py
More file actions
93 lines (69 loc) · 2.26 KB
/
Copy pathconfig.py
File metadata and controls
93 lines (69 loc) · 2.26 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
from functools import lru_cache
import tomllib
from pydantic_settings import BaseSettings, SettingsConfigDict
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_ENV = os.environ.get("APP_ENV", "development")
def get_version() -> str:
with open("pyproject.toml", "rb") as f:
return tomllib.load(f)["tool"]["poetry"]["version"]
class BaseConfig(BaseSettings):
"""Base configuration."""
IS_API: bool = False
ENV: str = "base"
APP_NAME: str = "Simple Flask App"
SECRET_KEY: str
SQLALCHEMY_TRACK_MODIFICATIONS: bool = False
WTF_CSRF_ENABLED: bool = False
VERSION: str = get_version()
# Mail config
MAIL_SERVER: str
MAIL_PORT: int
MAIL_USE_TLS: bool
MAIL_USE_SSL: bool
MAIL_USERNAME: str
MAIL_PASSWORD: str
MAIL_DEFAULT_SENDER: str
# Super admin
ADMIN_USERNAME: str
ADMIN_EMAIL: str
ADMIN_PASSWORD: str
# Pagination
DEFAULT_PAGE_SIZE: int
PAGE_LINKS_NUMBER: int
# API
JWT_SECRET: str
ACCESS_TOKEN_EXPIRE_MINUTES: int
@staticmethod
def configure(app):
# Implement this method to do further configuration on your app.
pass
model_config = SettingsConfigDict(
extra="allow",
env_file=("project.env", ".env.dev", ".env"),
)
class DevelopmentConfig(BaseConfig):
"""Development configuration."""
DEBUG: bool = True
ALCHEMICAL_DATABASE_URL: str = "sqlite:///" + os.path.join(BASE_DIR, "database-dev.sqlite3")
class TestingConfig(BaseConfig):
"""Testing configuration."""
TESTING: bool = True
PRESERVE_CONTEXT_ON_EXCEPTION: bool = False
ALCHEMICAL_DATABASE_URL: str = "sqlite:///" + os.path.join(BASE_DIR, "database-test.sqlite3")
class ProductionConfig(BaseConfig):
"""Production configuration."""
ALCHEMICAL_DATABASE_URL: str = os.environ.get(
"DATABASE_URL", "sqlite:///" + os.path.join(BASE_DIR, "database.sqlite3")
)
WTF_CSRF_ENABLED: bool = True
@lru_cache
def config(name: str = APP_ENV) -> DevelopmentConfig | TestingConfig | ProductionConfig:
CONF_MAP = dict(
development=DevelopmentConfig,
testing=TestingConfig,
production=ProductionConfig,
)
configuration = CONF_MAP[name]()
configuration.ENV = name
return configuration