From 14a492f9af6e1dea939220eac115fea44d7917b2 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Tue, 19 Mar 2024 16:36:21 -0400 Subject: [PATCH 1/2] add encoding to load_config --- xscen/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xscen/config.py b/xscen/config.py index cb54dd71..36d1a021 100644 --- a/xscen/config.py +++ b/xscen/config.py @@ -130,7 +130,9 @@ def args_as_str(*args: tuple[Any, ...]) -> tuple[str, ...]: return tuple(new_args) -def load_config(*elements, reset: bool = False, verbose: bool = False): +def load_config( + *elements, reset: bool = False, encoding: str = None, verbose: bool = False +): """Load configuration from given files or key=value pairs. Once all elements are loaded, special sections are dispatched to their module, but only if @@ -151,6 +153,8 @@ def load_config(*elements, reset: bool = False, verbose: bool = False): "key=value" pairs are set last, after all files are being processed. reset: bool If True, the current config is erased before loading files. + encoding: str, optional + The encoding to use when reading files. verbose: bool if True, each element triggers a INFO log line. @@ -184,7 +188,7 @@ def load_config(*elements, reset: bool = False, verbose: bool = False): configfiles = [file] for configfile in configfiles: - with configfile.open() as f: + with configfile.open(encoding=encoding) as f: recursive_update(CONFIG, yaml.safe_load(f)) if verbose: logger.info(f"Updated the config with {configfile}.") From 2fc0e742d942b11c983e335ee2462fbae7e49ed6 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Tue, 19 Mar 2024 16:40:14 -0400 Subject: [PATCH 2/2] upd changes --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index a5df9dfa..284f6eb5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -19,6 +19,7 @@ Internal changes * Updated `ruff` to v0.2.0 and `black` to v24.2.0. * Added more tests. (:pull:`366`, :pull:`367`). * Refactored ``xs.spatial.subset`` into smaller functions. (:pull:`367`). +* An `encoding` argument was added to ``xs.config.load_config``. (:pull:`370`). Bug fixes ^^^^^^^^^