lmod.module module¶
-
class
lmod.module.Module(modules=None, purge=True, force=False, debug=False)[source]¶ Bases:
objectThis is the class declaration of Module class which emulates the
modulecommand provided by LmodPublic Methods:
avail: implements
module availoption version: gets Lmod version by reading LMOD_VERSION is_avail: implementsmodule is-availoption get_command: gets themodule loadcommand based on modules passed to the class test_modules: test themodule loadcommand based on modules passed to the class save: implementsmodule saveoption describe: implementsmodule describeoption get_collection: gets themodule restorecommand with the specified collection name test_collection: test themodule restorecommand with the specified collection name-
avail(name=None)[source]¶ This method implements the
module availcommand. The output of module avail will return available modules in the system. The output is returned as a list using themodule -t availwhich presents the output in a single line per module.Parameters:
Parameters: name (str, optional) – argument passed to module avail. This is used for showing what modules are availableReturns: Return output of module availas a listReturn type: list
-
checkSyntax(name=None)[source]¶ This method implements the
module --checkSyntax loadcommand which is used for checking syntax error for modulefile. The return is an exit code, if its 0 there is no error otherwise there is a syntax error in modulefile.If
nameis specified, we can check check for any modulefile, otherwise we use the default modules passed to the Module class.Parameters:
Parameters: name (str, optional) – argument passed to module --checkSyntax loadto check for syntax error
-
describe(collection='default')[source]¶ Show content of a user collection and implements the command
module describe. By default, if no argument is specified it will resort to showing contents ofdefaultcollection. One can pass a collection name which must be of typestrthat is the user collection name. Internally it will runmodule describe <collection>. If collection name is not of typestr, then an exception ofTypeErrorwill be raised.Parameters:
Parameters: collection (str, optional) – name of user collection to show.
-
get_collection(collection='default')[source]¶ Return the module command to restore a collection. If no argument is specified, it will resort to the
defaultcollection, otherwise one can specify a collection name of typestr. The output will be of typestrsuch asmodule restore default. If argument to class is not of typestrthen an exception of typeTypeErrorwill be raised.Parameters:
Parameters: collection (str, optional) – collection name to restore Returns: return the module restorecommand with the collection nameReturn type: str
-
get_command()[source]¶ Get the actual module load command that can be used to load the given modules.
Returns: return the actual module load command Return type: str
-
is_avail(name)[source]¶ This method implements the
module is-availcommand which is used for checking if a module is available before loading it. The return value is a 0 or 1.Parameters:
Parameters: name (str, required) – argument passed to module is-avail. This is used for checking if module is availableReturns: Return output of module is-avail. This checks if module is available and return code is a 0 or 1Return type: int
-
overview(name=None)[source]¶ This method implements the
module overviewcommand. The output of module overview will return list of modules with number of versions available.Parameters: name (str or list, optional) – Specify a list of modules to run module overviewcommandReturns: Return output of module overviewas a string
-
save(collection='default')[source]¶ Save modules specified in Module class into a user collection. This implements the
module savecommand for active modules. In this case, we are saving modules that were passed to the Module class. If no argument is specified, we will save todefaultcollection, but user can specify a collection name, in that case we are runningmodule save <collection>. The collection name must be of typestrin order for this to work, otherwise an exception ofTypeErrorwill be raised.Parameters:
Parameters: collection (str, optional) – collection name to save modules. If none specified, defaultis the collection.
-
spider(name=None)[source]¶ This method invokes
module spidercommand. One can specify input arguments as a string or list type which are converted into string.If no arguments are specified to
Module()and spider class we will return the output ofmodule spidercommand which is a list of all modules.m = Module() m.spider()
If modules are specified during instance creation then we will use those modules during module spider output. In this following example, we will run
module spider gcc pythonm = Module("gcc python") m.spider()
We can also specify modules via spider method which will be read first even if modules are passed during object creation time. In example below
>>> m = Module(["gcc", "python"]) >>> m.modules ['gcc', 'python'] >>> out = m.spider("gcc") >>> print(out) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- gcc: --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Versions: gcc/9.3.0-n7p74fd gcc/10.2.0-37fmsw7 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- For detailed information about a specific "gcc" package (including how to load the modules) use the module's full name. Note that names that have a trailing (E) are extensions provided by other modules. For example: $ module spider gcc/10.2.0-37fmsw7 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Parameters: name (str, list) – Input modules to run module spider. Input can be a string or listReturns: Output of module spidercommand as a string typeReturn type: str
-
test_collection(collection='default')[source]¶ Test the user collection by running
module restoreagainst a collection name. This is useful, to test a user collection is working before using it in your scripts. If no argument is specified, it will test thedefaultcollection. One can specify a user collection name which must of be of typestrand it must exist. The output will be a return code of themodule restorecommand which would be of typeint. If argument to method is not of typestran exception ofTypeErrorwill be raised.Parameters:
Parameters: collection (str, optional) – collection name to test Returns: return code of module restoreagainst the collection nameReturn type: int
-
test_modules(login=False)[source]¶ Test all modules passed to Module class by loading them using
module load. The default behavior is to run the command in a sub-shell but this can be changed to run in a new login shell iflogin=Trueis specified. The return value is a return code (typeint) of themodule loadcommand.Parameters:
Parameters: login (bool, optional) – When login=Trueis set, it will run the test in a login shell, the default is to run in a sub-shellReturns: return code of module loadcommandReturn type: int
-