-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.py
41 lines (30 loc) · 933 Bytes
/
schema.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
from typing import Any
import yaml
from classes import Expandable
from context import context
faker_config: dict[str, Any] = {}
params: dict[str, Any] = {}
struct: dict[str, Any] = {}
env = Expandable()
def load_schema(file_name=None):
global faker_config, params, struct, env
if not file_name:
file_name = "sample_schema.yaml"
with open(file_name) as f:
schema: dict = yaml.load(f, yaml.FullLoader)
faker_config = schema.get("faker", {})
params = schema["params"]
struct = schema["struct"]
def _make_env(obj: Expandable, dict_: dict):
if not dict_:
return
for k, v in dict_.items():
if type(v) is dict:
o = Expandable()
_make_env(o, v)
obj.set(k, o)
else:
obj.set(k, v)
env_dict = schema.get("env", {})
_make_env(env, env_dict)
context["env"] = env