-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
61 lines (46 loc) · 1.35 KB
/
utils.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import logging
import logging.config
import yaml
import os
from dataclasses import dataclass
from dataclass_wizard import YAMLWizard
def setup_logging(default_path='logging.yaml', default_level=logging.WARN, env_key='LOG_CFG') -> None:
"""Setup logging configuration.
:param default_path:
:param default_level:
:param env_key:
"""
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
else:
logging.basicConfig(level=default_level)
@dataclass()
class ConfigAnalysis:
model_path: str
fake: bool
@dataclass()
class Simulation:
lazy_agents: int
@dataclass
class Config(YAMLWizard):
analysis: ConfigAnalysis
simulation: Simulation
default_config = Config(analysis=ConfigAnalysis('CaseStudies/bundles/fluidTrustCaseStudy-Simplified/', False),
simulation=Simulation(0))
def get_config(default_path='config.yaml', env_key='FLUIDTRUST_CFG') -> Config:
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
return Config.from_yaml_file(path)
else:
return default_config
CONFIG = get_config()