From 8d0186375302a5c4b25070f112ff957ab0a542a2 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 12 Jun 2024 06:03:13 -0600 Subject: [PATCH] add support for parsing script Signed-off-by: vsoch --- jobspec/transformer/flux/steps.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/jobspec/transformer/flux/steps.py b/jobspec/transformer/flux/steps.py index 54fb5ad..691e416 100644 --- a/jobspec/transformer/flux/steps.py +++ b/jobspec/transformer/flux/steps.py @@ -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/(?Pbash|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 @@ -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/(?Pbash|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):