tanbro / pyyaml-include

yaml include other yaml
https://pypi.org/project/pyyaml-include/
GNU General Public License v3.0
77 stars 20 forks source link

How to concatenate two yaml files? #25

Closed johnsonkee closed 1 year ago

johnsonkee commented 1 year ago

Hello, I want to concatenate two yaml files, what should I do?

for example, I have two different yaml files,

# file1.yaml
name: 1
# file2.yaml
class: 2

I want to concatenate these two files into one file after using pyyaml-include, as shown below

# merge_file.yaml
name: 1
class: 2

I would like to ask, what should I do to get this result?

Thank you very much.

tanbro commented 1 year ago

No, i think it won't work if we use including(s) directly.

Suppose we have such a YAML snippet:

!include a.yml
!include b.yml

PyYAML will not parse the above into two tags, instead it's parsed as:

!include "foo-1.yml !include foo-2.yml"

So we should put them in a sequnce or a mapping, eg:

- !include a.yml
- !include b.yml

or

a: !include a.yml
b: !include b.yml