-
Notifications
You must be signed in to change notification settings - Fork 814
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
Allow environment variable substitution in conf file #1343
Conversation
- Enabled with the `--enable-env` command line option - Opt-in ensures current conf files don't get into ConfigParser recursion issues, e.g. `home: %(HOME)s` - Provide nicer error on exit if the conf file has bad interpolation - New unit tests with and without command line option present
The build failure is because it is claimed in the README that python 2.7 is ok to use, but CI is building with python 2.6 which doesn't support the |
Wow this is one flakey CI. It can't make up it's mind if it's running python 2.6 or 2.7, and randomly fails anyway. Suffice it to say, this patch is clean. Cheers, |
Thanks @delitescere We have made huge steps towards non-flakiness, but I cannot agree more it sucks. Relying on so many 3rd party mirrors and services for integration testing is hard, next up will be some more caching to avoid that. |
Cross reference #1243 |
+1 |
This is a really nice feature, we'll work on it soon for the future release we didn't have time to really work on it yet. And we want to add some more work on top so that we revamp the |
Still some more work to do, working a leo/configcleanup branch. Will submit new PR for 5.5. |
+1 |
@LeoCavaille Should we close this in favor of the branch you are working on? |
@LeoCavaille Should we close this in favor of the branch you mentioned in #1343 (comment) ? |
@LeoCavaille checking back in? |
@irabinovitch wow somehow I missed that thread 3 times in a row. I will coordinate with the rest of the team (cc @remh) to decide what to do next for this feature and re-update the PR this week. |
config = ConfigParser.ConfigParser() | ||
if options is not None and options.enable_env: | ||
log.info("Interpolation of environment variables in config is enabled") | ||
config = ConfigParser.ConfigParser(os.environ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@delitescere @LeoCavaille
You may want to add ConfigParser.ConfigParser.optionxform = str
before config = ConfigParser.ConfigParser(os.environ)
so that the keys in os.environ
are treated as case sensitive.
For example:
>>> from ConfigParser import ConfigParser
>>> import os
>>> os.environ['XY'] = 'foo'
>>> os.environ['Xy'] = 'bar'
>>> os.environ['xY'] = 'baz'
>>> print '\n'.join(sorted([':'.join((k, v)) for k, v in os.environ.items() if k.lower() == 'xy']))
XY:foo
Xy:baz
xY:bar
>>> cfgp = ConfigParser(os.environ)
>>> print '\n'.join(sorted([':'.join((k, v)) for (k, v) in cfgp.defaults().items() if k.lower() == 'xy']))
xy:foo
>>> ConfigParser.optionxform = str
>>> cfgp_cs = ConfigParser(os.environ)
>>> print '\n'.join(sorted([':'.join((k, v)) for (k, v) in cfgp_cs.defaults().items() if k.lower() == 'xy']))
XY:foo
Xy:baz
xY:bar
>>> assert([(k, v) for (k, v) in cfgp_cs.defaults().items() if k.lower() == 'xy'] == [(k, v) for (k, v) in os.environ.items() if k.lower() == 'xy'])
>>> assert([(k, v) for (k, v) in cfgp.defaults().items() if k.lower() == 'xy'] == [(k, v) for (k, v) in os.environ.items() if k.lower() == 'xy'])
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-43-1f97baeb1e97> in <module>()
----> 1 assert([(k, v) for (k, v) in cfgp.defaults().items() if k.lower() == 'xy'] == [(k, v) for (k, v) in os.environ.items() if k.lower() == 'xy'])
AssertionError:
/unsubscribe |
--enable-env
command line optionrecursion issues, e.g.
home: %(HOME)s