Load multiple config files into a single config dict. The latter config file in the list will override or add the former config file. ``"::"`` (or ``"#"``) in the config keys are interpreted as special characters to go one level further into the nested structures.
(cls, files: PathLike | Sequence[PathLike] | dict, **kwargs: Any)
| 612 | |
| 613 | @classmethod |
| 614 | def load_config_files(cls, files: PathLike | Sequence[PathLike] | dict, **kwargs: Any) -> dict: |
| 615 | """ |
| 616 | Load multiple config files into a single config dict. |
| 617 | The latter config file in the list will override or add the former config file. |
| 618 | ``"::"`` (or ``"#"``) in the config keys are interpreted as special characters to go one level |
| 619 | further into the nested structures. |
| 620 | |
| 621 | Args: |
| 622 | files: path of target files to load, supported postfixes: `.json`, `.yml`, `.yaml`. |
| 623 | if providing a list of files, will merge the content of them. |
| 624 | if providing a string with comma separated file paths, will merge the content of them. |
| 625 | if providing a dictionary, return it directly. |
| 626 | kwargs: other arguments for ``json.load`` or ```yaml.safe_load``, depends on the file format. |
| 627 | """ |
| 628 | if isinstance(files, dict): # already a config dict |
| 629 | return files |
| 630 | parser = ConfigParser(config={}) |
| 631 | if isinstance(files, str) and not Path(files).is_file() and "," in files: |
| 632 | files = files.split(",") |
| 633 | for i in ensure_tuple(files): |
| 634 | config_dict = cls.load_config_file(i, **kwargs) |
| 635 | for k, v in config_dict.items(): |
| 636 | merge_kv(parser, k, v) |
| 637 | |
| 638 | return parser.get() # type: ignore |
| 639 | |
| 640 | @classmethod |
| 641 | def export_config_file(cls, config: dict, filepath: PathLike, fmt: str = "json", **kwargs: Any) -> None: |