feat: add preset resolver

This commit is contained in:
2023-03-21 20:19:27 +03:00
parent 81c704576a
commit 265c80f082
12 changed files with 183 additions and 126 deletions
+28
View File
@@ -0,0 +1,28 @@
import importlib
__all__ = (
"reflect",
"merge_dicts",
)
def reflect(value: str):
if ":" in value:
module_name, item_name = value.split(":")
else:
module_name, item_name = "builtins", value
module = importlib.import_module(module_name)
return getattr(module, item_name)
def merge_dicts(target, enhancer):
for key, val in enhancer.items():
if key not in target:
target[key] = val
continue
if isinstance(val, dict):
merge_dicts(target[key], val)
else:
target[key] = val
return target