diff --git a/examples/simulation_pipeline.py b/examples/simulation_pipeline.py index 7b8b7bef..ea1c57f1 100644 --- a/examples/simulation_pipeline.py +++ b/examples/simulation_pipeline.py @@ -25,7 +25,7 @@ log_dir=os.path.join(OUTPUT, "logs"), ) -pipeline.JOB_TYPE = "singularity" +pipeline.JOB_TYPE = "docker" # 1: Make empty MS pipeline.add("cab/simms", # Executor image to start container from diff --git a/stimela/recipe.py b/stimela/recipe.py index f599da42..4451197c 100644 --- a/stimela/recipe.py +++ b/stimela/recipe.py @@ -272,6 +272,10 @@ def setup_job(self, image, config, if self.jtype == "singularity": cont.RUNSCRIPT = f"/{self.jtype}" + if _cab.base.startswith("stimela/casa") or _cab.base.startswith("stimela/simms"): + cont.add_environ("LANGUAGE", "en_US.UTF-8") + cont.add_environ("LANG", "en_US.UTF-8") + cont.add_environ("LC_ALL", "en_US.UTF-8") cont.execdir = self.workdir else: cont.RUNSCRIPT = f"/{self.jtype}_run" diff --git a/stimela/singularity.py b/stimela/singularity.py index e7951a65..b9de2731 100644 --- a/stimela/singularity.py +++ b/stimela/singularity.py @@ -70,6 +70,8 @@ def __init__(self, image, name, self.time_out = time_out self.execdir = execdir + self._env = os.environ.copy() + hashname = hashlib.md5(name.encode('utf-8')).hexdigest()[:3] self.name = hashname if version < "3.0.0" else name @@ -94,7 +96,7 @@ def add_environ(self, key, value): key_ = f"SINGULARITYENV_{key}" self.logger.debug(f"Setting singularity environmental variable {key_}={value} on host") - os.environ[key_] = value + self._env[key_] = value return 0 @@ -119,7 +121,7 @@ def run(self, *args, output_wrangler=None): utils.xrun(f"cd {self.execdir} && singularity", ["run", "--workdir", self.execdir] \ + list(args) + [volumes, self.image, self.RUNSCRIPT], log=self.logger, timeout=self.time_out, output_wrangler=output_wrangler, - logfile=self.logfile) + env=self._env, logfile=self.logfile) self.status = "exited" diff --git a/stimela/utils/xrun_poll.py b/stimela/utils/xrun_poll.py index 5c290720..eb4706a4 100644 --- a/stimela/utils/xrun_poll.py +++ b/stimela/utils/xrun_poll.py @@ -98,7 +98,7 @@ def xrun_nolog(command, name=None): return 0 -def xrun(command, options, log=None, logfile=None, timeout=-1, kill_callback=None, output_wrangler=None): +def xrun(command, options, log=None, logfile=None, env=None, timeout=-1, kill_callback=None, output_wrangler=None): command_name = command # this part could be inside the container @@ -119,7 +119,7 @@ def xrun(command, options, log=None, logfile=None, timeout=-1, kill_callback=Non start_time = time.time() proc = subprocess.Popen([command], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - bufsize=1, universal_newlines=True, shell=True) + env=env, bufsize=1, universal_newlines=True, shell=True) poller = Poller(log=log) poller.register_process(proc)