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.2.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for yaml_patch-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea986a4053c44fa9f1e296fe284bee3e4cf2b83feedc09df6484a1747658e7f1 |
|
MD5 | d3dc0c2a5e96ec963b111a13307746b9 |
|
BLAKE2b-256 | bb4678fbafc63851ce1a3087ded61a56ce319dfe4d7e16cbf3d98c2f9252a360 |