Skip to content

Commit

Permalink
persist environment
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Jun 12, 2024
1 parent 7a5321f commit 6dce1b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions jobspec/transformer/flux/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def write_job_script(self, command):
command = command.strip()
match = re.match("#!/bin/(?P<executable>bash|sh|python)", command)
terms = match.groupdict()
tmpfile = utils.get_tmpfile(prefix="jobscript-")
tmpfile = utils.get_tmpfile(prefix="jobscript-", suffix=".sh")

# Clean up (activate later)
command += f"\n#rm -rf {tmpfile}"
# Clean self up
command += f"\nrm -rf {tmpfile}"
utils.write_file(command, tmpfile)
return [terms["executable"], tmpfile]

Expand Down Expand Up @@ -119,7 +119,6 @@ def prepare(self, command=None, waitable=False):
for key, value in attributes.get("environment", {}).items():
cmd += [f"--env={key}={value}"]

print(cmd)
# Note that you need to install our frobnicator plugin
# for this to work. See the examples/depends_on directory
for depends_on in task.get("depends_on") or []:
Expand Down
6 changes: 3 additions & 3 deletions jobspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def recursive_find(base, pattern="[.]py"):
yield filepath


def get_tmpfile(tmpdir=None, prefix=""):
def get_tmpfile(tmpdir=None, prefix="", suffix=None):
"""
Get a temporary file with an optional prefix.
"""
Expand All @@ -51,7 +51,7 @@ def get_tmpfile(tmpdir=None, prefix=""):
if tmpdir:
prefix = os.path.join(tmpdir, os.path.basename(prefix))

fd, tmp_file = tempfile.mkstemp(prefix=prefix)
fd, tmp_file = tempfile.mkstemp(prefix=prefix, suffix=suffix)
os.close(fd)

return tmp_file
Expand Down Expand Up @@ -120,7 +120,7 @@ def run_command(cmd, stream=False, check_output=False, return_code=0):
If check_output is True, check against an expected return code.
"""
stdout = subprocess.PIPE if not stream else None
output = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=stdout)
output = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=stdout, env=os.environ.copy())
t = output.communicate()[0], output.returncode
output = {"message": t[0], "return_code": t[1]}

Expand Down

0 comments on commit 6dce1b9

Please sign in to comment.