Patch yaml strings
Project description
yaml-patch
Apply patches to a yaml string, keeping most of the formatting and comments.
Some formatting is not kept due to underlying yaml library limitations:
- Indentation will be forced to two spaces
- Spacing before sequence dashes will be forced to two spaces
- Empty lines at the start of the string will be removed
As a command line tool
You can pass any number of patches to be applied, they use the following syntax options:
Patch a single value:
<field>.<subfield>=<value>
Example:
yaml-patch -f test.yml 'spec.replicas=2'
Patch a value inside a single list item:
<field>.[<position]>.<subfield>=<value>
Example:
yaml-patch -f test.yml 'spec.template.containers.[0].image="mycontainer:latest"'
Patch a value inside all list items:
<field>.[].<subfield>=<value>
Example:
yaml-patch -f test.yml 'spec.template.containers.[].image="mycontainer:latest"'
As a Python library
To use yaml-patch
as a library just import the function and pass patches as dictionary entries.
Example:
from yaml_patch import patch
from textwrap import dedent
def override_list_all_values():
source_yaml = dedent(
"""\
some_list:
- alice
- bob
"""
)
patches = {"some_list.[]": "charlie"}
expected_yaml = dedent(
"""\
some_list:
- charlie
- charlie
"""
)
assert patch(source_yaml, patches) == expected_yaml
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yaml-patch-0.1.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for yaml_patch-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd6cf5f893346424fc5ef3312e0b4bb8af785cc4b8a36660d795af84c983f2e8 |
|
MD5 | 7ec089fd34b08d4160996bb4fc2d84fe |
|
BLAKE2b-256 | a6d3c522ca58845b5c36b914fedb8fca1439eb65b79dfea322d96a841dcd9663 |