-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Support for roundtripping YAML comments #106
Comments
Thanks for reporting - I agree this should be documented (or implemented in |
Duplicate of #28 Easiest way to do this seems to move the comment to a json object.
There're two flaws I can think of:
There's probably a better way to solve this, but this is what came to head. |
This comment was marked as resolved.
This comment was marked as resolved.
@jtagcat thanks for your suggestion. I agree with your approach and have previously tried to implement it. However the issue I am facing is that there is no obvious place to hook into the PyYAML parser to retrieve comments from the input stream (they get discarded too early in the process) and no obvious data model to emit the comments in the dumper. I know ruamel.yaml has comment round-tripping, but I'm not sure if the parser/dumper modifications made there to accomplish this would be portable into our customizations of PyYAML. Ultimately this seems possible but might require the use of the slow pure-Python tokenizer in the parser, and might require extensive customization. With that said, PRs are welcome. |
@andrewcrook thanks for expanding upon your original comment, it is now legible as a contribution to this discussion. While I appreciate the pointer to JSONC, the comment you linked on the jq wiki outlines why jq will not support it. Rewriting, repackaging, or replacing jq is outside the scope of this project, so none of the suggestions related to that are productive. You can check the comments by @jtagcat above for pointers to the course of action that we consider most likely to be productive. PRs are welcome. |
A workaround for this issue through the bash scripts based on diff+patch approach: mikefarah/yq#515 (comment) |
For reference, this is where PyYAML throws out comments (this happens in the tokenizer, before any of the parsing or constructor steps that we hook into): |
YAML has comments, JSON doesn't jq strips comments and the -Y -y flags doesn't get them back again.
The text was updated successfully, but these errors were encountered: