pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

For future major releases, consider TOML over ConfigObj for pgclirc

Open clbarnes opened this issue 5 years ago • 5 comments

ConfigObj fixes a lot of problems with INI, which isn't a real format, but AFAIK is a dead end in terms of adoption and indeed wider recognition as it's just one library with its own specification.

TOML resolves many of the same problems as ConfigObj and is seeing pretty widespread adoption (e.g. by the rust ecosystem, and indeed by modern python standards). Therefore it has better tooling available for it, is more recognisable, and is in wider use.

Changing config format is obviously a seriously breaking change. If there is interest in this transition, we could move to supporting both immediately, give a couple of minor versions' (Pending)DeprecationWarning, then actually deprecate it with a major version.

clbarnes avatar Mar 27 '20 12:03 clbarnes

The last time I checked the TOML library for python it didn't have a way to preserve the comments in the file when we update it.

For instance, we write to the config file when someone saves a named query. By using ConfigObj it allows us to preserve the comments in the file that a user might have added. With TOML if we read the config and write back the file it strips out the comments. I had filed an issue with the library author a while back, I don't think it has seen any movement though.

amjith avatar Mar 27 '20 16:03 amjith

Good point! The tomlkit library, from the creator of poetry, allows you to persist comments, as well as whitespace/ formatting. It's a little less transparent in its usage than the toml library is, though.

clbarnes avatar Mar 27 '20 16:03 clbarnes

For instance, we write to the config file when someone saves a named query. By using ConfigObj it allows us to preserve the comments in the file that a user might have added. ...

Sorry to somewhat hijack this issue, but it's the only relevant thing I found while searching for comment preserving in the config file. Are user comments supposed to be preserved already, or is it something that's possible ("allows us to ...") but not yet supported by pgcli? For me this has never worked. Just did a quick test again (pgcli 3.0.0, configobj 5.0.6, Python 3.6, Linux) by saving a named query and any manually added comments in my config file still get lost (tested the "named queries", "alias_dsn", "main" and "data_formats" sections).

If they're supposed to be preserved already I'll create a separate issue for it but first wanted to check if I understood correctly.

ghost avatar Dec 01 '20 11:12 ghost

@sevens-ef Indeed, comments in pgclirc are supposed to be preserved already. If this does not work for you, please create an issue to track the problem.

j-bennet avatar Dec 07 '20 17:12 j-bennet

Ok, thanks! I've been busy with other things but finally got around to it...

ghost avatar Feb 04 '21 16:02 ghost