diff options
author | Itxaka <itxakaserrano@gmail.com> | 2015-08-23 20:50:15 +0200 |
---|---|---|
committer | Itxaka <itxakaserrano@gmail.com> | 2015-08-23 20:50:15 +0200 |
commit | 2fe3b893c479f2838342addde51fa8edba71653e (patch) | |
tree | 1af3dd19472c4fdf181ba35007a4c864a6be4bd8 | |
parent | 260c83e398490f63791535b5df8b47d72b2ef42c (diff) | |
download | tox-2fe3b893c479f2838342addde51fa8edba71653e.tar.gz |
If the {env:key:default} paremeter is found in the config but there are no environment variables yet, fall back to the current section setenv variables
-rw-r--r-- | tox/config.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tox/config.py b/tox/config.py index d68d276..17fdccf 100644 --- a/tox/config.py +++ b/tox/config.py @@ -903,6 +903,7 @@ class SectionReader: return '\n'.join(filter(None, map(factor_line, lines))) def _replace_env(self, match): + env_list = self._build_envs_list() match_value = match.group('substitution_value') if not match_value: raise tox.exception.ConfigError( @@ -917,11 +918,21 @@ class SectionReader: envkey = match_value if envkey not in os.environ and default is None: - raise tox.exception.ConfigError( - "substitution env:%r: unknown environment variable %r" % - (envkey, envkey)) + if envkey not in env_list and default is None: + raise tox.exception.ConfigError( + "substitution env:%r: unknown environment variable %r" % + (envkey, envkey)) + if envkey in os.environ: + return os.environ.get(envkey, default) + else: + return env_list.get(envkey, default) - return os.environ.get(envkey, default) + def _build_envs_list(self): + full_envs = self._cfg[self.section_name].get('setenv') + if full_envs: + return {k.split('=')[0]: k.split('=')[1] for k in full_envs.split('\n')} + else: + return {} def _substitute_from_other_section(self, key): if key.startswith("[") and "]" in key: |