Skip to content

Commit

Permalink
Merge pull request #6 from ML4GW/err-files
Browse files Browse the repository at this point in the history
Allow suffix to be written to condor submit log, output, and error files
  • Loading branch information
EthanMarx authored Apr 23, 2024
2 parents c71a76a + 0ad7ca0 commit 213774e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pycondor/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Job(BaseNode):
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
(defaults to the directory was the Job was submitted from).
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 @@ -298,13 +302,11 @@ def _make_submit_script(self, makedirs=True, fancyname=True, indag=False):
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 213774e

Please sign in to comment.