keepmenu
keepmenu copied to clipboard
[request] allow for environment variables in config
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.
Any update on this? I also need to use env vars in the config file.
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!