Update yaml configs

This commit is contained in:
D-X-Y
2021-06-10 21:53:22 +08:00
parent 1a7440d2af
commit 9bf0fa5f04
21 changed files with 410 additions and 178 deletions

View File

@@ -62,18 +62,25 @@ def call_by_yaml(path, *args, **kwargs) -> object:
def nested_call_by_dict(config: Union[Dict[Text, Any], Any], *args, **kwargs) -> object:
"""Similar to `call_by_dict`, but differently, the args may contain another dict needs to be called."""
if not has_key_words(config):
if isinstance(config, list):
return [nested_call_by_dict(x) for x in config]
elif isinstance(config, tuple):
return (nested_call_by_dict(x) for x in config)
elif not isinstance(config, dict):
return config
module = get_module_by_module_path(config["module_path"])
cls_or_func = getattr(module, config[CLS_FUNC_KEY])
args = tuple(list(config["args"]) + list(args))
kwargs = {**config["kwargs"], **kwargs}
# check whether there are nested special dict
new_args = [nested_call_by_dict(x) for x in args]
new_kwargs = {}
for key, x in kwargs.items():
new_kwargs[key] = nested_call_by_dict(x)
return cls_or_func(*new_args, **new_kwargs)
elif not has_key_words(config):
return {key: nested_call_by_dict(x) for x, key in config.items()}
else:
module = get_module_by_module_path(config["module_path"])
cls_or_func = getattr(module, config[CLS_FUNC_KEY])
args = tuple(list(config["args"]) + list(args))
kwargs = {**config["kwargs"], **kwargs}
# check whether there are nested special dict
new_args = [nested_call_by_dict(x) for x in args]
new_kwargs = {}
for key, x in kwargs.items():
new_kwargs[key] = nested_call_by_dict(x)
return cls_or_func(*new_args, **new_kwargs)
def nested_call_by_yaml(path, *args, **kwargs) -> object: