Skip to content
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

A new configuration discovery strategy. #18

Closed
hernantz opened this issue Apr 24, 2018 · 2 comments
Closed

A new configuration discovery strategy. #18

hernantz opened this issue Apr 24, 2018 · 2 comments

Comments

@hernantz
Copy link
Contributor

hernantz commented Apr 24, 2018

If I write an app which has code in /opt/app and I would like users to optionally put a config.ini in /etc/app/, there is no way to do it through prettyconf's current discovery strategy.
It would be nice to be able to configure this behavior.
I imagine something like:

from prettyconf.configuration import env_vars, dirs, recursive

config.strategies = [
     env_vars, 
     dirs('/etc/app', '~/.configs/app'], 
     recursive(root_dir='/', starting_path='./')
]

The above snippet means that a config variable would be first checked within the environment variables,
if it is not found there, it would look at /etc/app, etc.

What do you think? I'm currently facing this issue and I'm willing to work on this.

@osantana
Copy link
Owner

osantana commented Apr 25, 2018

I like this idea. But I'd use classes to implement strategies just to keep uniformity on API:

from prettyconf.discovery import Environment, Directory, Search, CommandLine

config.strategies = [
    CommandLine(...),  # nice-to-have: enable configuration using command-line/argparse
    Environment(),
    Directory('~/.config/app', '/etc/app'),
    Search(root_dir='/', starting_path=os.path.dirname(__file__)),
]

@hernantz
Copy link
Contributor Author

Sounds good to me.
What are your thoughts on having something similar to Directory() called Files() that would look for configuration files with specific names:

Files('~/.config/app/app.cfg', '/etc/app/app.cfg')

CommandLine(...) strategy is very interesting too, maybe it can receive sys.argv or maybe something else after the args parsing has been handled by another library?

@hernantz hernantz mentioned this issue Dec 26, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants