| # marble/core/utils.py | |
| import importlib | |
| def get_obj_from_str(string, reload=False): | |
| module, cls = string.rsplit(".", 1) | |
| if reload: | |
| module_imp = importlib.import_module(module) | |
| importlib.reload(module_imp) | |
| return getattr(importlib.import_module(module, package=None), cls) | |
| def instantiate_from_config(config): | |
| if not "class_path" in config: | |
| raise KeyError("Expected key `class_path` to instantiate.") | |
| return get_obj_from_str(config["class_path"])(**config.get("init_args", dict())) | |