From 7821a667da9115d3482c32fe3f54e33bed44b2a3 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Sun, 11 Feb 2024 23:39:33 +0100 Subject: [PATCH] use set_vars_verbatim --- sisyphus/tools.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sisyphus/tools.py b/sisyphus/tools.py index 07d4bdf..a4fd52f 100644 --- a/sisyphus/tools.py +++ b/sisyphus/tools.py @@ -483,6 +483,7 @@ def __init__(self, *, cleanup_env: bool = True): self.cleanup_env = cleanup_env self.keep_vars = set() self.set_vars = {} + self.set_vars_verbatim = {} # does not go through string.Template(v).substitute def keep(self, var): if isinstance(var, str): @@ -497,10 +498,7 @@ def set(self, var, value=None): self.set_vars[var] = value def set_var(self, key: str, value: str, *, allow_env_substitute: bool = False): - if not allow_env_substitute: - # Need to escape $ for string.Template.substitute below. - value = value.replace("$", "$$") - self.set_vars[key] = value + (self.set_vars if allow_env_substitute else self.set_vars_verbatim)[key] = value def modify_environment(self): import os @@ -519,6 +517,9 @@ def modify_environment(self): else: os.environ[k] = str(v) + for k, v in self.set_vars_verbatim.items(): + os.environ[k] = v + for k, v in os.environ.items(): logging.debug("environment var %s=%s" % (k, v))