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

[request] allow for environment variables in config #32

Open
ghost opened this issue Mar 27, 2019 · 2 comments
Open

[request] allow for environment variables in config #32

ghost opened this issue Mar 27, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2019

I would like to include environment variables in the config.ini file. I often find myself adding a bunch of long filepaths or complicated variables that might change in the future, so this would be really convenient for me.

For example:

[some_section]
main_folder = $HOME/main
mountain_picture = $WALLPAPERS/mountain.jpg

I already have an idea of how you could accomplish this. Basically, you could just subclass BasicInterpolation and just expand the variables before the value is accessed:

import configparser, os
class EnvInterpolation(configparser.BasicInterpolation):

    def before_get(self, parser, section, option, value, defaults):
        return os.path.expandvars(value)

And then you would just initialize the config parser as:

parser = configparser.ConfigParser(interpolation=EnvInterpolation())

You could even subclass ExtendedInterpolation if you want the user to access variables from other sections (although the interpolation syntax is a bit different). I would really appreciate if you did this.

@KaziSadmanAhmed
Copy link

Any update on this? I also need to use env vars in the config file.

@firecat53
Copy link
Owner

Sorry, this one hasn't been a priority for me. PR's welcome, but I will start working on it when I get a chance!

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