1

With OmegaConf, is it possible to "turn off" node interpolation, so that when you access an interpolation node it just returns the literal string, i.e. "${resolver:value}" instead of evaluating the interpolation?

I have a program that uses configuration files with some custom interpolations, but I sometimes want to evaluate or compare the configs programatically without worrying about the interpolations (they might correspond to environment variables that aren't set, for example).

  • I can hack around it by converting from omegaconf to a dict and then accessing the requisite key, but it would be nice if there were a supported way to do this. – Connor Anderson Sep 09 '22 at 19:48

1 Answers1

1

You can access the raw value using internal APIs:

c = OmegaConf.create({"a" :10, "b": "${a}"})
v = c._get_node("b")._value()
print(type(v), v)
# <class 'str'> ${a}

Comparing configs works correctly in the case you are describing (Or in general when some custom resolvers are not resolving):

c1 = OmegaConf.create({"e": "${oc.env:FOO}", "a": 1})
c2 = OmegaConf.create({"e": "${oc.env:FOO}", "a": 1})
print(c1 == c2)
# True
c2.a = 2
print(c1 == c2)
# False
Jasha
  • 5,507
  • 2
  • 33
  • 44
Omry Yadan
  • 31,280
  • 18
  • 64
  • 87