Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import YAML files containing multiple documents as arrays #1497

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

vkleen
Copy link
Contributor

@vkleen vkleen commented Aug 3, 2023

For example, in Kubernetes deployments it is common practice to package multiple YAML documents into a single file. For processing such files with Nickel we need to support importing multiple YAML documents from a single file. The concern with this is: how does such a file fit into Nickel's data model? Importing it as an array of Nickel values felt most reasonable to me. At the same time, a YAML file containing a single document should still be transparently serialized as that document, not as a single element array.

@github-actions github-actions bot temporarily deployed to pull request August 3, 2023 18:53 Inactive
let mut terms = de
.map(|de| {
RichTerm::deserialize(de)
.map(attach_pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense to attach the sub-span corresponding to the single document, I guess. Doesn't seem like this can be easily extracted from serde_yaml, though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess that's also the reason that the subterms of a term imported from something other than Nickel don't carry positions. I wonder if that breaks some assumptions in the evaluator...

// we deserialize the file as an array.
let de = serde_yaml::Deserializer::from_str(self.files.source(file_id));
let mut terms = de
.map(|de| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that serde_yaml::Deserializer implements Iterator<Item=serde_yaml::Deserializer> 🙀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too 🙀

@vkleen vkleen force-pushed the feat/multiple-yaml-documents branch from deec759 to 140108f Compare August 3, 2023 19:47
@github-actions github-actions bot temporarily deployed to pull request August 3, 2023 19:52 Inactive
For example, in Kubernetes deployments it is common practice to package
multiple YAML documents into a single file. For processing such files
with Nickel we need to support importing multiple YAML documents from
a single file. The concern with this is: how does such a file fit into
Nickel's data model? Importing it as an array of Nickel values felt most
reasonable to me. At the same time, a YAML file containing a single
document should still be transparently serialized as that document, not
as a single element array.
@vkleen vkleen force-pushed the feat/multiple-yaml-documents branch from 140108f to 505105b Compare August 3, 2023 21:13
@github-actions github-actions bot temporarily deployed to pull request August 3, 2023 21:18 Inactive
@vkleen vkleen added this pull request to the merge queue Aug 3, 2023
Merged via the queue into master with commit ebfa2a6 Aug 3, 2023
4 checks passed
@vkleen vkleen deleted the feat/multiple-yaml-documents branch August 3, 2023 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants