Repository: HECBioSim/Longbow

Issue:
module override parameter has gone missing
In older versions of Longbow there used to be a MODULEOVERRIDE parameter that could be optionally provided in application plugin files to alter the default naming of modules from the name of the plugin file to something else. This could be used by users to set the module name if something peculiar had been used.

This should be restated along with tests, as along the line this functionality has disappeared.

This will need adding to dev docs as well.

Discussion:

Patch:
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 @@ MODULES = pkgutil.iter_modules(path=[PATH])
 
 EXECLIST = []
 PLUGINEXECS = {}
+MODNAMEOVERRIDES = {}
 
 # Loop through all the modules in the plugin.
 for loader, modulename, ispkg in MODULES:
@@ -61,3 +62,12 @@ for loader, modulename, ispkg in MODULES:
 
             # 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


Test patch:
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"