diff --git a/apps/cli/executables/vulture/test/localscript.condor b/apps/cli/executables/vulture/test/localscript.condor new file mode 100644 index 0000000000000000000000000000000000000000..757b5d3f4c5ded045cabafdcbb114d5ecafbce37 --- /dev/null +++ b/apps/cli/executables/vulture/test/localscript.condor @@ -0,0 +1,4 @@ +executable = test.sh +arguments = hello + +queue \ No newline at end of file diff --git a/apps/cli/executables/vulture/test/test.sh b/apps/cli/executables/vulture/test/test.sh new file mode 100755 index 0000000000000000000000000000000000000000..3747a7ba08ee591c41b7c518e430d2802137eac4 --- /dev/null +++ b/apps/cli/executables/vulture/test/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo $* diff --git a/apps/cli/executables/vulture/test/test_vulture.py b/apps/cli/executables/vulture/test/test_vulture.py index 32487089a894e74197861c2ad983594783bd2f44..c987b2d789e38e250e93f705c27c3f2b0995641a 100644 --- a/apps/cli/executables/vulture/test/test_vulture.py +++ b/apps/cli/executables/vulture/test/test_vulture.py @@ -56,6 +56,16 @@ def test_job_stdout(): os.remove("null.error") +def test_shell_script_in_working_directory(caplog): + test_job = Job("test/localscript.condor") + test_job.execute() + with open("test.sh.out", "r") as f: + contents = f.read() + assert "hello" in contents + os.remove("test.sh.out") + os.remove("test.sh.error") + + def test_job_stderr(): """ Test that vulture writes correct output from stderr to a log file diff --git a/apps/cli/executables/vulture/vulture/condorlite.py b/apps/cli/executables/vulture/vulture/condorlite.py index 1244613d2aae94ec3f1a194c94028ec4bbe1725c..ab37247355bd0e1bd4f8d16678db378090fe7f98 100644 --- a/apps/cli/executables/vulture/vulture/condorlite.py +++ b/apps/cli/executables/vulture/vulture/condorlite.py @@ -133,6 +133,7 @@ class Job: :param write_log: Boolean that determines whether a log file will be written """ self.fields, self.command = self.parse(file) + self.job_directory = Path(file).resolve().parent self.write_log = write_log if self.write_log: if self.fields.get("executable"): @@ -216,8 +217,19 @@ class Job: # Execute if self.fields.get("executable"): + # So there is a thing that can happen here, where the condor file refers to a script in the same directory + # HTCondor will happily execute such a thing, but using subprocess.run like this will not. So we have to + # detect if there is a file in the current directory with the same name as the executable, and if there is, + # we must prefix with "./" to get the right behavior. + if (self.job_directory / self.fields["executable"]).exists(): + executable = str( + (self.job_directory / self.fields["executable"]).resolve() + ) + else: + executable = self.fields["executable"] + process = subprocess.run( - [self.fields["executable"], self.fields["arguments"]], + [executable, self.fields["arguments"]], capture_output=capture_output, text=True, )