lmod.module module¶
-
class
lmod.module.
Module
(modules=None, purge=True, force=False, debug=False)[source]¶ Bases:
object
This is the class declaration of Module class which emulates the
module
command provided by LmodPublic Methods:
avail: implements
module avail
option version: gets Lmod version by reading LMOD_VERSION is_avail: implementsmodule is-avail
option get_command: gets themodule load
command based on modules passed to the class test_modules: test themodule load
command based on modules passed to the class save: implementsmodule save
option describe: implementsmodule describe
option get_collection: gets themodule restore
command with the specified collection name test_collection: test themodule restore
command with the specified collection name-
avail
(name=None)[source]¶ This method implements the
module avail
command. The output of module avail will return available modules in the system. The output is returned as a list using themodule -t avail
which 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 avail
as a listReturn type: list
-
checkSyntax
(name=None)[source]¶ This method implements the
module --checkSyntax load
command 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
name
is 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 load
to 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 ofdefault
collection. One can pass a collection name which must be of typestr
that is the user collection name. Internally it will runmodule describe <collection>
. If collection name is not of typestr
, then an exception ofTypeError
will 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
default
collection, otherwise one can specify a collection name of typestr
. The output will be of typestr
such asmodule restore default
. If argument to class is not of typestr
then an exception of typeTypeError
will be raised.Parameters:
Parameters: collection (str, optional) – collection name to restore Returns: return the module restore
command 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-avail
command 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 overview
command. 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 overview
commandReturns: Return output of module overview
as a string
-
save
(collection='default')[source]¶ Save modules specified in Module class into a user collection. This implements the
module save
command 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 todefault
collection, but user can specify a collection name, in that case we are runningmodule save <collection>
. The collection name must be of typestr
in order for this to work, otherwise an exception ofTypeError
will be raised.Parameters:
Parameters: collection (str, optional) – collection name to save modules. If none specified, default
is the collection.
-
spider
(name=None)[source]¶ This method invokes
module spider
command. 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 spider
command 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 python
m = 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 spider
command as a string typeReturn type: str
-
test_collection
(collection='default')[source]¶ Test the user collection by running
module restore
against 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 thedefault
collection. One can specify a user collection name which must of be of typestr
and it must exist. The output will be a return code of themodule restore
command which would be of typeint
. If argument to method is not of typestr
an exception ofTypeError
will be raised.Parameters:
Parameters: collection (str, optional) – collection name to test Returns: return code of module restore
against 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=True
is specified. The return value is a return code (typeint
) of themodule load
command.Parameters:
Parameters: login (bool, optional) – When login=True
is set, it will run the test in a login shell, the default is to run in a sub-shellReturns: return code of module load
commandReturn type: int
-