pyhocon
pyhocon copied to clipboard
A way to update configuration using pyhocon
Let's say I've got some property-like configuration:
server.property1 = ${foo.bar}
server.property2 = ${baz}
And I want to add another two properties without resolving existing variables
server.property2 = replacement
server.property3 = 100500
overwriting existing ones values. So I wrote following code:
from pyhocon import ConfigFactory
from pyhocon import ConfigTree
from pyhocon import HOCONConverter
config = ConfigFactory.parse_file("server.properties", resolve=False)
ConfigTree.put(config,"server.property3","100500")
ConfigTree.put(config,"server.property2","replacement")
print HOCONConverter.to_properties(config)
And the result is almost good, but it prints out object names:
server.property1 = [ConfigValues: [ConfigSubstitution: foo.bar]]
server.property2 = replacement
server.property3 = 100500
Is there any way I can get my ${foo.bar}
back?
any update on this?
Any updates? It would be great if this could get fixed.
Looks like HOCONConverter.to_hocon(tree) will in fact do the right thing with unresolved references:
HC file:
template { foo : 12 bar : ${unresolved} }
from pyhocon import ConfigFactory, HOCONConverter tree = ConfigFactory.parse_file('test.hc', resolve=False) print(HOCONConverter.to_hocon(tree))
result 'template {\n foo = 12\n bar = ${unresolved}\n}'