tr11 / python-configuration

A Python library to load configuration parameters

Home Page:https://tr11.github.io/python-configuration/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ConfigurationSet Not Consistent

olgapeled opened this issue · comments

Hi,

It's a great project!!! Thank you!!!

I try to use ConfigurationSet to load two python files with config_from_python.

my_config = ConfigurationSet(
config_from_python(1.py, prefix='', separator=''),
config_from_python(2.py, prefix='', separator='
'),
)

there are some mutual parameters between the two python files....
for example:
1.py:
A = 1
2.py:
A = 2

I thought that the second file overrides (ONLY the mutual parameters) the first one...
BUT, it seems that ConfigurationSet not consistent...
sometimes the first file overrides and sometimes otherwise... without switching the lines in ConfigurationSet
What am I missing???

Thank you!!
Olga

Hi Olga,

Can you give me the full example? The hierarchy works the other way around; the first file is 1 so any parameter existing in 1 will not be searched in file 2.

Would you be able to give me the two test cases when file one overrides and then file 2?

Hi!! Thank you!
It was my mistake...

Another question:
If the 2 files have the same nested parameter (for example a dictionary). Is there a way that the first definition will override the second one without the merge of the inner items.
"The hierarchy works the other way around; the first file is 1 so any parameter existing in 1 will not be searched in file 2."
Means that the search will be ONLY by level 1 ?
For example:
1.py:
d = { "1" : 1}
2.py:
d = {"2" : 2}

and I want that the output will be the first definition without merging?

Thank You!

By design, internally the definitions are converted to a single dictionary with keys such as a.b.c. In the case above, the keys are indeed merged and the configuration becomes
{'d.2': 2, 'd.1': 1}
In particular, when you retrieve d, the result will be {'2': 2, '1': 1}. You can also get d.1 and d.2 or even 1 and 2 from the result of d.

Do you want to open another issue to discuss the intended behavior?

You are right!
I will open a new issue...
Thank you again!!!