pypyr.steps.fetchyaml
load & parse yaml
Loads a yaml file into the pypyr context.
This step requires the following key in the pypyr context:
- name: pypyr.steps.fetchyaml
description: fetch yaml from path
in:
fetchYaml:
path: ./path.yaml # required. path to file on disk. can be relative.
key: destinationKey # optional. write yaml to this context key.If you do not specify key, yaml writes directly to context root.
If you do not want to specify a key, you can also use the streamlined format:
- name: pypyr.steps.fetchyaml
description: fetch yaml with simplified path input
in:
fetchYaml: ./path.yaml # required. path to file on disk. can be relative.All inputs support substitutions.
See some worked examples of fetchyaml.
merging logic
pypyr will parse the yaml from the file and merge it into the pypyr context. This will overwrite existing values if the same keys are already in there.
I.e if file yaml has
eggs: boiledbut context {'eggs': 'fried'} already exists, after fetchyaml context will
be:
eggs: friedinput yaml structure
key, the yaml should NOT be a list at the top
level, but rather a mapping.So the top-level yaml should not look like this:
- eggs
- hambut rather like this:
breakfastOfChampions:
- eggs
- hamencoding
By default the yaml file will read in the platform’s default encoding. This is
utf-8 for most systems, but be aware on Windows it’s still cp1252.
You can use the encoding input explicitly to set the encoding:
- name: pypyr.steps.fetchyaml
comment: set encoding
in:
fetchYaml:
path: testfiles/myfile.yaml
key: mykey
encoding: utf-8See here for more details on handling text encoding in pypyr and changing the defaults.
See here for a list of available encodings.