From 17f828cef2d8ce5078278d12510c3ba8c16ad5a8 Mon Sep 17 00:00:00 2001 From: JSKenyon Date: Thu, 28 Mar 2024 12:24:02 +0200 Subject: [PATCH 1/5] Attempt at making substitutions work inside dicts and lists. --- scabha/evaluator.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scabha/evaluator.py b/scabha/evaluator.py index 42ac41e9..7a6b7712 100644 --- a/scabha/evaluator.py +++ b/scabha/evaluator.py @@ -625,6 +625,31 @@ def evaluate_dict(self, params: Dict[str, Any], params_out[name] = new_value if corresponding_ns: corresponding_ns[name] = new_value + elif isinstance(value, (dict, DictConfig)): + params_out[name] = self.evaluate_dict( + value, + corresponding_ns, + defaults, + sublocation, + raise_substitution_errors, + recursive, + verbose + ) + elif isinstance(value, list): + params_out[name] = type(value)( + [ + self.evaluate_dict( + {"dummy": v}, + corresponding_ns, + defaults, + sublocation, + raise_substitution_errors, + recursive, + verbose + )["dummy"] for v in value + ] + ) + return params_out From 420649817a7103a18c5ff699072df1d4a7de4765 Mon Sep 17 00:00:00 2001 From: JSKenyon Date: Thu, 28 Mar 2024 15:49:08 +0200 Subject: [PATCH 2/5] Address comments. --- scabha/evaluator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scabha/evaluator.py b/scabha/evaluator.py index 7a6b7712..1dfd84a4 100644 --- a/scabha/evaluator.py +++ b/scabha/evaluator.py @@ -635,18 +635,18 @@ def evaluate_dict(self, params: Dict[str, Any], recursive, verbose ) - elif isinstance(value, list): + elif isinstance(value, (list, ListConfig)): params_out[name] = type(value)( [ - self.evaluate_dict( - {"dummy": v}, + ele for ele in self.evaluate_dict( + {f"[{i}]": v for i, v in enumerate(value)}, corresponding_ns, defaults, sublocation, raise_substitution_errors, recursive, verbose - )["dummy"] for v in value + ).values() ] ) From a7447848011a640a7fa8cb36355ce87c5bcc239a Mon Sep 17 00:00:00 2001 From: JSKenyon Date: Thu, 28 Mar 2024 16:29:58 +0200 Subject: [PATCH 3/5] Slightly tidier solution. --- scabha/evaluator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scabha/evaluator.py b/scabha/evaluator.py index 1dfd84a4..8dde3d15 100644 --- a/scabha/evaluator.py +++ b/scabha/evaluator.py @@ -638,7 +638,7 @@ def evaluate_dict(self, params: Dict[str, Any], elif isinstance(value, (list, ListConfig)): params_out[name] = type(value)( [ - ele for ele in self.evaluate_dict( + *self.evaluate_dict( {f"[{i}]": v for i, v in enumerate(value)}, corresponding_ns, defaults, From 746e8aebd38349e68ed61e46b7efe77f0a79925c Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Tue, 2 Apr 2024 21:38:51 +0200 Subject: [PATCH 4/5] update sublocation, and honour recursive argument --- pyproject.toml | 2 +- scabha/evaluator.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 306a7a52..8fb29f52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "stimela" -version = "2.0rc17" +version = "2.0rc18" description = "Framework for system agnostic pipelines for (not just) radio interferometry" authors = ["Sphesihle Makhathini ", "Oleg Smirnov and RATT "] readme = "README.rst" diff --git a/scabha/evaluator.py b/scabha/evaluator.py index 8dde3d15..ee19cc8c 100644 --- a/scabha/evaluator.py +++ b/scabha/evaluator.py @@ -580,7 +580,7 @@ def evaluate_dict(self, params: Dict[str, Any], defaults: Dict[str, Any] = {}, sublocation = [], raise_substitution_errors: bool = True, - recursive: bool = False, + recursive: bool = True, verbose: bool = False): params_out = params for name, value in list(params.items()): @@ -625,27 +625,27 @@ def evaluate_dict(self, params: Dict[str, Any], params_out[name] = new_value if corresponding_ns: corresponding_ns[name] = new_value - elif isinstance(value, (dict, DictConfig)): + elif isinstance(value, (dict, DictConfig)) and recursive: params_out[name] = self.evaluate_dict( value, corresponding_ns, defaults, - sublocation, - raise_substitution_errors, - recursive, - verbose + sublocation=sublocation + [name], + raise_substitution_errors=raise_substitution_errors, + recursive=True, + verbose=verbose ) - elif isinstance(value, (list, ListConfig)): + elif isinstance(value, (list, ListConfig)) and recursive: params_out[name] = type(value)( [ *self.evaluate_dict( {f"[{i}]": v for i, v in enumerate(value)}, corresponding_ns, defaults, - sublocation, - raise_substitution_errors, - recursive, - verbose + sublocation=sublocation + [name], + raise_substitution_errors=raise_substitution_errors, + recursive=True, + verbose=verbose ).values() ] ) From 1365cbf756338e5225af2f6e7fbb0ef9a5390c9b Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Tue, 2 Apr 2024 23:08:22 +0200 Subject: [PATCH 5/5] enable propgation from loggers that disable handlers, needed for nested recipes --- stimela/stimelogging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stimela/stimelogging.py b/stimela/stimelogging.py index 0a6b50fa..e8cc39ab 100644 --- a/stimela/stimelogging.py +++ b/stimela/stimelogging.py @@ -291,6 +291,7 @@ def update_file_logger(log: logging.Logger, logopts: DictConfig, nesting: int = setup_file_logger(log, path, level=logopts.level, symlink=logopts.symlink) else: disable_file_logger(log) + log.propagate = True def get_logfile_dir(log: logging.Logger):