Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to update configuration using pyhocon #77

Open
alexey-terentiev opened this issue Apr 20, 2016 · 3 comments
Open

A way to update configuration using pyhocon #77

alexey-terentiev opened this issue Apr 20, 2016 · 3 comments
Assignees
Labels

Comments

@alexey-terentiev
Copy link

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?

@darthbear darthbear added the bug label Apr 20, 2016
@darthbear darthbear self-assigned this Apr 20, 2016
@huskarz
Copy link

huskarz commented Jul 15, 2016

any update on this?

@DWiechert
Copy link

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

@jlrobins
Copy link

jlrobins commented Aug 29, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants