diff options
author | Chris Rose <offby1@offby1.net> | 2011-07-19 22:52:33 -0700 |
---|---|---|
committer | Chris Rose <offby1@offby1.net> | 2011-07-19 22:52:33 -0700 |
commit | 4c4bfea7c9e21bd2a576bbbeac9732202c2f8d1e (patch) | |
tree | dfae5140db5d1e01d49a1244299c7f75b5c6b177 | |
parent | 7cb6f265883f044a22b8e0cc45f5c9abd89527cf (diff) | |
download | tox-4c4bfea7c9e21bd2a576bbbeac9732202c2f8d1e.tar.gz |
Implement a fix for bare {posargs} substitution
-rw-r--r-- | tox/_config.py | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/tox/_config.py b/tox/_config.py index f40e60a..3a697c7 100644 --- a/tox/_config.py +++ b/tox/_config.py @@ -400,15 +400,19 @@ class IniReader: return str(self._subs[key]) def _replace_posargs(self, match): + return self._do_replace_posargs(lambda: match.group('substitution_value')) + + def _do_replace_posargs(self, value_func): posargs = self._subs.get('_posargs', None) if posargs: return " ".join(posargs) - if match.group('substitution_value'): - return match.group('substitution_value') - else: - return '' + value = value_func() + if value: + return value + + return '' def _replace_env(self, match): envkey = match.group('substitution_value') @@ -430,19 +434,34 @@ class IniReader: "substitution key %r not found" % sub_key) return '"%s"' % str(self._subs[sub_key]).replace('"', r'\"') + def _is_bare_posargs(self, groupdict): + return groupdict.get('substitution_value', None) == 'posargs' \ + and not groupdict.get('sub_type') + def _replace_match(self, match): g = match.groupdict() + + # special case: posargs. If there is a 'posargs' substitution value + # and no type, handle it as empty posargs + if self._is_bare_posargs(g): + return self._do_replace_posargs(lambda: '') + handlers = { 'posargs' : self._replace_posargs, 'env' : self._replace_env, None : self._replace_substitution, } try: - handler = handlers.get(g['sub_type']) + sub_type = g['sub_type'] except KeyError: - raise tox.exception.ConfigError("No support for the %s substitution type" % g['sub_type']) - else: - return handler(match) + raise tox.exception.ConfigError("Malformed substitution; no substitution type provided") + + try: + handler = handlers[sub_type] + except KeyError: + raise tox.exception.ConfigError("No support for the %s substitution type" % sub_type) + + return handler(match) def _replace(self, x, rexpattern = re.compile("\{.+?\}")): if '{' in x: |