Read and merge a list of config files.
(
files: list[str | IO[str]],
list_values: bool = True,
ignore_package_defaults: bool = False,
ignore_user_options: bool = False,
)
| 51 | |
| 52 | |
| 53 | def read_config_files( |
| 54 | files: list[str | IO[str]], |
| 55 | list_values: bool = True, |
| 56 | ignore_package_defaults: bool = False, |
| 57 | ignore_user_options: bool = False, |
| 58 | ) -> ConfigObj: |
| 59 | """Read and merge a list of config files.""" |
| 60 | |
| 61 | if ignore_package_defaults: |
| 62 | config = ConfigObj() |
| 63 | else: |
| 64 | config = create_default_config(list_values=list_values) |
| 65 | |
| 66 | if ignore_user_options: |
| 67 | return config |
| 68 | |
| 69 | _files = copy(files) |
| 70 | while _files: |
| 71 | _file = _files.pop(0) |
| 72 | _config = read_config_file(_file, list_values=list_values) |
| 73 | |
| 74 | if _config is not None: |
| 75 | config.merge(_config) |
| 76 | config.filename = _config.filename |
| 77 | |
| 78 | return config |
| 79 | |
| 80 | |
| 81 | def create_default_config(list_values: bool = True) -> ConfigObj: |
no test coverage detected