From 363ca809cce8255c99553389dceedc12fb72dba9 Mon Sep 17 00:00:00 2001 From: Benedikt Volkel Date: Thu, 3 Oct 2024 14:49:48 +0200 Subject: [PATCH] [Config] Use one global config A global config key 'config' can be used to pass a dictionary which will be available everywhere. Per step, it can be extended or changed by passing a dict in that stage, also using the key 'config' --- src/o2tuner/config.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/o2tuner/config.py b/src/o2tuner/config.py index 5dcf21a..77f5889 100644 --- a/src/o2tuner/config.py +++ b/src/o2tuner/config.py @@ -28,6 +28,8 @@ class WorkDir: CONFIG_STAGES_KEYS = [CONFIG_STAGES_USER_KEY, CONFIG_STAGES_OPTIMISATION_KEY] +CONFIG_STATIC_CONFIG_KEY = "config" + def get_work_dir(): """ @@ -127,6 +129,10 @@ def setup(self): print(f" - {CONFIG_STAGES_USER_KEY}\n - {CONFIG_STAGES_OPTIMISATION_KEY}") sys.exit(1) + global_config = config.get(CONFIG_STATIC_CONFIG_KEY, {}) + if not global_config: + LOG.info('No global configuration passed') + self.all_stages = [] # set working directories all_deps = [] @@ -142,7 +148,10 @@ def setup(self): config[csk][name] = deepcopy(config[csk][name]) value = config[csk][name] value["cwd"] = value.get("cwd", name) - value["config"] = value.get("config", {}) + local_config = value.get(CONFIG_STATIC_CONFIG_KEY, {}) + # merge global and local config, local config takes precedence + value_config = global_config | local_config + value[CONFIG_STATIC_CONFIG_KEY] = value_config all_deps.extend(value.get("deps", [])) if csk == CONFIG_STAGES_OPTIMISATION_KEY: