configparser removes comments from config files
joyeusenoelle opened this issue · comments
When ananas closes, it writes the running bots' current configuration information into the indicated config file. However, this appears to have the undesired result of removing any comments that were in the original configuration file.
This means, among other things, that you can't simply comment out the configuration of a bot you temporarily don't want to run.
Is there a way to change this so that configparser.ConfigParser preserves the comments in the original file?
Although I'm not a dev, here's my 2¢
ConfigParser can't do it and it's a lot of work (see https://groups.google.com/forum/#!topic/comp.lang.python/ElamPZoOjbI)
There is a library called ConfigObj (http://www.voidspace.org.uk/python/configobj.html) but it hasn't been updated in 8 years.
Honestly, it's probably better to move off the INI based format and use something else. The config stuff should be more loosely coupled anyway, in my opinion.
The ini format doesn't change that often, if python's file API hasn't changed in the last 8 years it shouldn't matter if the library's old.
That said I like INI style config files because they're dead simple. I'm open to the bot supporting other file types (json and yaml come to mind as examples of other formats that could map fairly cleanly to the current system) but it'll have to be clear how they map to concepts in the current system.
also if you follow through the link chain on their page, it goes to this github repo which was updated 23 days ago: https://github.com/DiffSK/configobj
Went ahead and added a depend on this library so that comments are preserved. If any of y'all want other config formats, open another issue and we can discuss it further.