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
Refactor config file parsing #28
Conversation
The parse_config_file and convert_parsed_args_to_config_file_contents methods were moved to a generic ConfigFileParser class, which can be overridden in the ArgumentParser constructor using the config_file_parser option. Addresses bw2#21
The very convoluted code for showing examples was greatly simplified, there is little benefit in showing true args instead of pseudo-args. For advanced parsers, the full syntax can't be expressed in a simple description, so we should also refer to the "upstream" documentation for completeness.
There is a couple of undocumented features/regressions I wanted to discuss:
I have a prototype addressing the above issues in my config_files_without_merging branch, but since it breaks stuff (including some tests), it should be discussed before merging into master. |
Thanks for the great pull request! Also, I need to go through and better understand the I'm more hesitant about enabling multiple default files in the arg (eg. default=["foo.conf", "bar.conf"]) since it's type _StoreAction so users would expect the default to be a single value, and also I'm guessing the need for multiple files here is rare. What do you think? |
Enabling multiple default files in the |
|
There are too many (sometimes even conflicting) conventions. For sure the configargparse library should not be too restrictive and let the application developers choose the most fitting convention for their use case. Actually, the Rather than introducing null values, which may depend on the config file format, perhaps we should add another parameter for the |
Oh, I forgot about that. I can switch it to accept Append also. Looking at dnsmasq (http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html#lbAF) the behavior generally differs from configargparse:
|
Looking at dnsmasq (http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html#lbAF) the behavior generally different from configargparse:
"For options which may only be specified once, the configuration file overrides the command line. "
so I'm not sure I want to emulate it.. and I'm still not fully understanding the use-case where you need to specify multiple config files, but then discard one of them. Are there other tools besides these network ones that use this behavior?
Modifying the behaviour to match dnsmasq _exactly_ was not the point. Of course
there are more than just dnsmasq: i3, i3status, mpv, mpd, pulseaudio -- I could
most likely go on. The programs doing it this way are not restricted to a single
category and neither should ConfigArgParse.
would you ever need more than 1 but fewer than all files loaded? If not, could this be a boolean (eg. load_one_file)? and then, should it be the last file found or the 1st file found?
You might e.g. want to skip all system configs if any user config has been
found, but you're right that specifying this by a fixed number is not very
useful.
|
I don't mean to beat this to death, but I went looking for how this behavior is documented in another tool, but couldn't find a good description. For example https://wiki.archlinux.org/index.php/Music_Player_Daemon Also, to play devil's advocate, in the case where you want only one file to load, why not code this up just prior to defining configargparse args. eg.
then pass default_config_files either to the constructor or to add_args(.., default=) |
#25 might also be relevant to this. and it might be good to move further discussions to a new Issue. |
Regardless of what the documentation for the mentioned programs says, I've actually tried it or looked into the source to confirm that only one config file is loaded. If one wants to always load only one file, including the one specified to e.g. |
@lahwaacz After thinking about this more, I would prefer (assuming there's broader interest) to add null values rather than add a new / different config-file-loading behavior that would coexist with the current one. Since (as you pointed out) default="bla.txt" already works for config file args, that's as far as I currently want to go in this direction. |
This is a basic refactoring to address #21, I'm working on testing it with custom parser now... All tests are passing, so hopefully I did not mess up anything.
The documentation and examples in the README will be updated based on input from others.