bw2 / ConfigArgParse

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.
MIT License
728 stars 121 forks source link

Support loading from a pre-defined section of a file only #227

Closed tristanlatr closed 3 years ago

tristanlatr commented 3 years ago

The use case I'm thinking of is the following:

I would like to use ConfigArgParse to parse a part of my setup.cfg file only. If I pass the whole file, they might have conflicts in the names!

For instance, pytest accepts a section [tool:pytest] inside the setup.cfg.

A simple argument like the following should be sufficient:

ArgumentParser(config_section='[tool:pytest]', ...)

Tell me if that's not too hard, I can give it a go!

Thanks

bw2 commented 3 years ago

Hi tristan, this seems like a very niche use-case. Also, it's difficult to generalize to different config file formats. Unless more people are interested, I would recommend forking the repo and adding this to your own version.

tristanlatr commented 2 years ago

Hi @bw2,

Could you re-open this issue since it's a missing feature from configargparse ? Also, it's more likely to be seen by other users and upvoted if it's actually open.

I would argue that setup.cfg, project.toml files are becomming more and more popular.

Anyway, I'll implement an alternative ConfigFileParser subclass that support this kind of stuff. Without touching the main ArgumentParser object. So maybe it can be merged as an extra config parser subclass.

tristanlatr commented 2 years ago

This is a duplicate of #250, in which I proposed a simple and maintainable solution to support configuration sections.