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

merging lists? #46

Closed airtonix closed 50 minutes ago

airtonix commented 2 weeks ago

files:

0.yml
a/b/c
  1.yml
  2.yml
f/j/k
  4.yml
  5.yml

{1,2,3,4}.yml

name: 1 # or 2,3,4

0.yml

title: merged lists

items:
  - <<: !include "a/b/c/*.yml"
  - <<: !include "f/j/k/*.yml"

expected output:

title: merged lists

items: 
  - name: 1
  - name: 2
  - name: 3
  - name: 4

variations I've tried:

0a.yml

title: merged lists

x-one: !include &one "a/b/c/*.yml"
x-two: !include &two "f/j/k/*.yml"

items:
  - <<: *one
  - <<: *two
tanbro commented 1 week ago

Consider we have such a YAML:

items: !include *.yaml

if all files match *.yaml contain a Sequence at the top level in it, what parsed and loaded are:

items: [
  [item, item, item, ...] # items of 1st file match *.yaml
  [item, item, item, ...] # items of 2nd file match *.yaml
  # ....
  [item, item, item, ...] # items of n-th file match *.yaml
  # ...
]

because YAML content of each matched file are treated as a list(sequence).

So i think, if a flatten function was provided, like:

items: !include {urlpath: *.yaml, flattern: true}

we could get:

items: [
  item 0 of 1st file, item 1 of 1st file, ... , item n of 1st file,  # ...
  item 0 of 2nd file, item 1 of 2nd file, ... , item n of 2nd file,  # ...
  # ....
  item 0 of n-th file, item 1 of n-th file, ... , item n of n-th file,  # ...
  # ...
]
tanbro commented 1 week ago

92f9223 is for the requirement.

It will be released later.