How to delete an inherit property from yaml config? How to delete an inherit property from yaml config? docker docker

How to delete an inherit property from yaml config?


No there isn't a way to mark a key for deletion in a YAML file. You can only overwrite existing values.

And the latter is what you do, you associate the empty scalar as value to the key image as if you would have written:

  image: null   # delete

There are two things you can do: post-process or make a base mapping in your YAML file.

If you want to post-process, you associate a special unique value to image, or a specially tagged object, and after loading recursively walk over the tree to remove key-value pairs with this special value. Whether you can already do this during parsing, using hooks or overwriting some of its methods, depends on the parser.

Using a base mapping requires less work, but is more intrusive to the YAML file:

localbase: &lb  # *tons of config*local: &local  image: xxxci:  <<: *lb  build: .

If you do the former you should note that if you use a parsers that preserve the "merge-hierarchy" on round-tripping (like my ruamel.yaml parser can do) it is not enough to delete the key-value pair, in that case the original from local would come back. Other parsers that simply resolve this at load time don't have this issue.