-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
38 lines (31 loc) · 1.18 KB
/
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
35
36
37
38
from logging import Logger
from pathlib import Path
from toml import load
from logger import global_logger
"""
This file will load the server configuration depending on the environment settings in the
pyproject.toml.
Following settings are possible:
- "dev": development environment, this will load config.dev.toml
- "prod": production environment, this will load config.prod.toml
- "test": testing environment, this will load config.test.toml
"""
logger: Logger = global_logger()
try:
pyproject_toml_path: str = str(Path(__file__).resolve().parent / "pyproject.toml")
pyproject_config = load(pyproject_toml_path)
except FileNotFoundError:
logger.error(
"File 'pyproject.toml' not found in same directory as config.py. This error is fatal,"
" please fix."
)
raise
env = pyproject_config["monntpy"]["env"]
try:
config_toml_path: str = str(Path(__file__).resolve().parent / f"config.{env}.toml")
server_config = load(config_toml_path)
except FileNotFoundError:
logger.error(
f"config.{env}.toml not found in same directory as config.py. This error is fatal,"
" please fix either the setting in pyproject.toml or the filesystem."
)