Load the key, value pairs from config_dict to opt, overriding existing values in opt if there is any.
(opt, config_dict)
| 7 | |
| 8 | |
| 9 | def load_config_dict_to_opt(opt, config_dict): |
| 10 | """ |
| 11 | Load the key, value pairs from config_dict to opt, overriding existing values in opt |
| 12 | if there is any. |
| 13 | """ |
| 14 | if not isinstance(config_dict, dict): |
| 15 | raise TypeError("Config must be a Python dictionary") |
| 16 | for k, v in config_dict.items(): |
| 17 | k_parts = k.split('.') |
| 18 | pointer = opt |
| 19 | for k_part in k_parts[:-1]: |
| 20 | if k_part not in pointer: |
| 21 | pointer[k_part] = {} |
| 22 | pointer = pointer[k_part] |
| 23 | assert isinstance(pointer, dict), "Overriding key needs to be inside a Python dict." |
| 24 | ori_value = pointer.get(k_parts[-1]) |
| 25 | pointer[k_parts[-1]] = v |
| 26 | if ori_value: |
| 27 | logger.warning(f"Overrided {k} from {ori_value} to {pointer[k_parts[-1]]}") |
| 28 | |
| 29 | def load_opt_from_config_file(conf_file): |
| 30 | """ |
no test coverage detected