-
HI @omry, first, I want to thank you for the implementation of omegaconf, it is very useful and covers the need of having a "easiertouse" configuration management package. Here I contact you because I am facing an issue with anchors and aliases and maybe you might know an alternative for it. I need to use them between different files, I will try to explain the concept: file_containing_data.yml extension_file1.yml extension_file2.yml I plan to get a config_object that looks like this: slave_data_1: slave_data_2: This is just a fictive example to ilustrate my concept, I read also in one of your posts that anchors and aliases shall not be used with this purposes, and you suggested to use interpolation, however I do not think that this cover this use case. I will highly appreciate your opinions and suggestions. Thanks again |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @Lads0909, # file_containing_data.yml
master_data:
data1: data_value # extension_file1.yml
slave_data_1:
master_data: ${master_data.data1} # extension_file2.yml
slave_data_2:
master_data: ${master_data.data1} # main.py
from omegaconf import OmegaConf
cfg1 = OmegaConf.load("file_containing_data.yml")
cfg2 = OmegaConf.load("extension_file1.yml")
cfg3 = OmegaConf.load("extension_file2.yml")
cfg_merged = OmegaConf.merge(cfg1, cfg2, cfg3)
OmegaConf.resolve(cfg_merged)
assert cfg_merged == {
"master_data": {"data1": "data_value"},
"slave_data_1": {"master_data": "data_value"},
"slave_data_2": {"master_data": "data_value"},
} Also, I'd recommend to check out the Hydra project (which is also Omry's project :) ). |
Beta Was this translation helpful? Give feedback.
-
OmegaConf.resolve is not needed here. |
Beta Was this translation helpful? Give feedback.
Hi @Lads0909,
Does the following work for you?
Also, I'd rec…