Skip to content

Commit

Permalink
Merge pull request #599 from ratt-ru/respect-the-environment
Browse files Browse the repository at this point in the history
Respect the environment
  • Loading branch information
SpheMakh authored May 7, 2020
2 parents 4b8b25e + dbbcf90 commit a8333e3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/simulation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stimela/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions stimela/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions stimela/utils/xrun_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a8333e3

Please sign in to comment.