Skip to content

Commit

Permalink
allow suffix to be written to condor submit log, output, and error files
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanMarx committed Apr 23, 2024
1 parent c71a76a commit a2632f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pycondor/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Job(BaseNode):
output : str or None, optional
Path to directory where condor Job output files will be written
(default is None, will not be included in Job submit file).
suffix: str or None, optional
Suffix to append to output, log, and error files in the submit file.
submit : str, optional
Path to directory where condor Job submit files will be written
Expand Down Expand Up @@ -136,7 +139,7 @@ class Job(BaseNode):
"""

def __init__(self, name, executable, error=None, log=None, output=None,
submit=None, request_memory=None, request_disk=None,
suffix=None, submit=None, request_memory=None, request_disk=None,
request_cpus=None, getenv=None, universe=None,
initialdir=None, notification=None, requirements=None,
queue=None, extra_lines=None, dag=None, arguments=None,
Expand All @@ -148,6 +151,7 @@ def __init__(self, name, executable, error=None, log=None, output=None,
self.error = error
self.log = log
self.output = output
self.suffix = suffix
self.request_memory = request_memory
self.request_disk = request_disk
self.request_cpus = request_cpus
Expand Down Expand Up @@ -297,14 +301,12 @@ def _make_submit_script(self, makedirs=True, fancyname=True, indag=False):
dir_path = dir_env_var
else:
continue

# Add log/output/error files to submit file lines
if self._has_arg_names:
file_path = os.path.join(dir_path,
'$(job_name).{}'.format(attr))
else:
file_path = os.path.join(dir_path,
'{}.{}'.format(name, attr))

suffix = self.suffix if self.suffix is not None else ''
job_name = name if not self._has_arg_names else '$(job_name)'

file_path = os.path.join(dir_path, "{}{}.{}".format(job_name, suffix, attr))

lines.append('{} = {}'.format(attr, file_path))
setattr(self, '{}_file'.format(attr), file_path)
checkdir(file_path, makedirs)
Expand Down
19 changes: 19 additions & 0 deletions pycondor/tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,22 @@ def test_init_retry_type_fail():
job_with_retry.build()
error = 'retry must be an int'
assert error == str(excinfo.value)


def test_job_suffix(tmpdir):
job = Job(
'jobname',
example_script,
suffix='-suffix',
log = str(tmpdir.join('log')),
error = str(tmpdir.join('error')),
output = str(tmpdir.join('output')),
)
job.build()
with open(job.submit_file, 'r') as f:
lines = f.readlines()

for attr in ['log', 'error', 'output']:
for line in lines:
if line.startswith(attr):
assert f'-suffix.{attr}' in line

0 comments on commit a2632f6

Please sign in to comment.