Skip to content

Commit

Permalink
Issue #75
Browse files Browse the repository at this point in the history
Further problems with absolute paths where a keyerror would occur on the
executable. A fix has been applied where the os.path.basename is run
against the executable. This should at least allow longbow to match the
executables that it knows.
  • Loading branch information
jimboid committed Nov 7, 2017
1 parent 33eb563 commit 0c30617
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
22 changes: 12 additions & 10 deletions longbow/corelibs/applications.py
Expand Up @@ -147,7 +147,7 @@ def processjobs(jobs):

filelist = []
appplugins = getattr(apps, "PLUGINEXECS")
app = appplugins[jobs[job]["executable"]]
app = appplugins[os.path.basename(jobs[job]["executable"])]
foundflags = []
substitution = {}

Expand Down Expand Up @@ -180,7 +180,7 @@ def processjobs(jobs):
"The local job directory '{0}' cannot be found for job '{1}'"
.format(jobs[job]["localworkdir"], job))

# Detect command-line parameter substitutions.
# Hook to determine command-line parameter substitutions.
try:

substitution = getattr(
Expand Down Expand Up @@ -222,8 +222,9 @@ def _flagvalidator(job, foundflags):
"""Validate that required command-line flags are provided."""
# Initialisation.
appplugins = getattr(apps, "PLUGINEXECS")
app = appplugins[job["executable"]]
execdata = getattr(apps, app.lower()).EXECDATA[job["executable"]]
executable = os.path.basename(job["executable"])
app = appplugins[executable]
execdata = getattr(apps, app.lower()).EXECDATA[executable]

# Final check for if any required flags are missing.
flags = list(set(execdata["requiredfiles"]) - set(foundflags))
Expand Down Expand Up @@ -288,17 +289,17 @@ def _proccommandline(job, filelist, foundflags, substitution):
"""
# Initialisation.
appplugins = getattr(apps, "PLUGINEXECS")
app = appplugins[job["executable"]]
executable = os.path.basename(job["executable"])
app = appplugins[executable]
args = list(job["executableargs"])
subexecs = getattr(
apps, app.lower()).EXECDATA[job["executable"]]["subexecutables"]
subexe = getattr(apps, app.lower()).EXECDATA[executable]["subexecutables"]

try:

for arg in args:

if (arg != "<" and arg != ">" and arg[0] != "-" and
arg not in subexecs):
arg not in subexe):

foundflags = _procfiles(job, arg, filelist, foundflags,
substitution)
Expand All @@ -318,7 +319,8 @@ def _procfiles(job, arg, filelist, foundflags, substitution):
"""Processor for finding flags and files."""
# Initialisation.
appplugins = getattr(apps, "PLUGINEXECS")
app = appplugins[job["executable"]]
executable = os.path.basename(job["executable"])
app = appplugins[executable]
initargs = list(job["executableargs"])

# Check for as many files as there are replicates (default of 1).
Expand Down Expand Up @@ -349,7 +351,7 @@ def _procfiles(job, arg, filelist, foundflags, substitution):

_markfoundfiles(arg, initargs, foundflags)

# Search input file for any file dependencies.
# Hook to search input file for any file dependencies.
try:

getattr(apps, app.lower()).file_parser(
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/corelibs_applications/test_processjobs.py
Expand Up @@ -98,7 +98,38 @@ def test_processjobs_pardir():

@mock.patch('longbow.corelibs.applications._proccommandline')
@mock.patch('longbow.corelibs.applications._flagvalidator')
def test_processjobs_singlejob(m_validator, m_proccommandline):
def test_processjobs_singlejob1(m_validator, m_proccommandline):

"""Test for single job, make sure parameters are all set correctly."""

jobs = {
"jobone": {
"executableargs": ["-i", "input", "-c", "coords", "-p", "topol"],
"localworkdir": os.path.join(os.getcwd(),
"tests/standards/jobs/single"),
"executable": "/some/path/pmemd.MPI",
"upload-include": "",
"upload-exclude": ""
}
}

m_proccommandline.side_effect = _proccommandline

m_validator.return_value = None

processjobs(jobs)

assert jobs["jobone"]["upload-exclude"] == "*"
assert jobs["jobone"]["localworkdir"] == os.path.join(
os.getcwd(), "tests/standards/jobs/single")
assert jobs["jobone"]["executableargs"] == \
"/some/path/pmemd.MPI -i input -c coords -p topol"
assert jobs["jobone"]["upload-include"] == "input, coords, topol"


@mock.patch('longbow.corelibs.applications._proccommandline')
@mock.patch('longbow.corelibs.applications._flagvalidator')
def test_processjobs_singlejob2(m_validator, m_proccommandline):

"""Test for single job, make sure parameters are all set correctly."""

Expand Down

0 comments on commit 0c30617

Please sign in to comment.