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

Import secondary configuration files #40

Open
amadanmath opened this issue Jul 2, 2018 · 1 comment
Open

Import secondary configuration files #40

amadanmath opened this issue Jul 2, 2018 · 1 comment

Comments

@amadanmath
Copy link

I read in other issues the opinion that there should be one configuration file, and the rest be data. I have a counterexample to that.

I currently need user-switchable configurations for what the app will be doing as the main configuration file. There will be sample configurations for different tasks that users can easily copy. Independently of that, I want database configuration that will not be modified that often. Consequently, I expect to have config.yaml and db.yaml in my .config/APPNAME directory. So currently I have something like this:

config = confuse.Configuration(APPNAME, __name__)
try:
    _db_config_name = os.path.join(config.config_dir(), 'db.yaml')
    config['db'].set(confuse.ConfigSource(confuse.load_yaml(_db_config_name), _db_config_name))
except confuse.ConfigReadError:
    pass

However, it feels like I'm doing something dirty. :) Is there a better way to do something like this?

@sampsyo
Copy link
Member

sampsyo commented Jul 2, 2018

Cool! Yes, this seems like a good argument in favor of the way Confuse merges configuration sources.

Your way doesn’t look bad at all. But there is a set_file method here that parses and adds a source from a filename, but it doesn’t include the path manipulation or the error handler. That would at least help make your code a little simpler. 😃

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