From 3c38762fc6acfd6ca93ddc8607133d3a39e6d25c Mon Sep 17 00:00:00 2001 From: Matthew Kenigsberg Date: Wed, 19 Aug 2020 18:15:55 -0500 Subject: [PATCH] Allow escaping curly braces in setenv Currently braces can be escaped, but the backslashes are not removed, making it impossible to add a plain curly brace Signed-off-by: Bernat Gabor --- CONTRIBUTORS | 1 + docs/changelog/1656.bugfix.rst | 1 + src/tox/config/__init__.py | 4 +++- tests/unit/config/test_config.py | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/1656.bugfix.rst diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8eac46c94..16455de28 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -67,6 +67,7 @@ Mariusz Rusiniak Mark Hirota Matt Good Matt Jeffery +Matthew Kenigsberg Mattieu Agopian Mehdi Abaakouk Michael Manganiello diff --git a/docs/changelog/1656.bugfix.rst b/docs/changelog/1656.bugfix.rst new file mode 100644 index 000000000..7e778094a --- /dev/null +++ b/docs/changelog/1656.bugfix.rst @@ -0,0 +1 @@ +Allow escaping curly braces in setenv. - by :user:`mkenigs` diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 891aa59af..fba4b1e2e 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -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 diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 206fdc1c2..eff91fadc 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -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 = r""" + [testenv] + setenv = + VAR = \{val\} + """ + configs = newconfig([], inisource).envconfigs + assert configs["python"].setenv["VAR"] == "{val}" + def test_factor_use_not_checked(self, newconfig): inisource = """ [tox]