fix: ignore empty YAML documents in copier.yml
#1538
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've fixed loading
copier.yml
with empty YAML documents. The fix is simple:yaml.load_all()
returns a sequence of YAML documents, and empty documents are represented byNone
, so I'm filteringNone
items usingfilter(None, yaml.load_all(...))
.filter(None, <sequence>)
actually filters any falsy items – not onlyNone
s –, but that's no problem in this case.Before, Copier raised an error
which is not very helpful for debugging. Now, an empty YAML document is simply ignored. Of course, there's little sense in having empty YAML documents, but it's easy to have one unintentionally, e.g. when the file ends with the
---
marker:In this regard, the YAML document syntax is a bit confusing IMO because a leading
---
marker at the beginning of the file does not cause an empty YAML document. I think Copier should not be strict about it and ease template developers' lives. See also the confusion about this in #1496.