Skip to content

Commit

Permalink
Allow escaping curly braces in setenv
Browse files Browse the repository at this point in the history
Currently braces can be escaped, but the backslashes are not removed,
making it impossible to add a plain curly brace
  • Loading branch information
mkenigs committed Aug 21, 2020
1 parent 23dd96f commit 2e5e833
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Mariusz Rusiniak
Mark Hirota
Matt Good
Matt Jeffery
Matthew Kenigsberg
Mattieu Agopian
Mehdi Abaakouk
Michael Manganiello
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1656.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow escaping curly braces in setenv. - by :user:`mkenigs`
4 changes: 3 additions & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ def get(self, name, default=None):
return os.environ.get(name, default)
self._lookupstack.append(name)
try:
self.resolved[name] = res = self.reader._replace(val)
res = self.reader._replace(val)
res = res.replace("\\{", "{").replace("\\}", "}")
self.resolved[name] = res
finally:
self._lookupstack.pop()
return res
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,15 @@ def test_factors_in_setenv(self, newconfig):
assert configs["py27"].setenv["X"] == "1"
assert "X" not in configs["py36"].setenv

def test_curly_braces_in_setenv(self, newconfig):
inisource = """
[testenv]
setenv =
VAR = \{val\}
"""
configs = newconfig([], inisource).envconfigs
assert configs["python"].setenv["VAR"] == "{val}"

def test_factor_use_not_checked(self, newconfig):
inisource = """
[tox]
Expand Down

0 comments on commit 2e5e833

Please sign in to comment.