-
Notifications
You must be signed in to change notification settings - Fork 8
/
__init__.py
50 lines (39 loc) · 1.52 KB
/
__init__.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
"""
example run output:
[
{'name': 'REDIS_PASS', 'value': None, 'type': <class 'NoneType'>},
{'name': 'DEBUG', 'value': True, 'type': <class 'bool'>},
{'name': 'PORT', 'value': 8000, 'type': <class 'int'>},
{'name': 'HOST', 'value': '127.0.0.1', 'type': <class 'str'>},
{'name': 'REDIS_ADDRESS', 'value': 'localhost', 'type': <class 'str'>},
{'name': 'MYSQL_DB_HOST', 'value': 'localhost', 'type': <class 'str'>},
{'name': 'MYSQL_DB_USER', 'value': 'root', 'type': <class 'str'>},
{'name': 'MYSQL_DB_PASS', 'value': 'rootpass', 'type': <class 'str'>},
{'name': 'MYSQL_DB_NAME', 'value': 'rootdb', 'type': <class 'str'>},
{'name': 'ES_HOST', 'value': ['127.0.0.1:9200', '127.0.0.2:9200'], 'type': <class 'list'>}
]
"""
from __future__ import annotations
from typing import List, Optional
from pydantic.fields import Field
from fast_tools.config import Config, Json
class MyConfig(Config):
DEBUG: bool
HOST: str
PORT: int
ALIAS_HOST: str = Field(alias="HOST")
REDIS_ADDRESS: str
REDIS_PASS: Optional[str] = None
MYSQL_DB_HOST: str
MYSQL_DB_NAME: str
MYSQL_DB_PASS: str
MYSQL_DB_USER: str
ES_HOST: List[str] = Json.i()
TEST_LIST_INT: List[int] = Json.i()
YML_ES_HOST: Optional[List[str]] = None
YML_TEST_LIST_INT: Optional[List[int]] = None
def main(config_path: str, group: str) -> None:
print(config_path, MyConfig(config_path, group=group))
if __name__ == "__main__":
main("example_config.ini", "test")
main("example_config.yml", "test")