pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

A way to update configuration using pyhocon

Open alexey-terentiev opened this issue 8 years ago • 3 comments

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?

alexey-terentiev avatar Apr 20 '16 12:04 alexey-terentiev

any update on this?

huskarz avatar Jul 15 '16 08:07 huskarz

Any updates? It would be great if this could get fixed.

DWiechert avatar Sep 22 '17 15:09 DWiechert

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}'

jlrobins avatar Aug 29 '19 20:08 jlrobins