diff --git a/longbow/apps/__init__.py b/longbow/apps/__init__.py index 662c5a6..7ad59fb 100644 --- a/longbow/apps/__init__.py +++ b/longbow/apps/__init__.py @@ -45,6 +45,7 @@ EXECLIST = [] PLUGINEXECS = {} +MODNAMEOVERRIDES = {} # Loop through all the modules in the plugin. for loader, modulename, ispkg in MODULES: @@ -61,3 +62,12 @@ # Compile a dictionary associating executable with plugins. PLUGINEXECS[executable] = modulename + + # Is the module named differently on HPC than the software is called. + try: + + MODNAMEOVERRIDES[modulename] = getattr(mod, "MODULENAME").items() + + except AttributeError: + + pass diff --git a/longbow/configuration.py b/longbow/configuration.py index ac8672a..248d4c1 100644 --- a/longbow/configuration.py +++ b/longbow/configuration.py @@ -429,6 +429,7 @@ def _processconfigsfinalinit(jobs): """Perform some last bits of initialisation.""" # Initialisation. modules = getattr(apps, "PLUGINEXECS") + modoverrides = getattr(apps, "MODNAMEOVERRIDES") modules[""] = "" for job in [a for a in jobs if "lbowconf" not in a]: @@ -452,6 +453,10 @@ def _processconfigsfinalinit(jobs): jobs[job]["modules"] = modules[jobs[job]["executable"]] + if jobs[job]["modules"] in modoverrides: + + jobs[job]["modules"] = modoverrides[jobs[job]["modules"]] + except KeyError: pass diff --git a/tests/unit/configuration/test_processconfigsfinalinit.py b/tests/unit/configuration/test_processconfigsfinalinit.py index 691d085..d86fdfb 100644 --- a/tests/unit/configuration/test_processconfigsfinalinit.py +++ b/tests/unit/configuration/test_processconfigsfinalinit.py @@ -33,11 +33,33 @@ """ This testing module contains the tests for the configuration module methods. """ +try: + + from unittest import mock + +except ImportError: + + import mock import os from longbow.configuration import _processconfigsfinalinit +def pluginsdata(_, data): + + """ + mocked getattr call for external data. + """ + + if data == "PLUGINEXECS": + + return {"testexec": "testmodule"} + + elif data == "MODNAMEOVERRIDES": + + return {"testmodule": "fictionmodule"} + + def test_processconfigsfinalinit1(): """ @@ -102,3 +124,32 @@ def test_processconfigsfinalinit2(): assert jobs["test"]["destdir"] != "" assert jobs["test"]["remoteworkdir"] == "/work/dir" assert jobs["test"]["modules"] == "" + + +@mock.patch('longbow.configuration.getattr') +def test_processconfigsfinalinit3(attr): + + """ + Test the modulename overrides + """ + + jobs = { + "jobone": { + "modules": "", + "localworkdir": "/somepath/to/dir", + "executableargs": "arg1 arg2 arg3", + "executable": "testexec", + "remoteworkdir": "/work/dir" + } + } + + attr.side_effect = pluginsdata + + _processconfigsfinalinit(jobs) + + assert jobs["jobone"]["localworkdir"] == "/somepath/to/dir" + assert jobs["jobone"]["executableargs"] == ["arg1", "arg2", "arg3"] + assert jobs["jobone"]["executable"] == "testexec" + assert jobs["jobone"]["destdir"] != "" + assert jobs["jobone"]["remoteworkdir"] == "/work/dir" + assert jobs["jobone"]["modules"] == "fictionmodule"