-
Notifications
You must be signed in to change notification settings - Fork 51
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
Dumping changes to a config.yaml file places changed lines at the beginning #100
Comments
Interesting use case! Indeed, this will not work yet. To clarify, our current round-tripping of comments is quite hacky, but it could plausibly be greatly improved by switching to ruamel.yaml (cf #52). Regardless, however, the scheme works by trying to preserve the formatting of a given source, whereas this use case is about merging multiple sources while preserving the formatting of one of them. It certainly sounds possible, but it will take some creativity to figure out exactly how to do that in a predictable way! |
Thank you for the reply. I think you may have misunderstood my use case (or I have not used confuse the way I think I have). I am trying to load a config.yaml, update one of the values in said file and then write the changes back to the same file. In the code above, I use "config copy.yaml" to make sure I don't ruin the original config file. I suppose I could just have used the copy as backup and revert if something got screwed up, but this way seemed like an easier approach. |
Indeed—that's the tricky thing here. When you do That's why this is harder than it looks for Confuse to do: it needs to merge configuration sources together, even when they do not align perfectly, when you do |
Well, now I am confused (pardon the pun). What is the purpose of preserving comment lines during |
Well, here's the thing: you can actually dump a "changed" version of the config file, but the way that "change" works is pretty subtle. You're not actually modifying one data structure in place, as I think we may be getting a little side-tracked though. The main thing is that preserving the order of things when |
As you mentioned earlier, ruamel.yaml has some features that should make it easier. Since, I haven't yet had a look at any of this, maybe you can tell me how far away you are from implementing something similar? Also, I've read about bespON, which is somewhat similar to YAML and ships with complete round-tripping. Maybe there are some insights to be gleaned from the source code? |
I don't currently have plans to implement it, so any help would be greatly appreciated! However, part of the point of the discussion above was to emphasize plain round-tripping from the serialization library, while helpful, is not enough. There are also Confuse-specific issues related to the "layering" concept that would need to be resolved. |
As the title says, when I make a change to some of the config variables and dump it to the config.yaml file, the edited variables are now inserted at the very top of the file rather than the position they used to be in. This is especially frustrating when the config file is "supposed" to start with a few lines of comments indicating authorship and explanations for new users.
OS and versions
OS: Ubuntu 18.04
Python: 3.8.2 64-bit
confuse: 1.1.0
Steps to reproduce
Example config.yaml
Example python script
console output:
The text was updated successfully, but these errors were encountered: