Skip to content

Commit

Permalink
Merge pull request #19 from mbhall88/master
Browse files Browse the repository at this point in the history
Add some catches for passed args
  • Loading branch information
martinghunt authored Feb 28, 2019
2 parents 192f610 + cc5852d commit 9682cb7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions farmpy/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@
import subprocess
import getpass
import os
from pathlib import Path


class Error (Exception): pass


class NoCommandGiven(Exception):
"""Raised when no command is passed."""
pass


class DirectoryDoesNotExist(Exception):
"""Raised when log directory doesn't exist."""
pass


class Job:
def __init__(self, out, error, name, queue, mem, cmd,
array_start=0, array_end=0,
Expand Down Expand Up @@ -235,6 +247,21 @@ def _make_resources_string(self):


def _make_output_files_string(self):
log_out_dir = Path(self.stdout_file).parent
log_err_dir = Path(self.stderr_file).parent

# make sure the log directories exist
if not log_out_dir.exists():
raise DirectoryDoesNotExist(
"Directory for stdout log does not exist: {}".format(
str(log_out_dir.absolute()))
)
elif not log_err_dir.exists():
raise DirectoryDoesNotExist(
"Directory for stderr log does not exist: {}".format(
str(log_err_dir.absolute()))
)

if self.array_start > 0:
return '-o ' + self.stdout_file + '.%I -e ' + self.stderr_file + '.%I'
else:
Expand All @@ -259,6 +286,9 @@ def _make_dependencies_string(self):


def _make_command_string(self):
if not self.command:
raise NoCommandGiven("No command given to run.")

command = ''

if self.checkpoint:
Expand Down
9 changes: 9 additions & 0 deletions farmpy/tests/lsf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_make_output_files_string(self):
self.assertEqual('-o out -e error', bsub._make_output_files_string())
bsub = lsf.Job('out', 'error', 'name', 'queue', 1, 'cmd', array_start=1, array_end=42)
self.assertEqual('-o out.%I -e error.%I', bsub._make_output_files_string())
bsub = lsf.Job('doesntexist/out', 'error', 'name', 'queue', 1, 'cmd')
with self.assertRaises(lsf.DirectoryDoesNotExist):
bsub._make_output_files_string()
bsub = lsf.Job('out', 'doesntexist/error', 'name', 'queue', 1, 'cmd')
with self.assertRaises(lsf.DirectoryDoesNotExist):
bsub._make_output_files_string()

def test_make_job_name_string(self):
'''Check that the name of the job is set correctly'''
Expand Down Expand Up @@ -128,6 +134,9 @@ def test_make_command_string(self):
self.assertEqual('cmd.INDEX', bsub._make_command_string())
bsub = lsf.Job('out', 'error', 'name', 'queue', 1, 'cmd.INDEX foo bar.INDEX', array_start=1, array_end=42)
self.assertEqual('cmd.\$LSB_JOBINDEX foo bar.\$LSB_JOBINDEX', bsub._make_command_string())
bsub = lsf.Job('out', 'error', 'name', 'queue', 1, '')
with self.assertRaises(lsf.NoCommandGiven):
bsub._make_command_string()

def test_add_dependency(self):
bsub = lsf.Job('out', 'error', 'name', 'queue', 1, 'cmd')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='farmpy',
version='0.42.0',
version='0.42.1',
description='Package to run farm jobs - currently LSF supported',
author='Martin Hunt',
author_email='[email protected]',
Expand Down

0 comments on commit 9682cb7

Please sign in to comment.