Skip to content

Commit

Permalink
[Config] Use one global config (#63)
Browse files Browse the repository at this point in the history
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'

Co-authored-by: Benedikt Volkel <[email protected]>
  • Loading branch information
benedikt-voelkel and Benedikt Volkel authored Oct 9, 2024
1 parent bff3589 commit aa5c5a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/o2tuner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down Expand Up @@ -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 = []
Expand All @@ -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:
Expand Down

0 comments on commit aa5c5a8

Please sign in to comment.