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

Return txt files as list separated by newline #15

Closed csaska closed 3 years ago

csaska commented 3 years ago

I'm not sure what the orginal intention with the PlainTextReader was. In my use cases, plain texts are used to contain lists, each line representing a new item in a list.

Without this commit, using PlainText reader in sequence mode has the following behavior. 1.txt is:

foo
bar

2.txt is:

baz
bah

Sequence

If foo.yml was:

files:
  - !include include.d/1.txt
  - !include include.d/2.txt

We'll get:

files:
  - 'foo\nbar\n'
  - 'baz\nbah\n'

With this commit you woud get

files:
  - [ 'foo', 'bar' ]
  - [ 'baz', 'bah' ]

This is more intuitive to me, but perhaps that is only because of my specific use case.

tanbro commented 3 years ago

Then PlainTextReader just loads whole text file as a str, and put it into the YAML object.

If want to take each line as a list item, i think, we could use *.yml file instead.