Skip to content

Commit

Permalink
add support for parsing script
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 132e4ff commit 8d01863
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions jobspec/transformer/flux/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ def cleanup(self, filename):
if os.path.exists(filename):
os.remove(filename)

def write_job_script(self, command):
"""
Given a bash, shell, or python command, write
into a script.
"""
match = re.match("#!/bin/(?P<executable>bash|sh|python)", command)
terms = match.groupdict()
tmpfile = utils.get_tmpfile(prefix="jobscript-")

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

def prepare(self, command=None, waitable=False):
"""
Return the command, without flux submit|batch
Expand Down Expand Up @@ -143,13 +157,7 @@ def prepare(self, command=None, waitable=False):

# Case 1: we are given a script to write
if isinstance(command, str) and re.search("#!/bin/(bash|sh|python)", command):
match = re.match("#!/bin/(?P<executable>bash|sh|python)", command)
terms = match.groupdict()
tmpfile = utils.get_tmpfile(prefix="jobscript-")
# Clean up (activate later)
command += f"\n#rm -rf {tmpfile}"
utils.write_file(command, tmpfile)
command = [terms["executable", tmpfile]]
command = self.write_job_script(command)

# String that should be a list
if isinstance(command, str):
Expand Down

0 comments on commit 8d01863

Please sign in to comment.