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.2.0.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for yaml_patch-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09c14b5c4255e6f3a077238dc840436a8e35694427b2338c6e0388a3626862b3 |
|
MD5 | ffae72307c85bded767122ad90eacf14 |
|
BLAKE2b-256 | 91d0777e4dc64f92896d116edf605375d55d9dd51503adde4f81c8d65f637ab5 |