keepmenu icon indicating copy to clipboard operation
keepmenu copied to clipboard

[request] allow for environment variables in config

Open ghost opened this issue 5 years ago • 2 comments

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.

ghost avatar Mar 27 '19 21:03 ghost

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

KaziSadmanAhmed avatar May 08 '23 12:05 KaziSadmanAhmed

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!

firecat53 avatar May 08 '23 20:05 firecat53