Skip to content

Commit

Permalink
use set_vars_verbatim
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Feb 11, 2024
1 parent 29c56f6 commit 7821a66
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sisyphus/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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))

Expand Down

0 comments on commit 7821a66

Please sign in to comment.