(config, target="_ltp_target_", partial="_ltp_partial_")
| 25 | |
| 26 | |
| 27 | def instantiate(config, target="_ltp_target_", partial="_ltp_partial_"): |
| 28 | if isinstance(config, dict) and target in config: |
| 29 | target_path = config.get(target) |
| 30 | target_callable = find_callable(target_path) |
| 31 | |
| 32 | is_partial = config.get(partial, False) |
| 33 | target_args = { |
| 34 | key: instantiate(value) |
| 35 | for key, value in config.items() |
| 36 | if key not in [target, partial] |
| 37 | } |
| 38 | |
| 39 | if is_partial: |
| 40 | return functools.partial(target_callable, **target_args) |
| 41 | else: |
| 42 | return target_callable(**target_args) |
| 43 | elif isinstance(config, dict): |
| 44 | return {key: instantiate(value) for key, value in config.items()} |
| 45 | else: |
| 46 | return config |
| 47 | |
| 48 | |
| 49 | def instantiate_omega(config, target="_ltp_target_", partial="_ltp_partial_"): |
no test coverage detected