easybuild.tools.module_generator module

Generating module files.

author:Stijn De Weirdt (Ghent University)
author:Dries Verdegem (Ghent University)
author:Kenneth Hoste (Ghent University)
author:Pieter De Baets (Ghent University)
author:Jens Timmerman (Ghent University)
author:Fotis Georgatos (Uni.Lu, NTUA)
author:Damian Alvarez (Forschungszentrum Juelich GmbH)
class easybuild.tools.module_generator.ModuleGenerator(application, fake=False)

Bases: object

Class for generating module files.

CHARS_TO_ESCAPE = None
INDENTATION = ' '
MODULE_FILE_EXTENSION = None
MODULE_SHEBANG = None
SYNTAX = None
append_paths(key, paths, allow_abs=False, expand_relpaths=True)

Generate append-path statements for the given list of paths.

Parameters:
  • key – environment variable to append paths to
  • paths – list of paths to append
  • allow_abs – allow providing of absolute paths
  • expand_relpaths – expand relative paths into absolute paths (by prefixing install dir)
check_group(group, error_msg=None)

Generate a check of the software group and the current user, and refuse to load the module if the user don’t belong to the group

Parameters:
  • group – string with the group name
  • error_msg – error message to print for users outside that group
comment(msg)

Return given string formatted as a comment.

conditional_statement(condition, body, negative=False, else_body=None)

Return formatted conditional statement, with given condition and body.

Parameters:
  • condition – string containing the statement for the if condition (in correct syntax)
  • body – (multiline) string with if body (in correct syntax, without indentation)
  • negative – boolean indicating whether the condition should be negated
  • else_body – optional body for ‘else’ part

Create moduleclass symlink(s) to actual module file.

define_env_var(env_var)

Determine whether environment variable with specified name should be defined or not.

Parameters:env_var – name of environment variable to check
get_description(conflict=True)

Generate a description.

get_module_filepath(fake=False, mod_path_suffix=None)

Return path to module file.

get_modules_path(fake=False, mod_path_suffix=None)

Return path to directory where module files should be generated in.

getenv_cmd(envvar)

Return module-syntax specific code to get value of specific environment variable.

load_module(mod_name, recursive_unload=False, unload_modules=None)

Generate load statement for specified module.

Parameters:
  • mod_name – name of module to generate load statement for
  • recursive_unload – boolean indicating whether the ‘load’ statement should be reverted on unload
  • unload_modules – name(s) of module to unload first
msg_on_load(msg)

Add a message that should be printed when loading the module.

prepend_paths(key, paths, allow_abs=False, expand_relpaths=True)

Generate prepend-path statements for the given list of paths.

Parameters:
  • key – environment variable to append paths to
  • paths – list of paths to append
  • allow_abs – allow providing of absolute paths
  • expand_relpaths – expand relative paths into absolute paths (by prefixing install dir)
set_alias(key, value)

Generate set-alias statement in modulefile for the given key/value pair.

set_as_default(module_folder_path, module_version)

Set generated module as default module

Parameters:
  • module_folder_path – module folder path, e.g. $HOME/easybuild/modules/all/Bison
  • module_version – module version, e.g. 3.0.4
set_environment(key, value, relpath=False)

Generate a quoted setenv statement for the given key/value pair.

Parameters:
  • key – name of environment variable to define
  • value – value to define environment variable with
  • relpath – value is path relative to installation prefix
swap_module(mod_name_out, mod_name_in, guarded=True)

Generate swap statement for specified module names.

Parameters:
  • mod_name_out – name of module to unload (swap out)
  • mod_name_in – name of module to load (swap in)
  • guarded – guard ‘swap’ statement, fall back to ‘load’ if module being swapped out is not loaded
unload_module(mod_name)

Generate unload statement for specified module.

Parameters:mod_name – name of module to generate unload statement for
update_paths(key, paths, prepend=True, allow_abs=False, expand_relpaths=True)

Generate prepend-path or append-path statements for the given list of paths.

Parameters:
  • key – environment variable to prepend/append paths to
  • paths – list of paths to prepend
  • prepend – whether to prepend (True) or append (False) paths
  • allow_abs – allow providing of absolute paths
  • expand_relpaths – expand relative paths into absolute paths (by prefixing install dir)
use(paths, prefix=None, guarded=False)

Generate module use statements for given list of module paths. :param paths: list of module path extensions to generate use statements for; paths will be quoted :param prefix: optional path prefix; not quoted, i.e., can be a statement :param guarded: use statements will be guarded to only apply if path exists

class easybuild.tools.module_generator.ModuleGeneratorLua(application, fake=False)

Bases: easybuild.tools.module_generator.ModuleGenerator

Class for generating Lua module files.

CHARS_TO_ESCAPE = []
END_STR = ']==]'
LOAD_REGEX = '^\\s*load\\("(\\S+)"'
LOAD_TEMPLATE = 'load("%(mod_name)s")'
MODULE_FILE_EXTENSION = '.lua'
MODULE_SHEBANG = ''
PATH_JOIN_TEMPLATE = 'pathJoin(root, "%s")'
START_STR = '[==['
SYNTAX = 'Lua'
UPDATE_PATH_TEMPLATE = '%s_path("%s", %s)'
check_group(group, error_msg=None)

Generate a check of the software group and the current user, and refuse to load the module if the user don’t belong to the group

Parameters:
  • group – string with the group name
  • error_msg – error message to print for users outside that group
check_str(txt)

Check whether provided string has any unwanted substrings in it.

comment(msg)

Return string containing given message as a comment.

conditional_statement(condition, body, negative=False, else_body=None)

Return formatted conditional statement, with given condition and body.

Parameters:
  • condition – string containing the statement for the if condition (in correct syntax)
  • body – (multiline) string with if body (in correct syntax, without indentation)
  • negative – boolean indicating whether the condition should be negated
  • else_body – optional body for ‘else’ part
get_description(conflict=True)

Generate a description.

getenv_cmd(envvar)

Return module-syntax specific code to get value of specific environment variable.

load_module(mod_name, recursive_unload=False, unload_modules=None)

Generate load statement for specified module.

Parameters:
  • mod_name – name of module to generate load statement for
  • recursive_unload – boolean indicating whether the ‘load’ statement should be reverted on unload
  • unload_modules – name(s) of module to unload first
msg_on_load(msg)

Add a message that should be printed when loading the module.

set_alias(key, value)

Generate set-alias statement in modulefile for the given key/value pair.

set_as_default(module_folder_path, module_version)

Create a symlink named ‘default’ inside the package’s module folder in order to set the default module version

Parameters:
  • module_folder_path – module folder path, e.g. $HOME/easybuild/modules/all/Bison
  • module_version – module version, e.g. 3.0.4
set_environment(key, value, relpath=False)

Generate a quoted setenv statement for the given key/value pair.

Parameters:
  • key – name of environment variable to define
  • value – value to define environment variable with
  • relpath – value is path relative to installation prefix
swap_module(mod_name_out, mod_name_in, guarded=True)

Generate swap statement for specified module names.

Parameters:
  • mod_name_out – name of module to unload (swap out)
  • mod_name_in – name of module to load (swap in)
  • guarded – guard ‘swap’ statement, fall back to ‘load’ if module being swapped out is not loaded
unload_module(mod_name)

Generate unload statement for specified module.

Parameters:mod_name – name of module to generate unload statement for
update_paths(key, paths, prepend=True, allow_abs=False, expand_relpaths=True)

Generate prepend_path or append_path statements for the given list of paths

Parameters:
  • key – environment variable to prepend/append paths to
  • paths – list of paths to prepend/append
  • prepend – whether to prepend (True) or append (False) paths
  • allow_abs – allow providing of absolute paths
  • expand_relpaths – expand relative paths into absolute paths (by prefixing install dir)
use(paths, prefix=None, guarded=False)

Generate module use statements for given list of module paths. :param paths: list of module path extensions to generate use statements for; paths will be quoted :param prefix: optional path prefix; not quoted, i.e., can be a statement :param guarded: use statements will be guarded to only apply if path exists

class easybuild.tools.module_generator.ModuleGeneratorTcl(application, fake=False)

Bases: easybuild.tools.module_generator.ModuleGenerator

Class for generating Tcl module files.

CHARS_TO_ESCAPE = ['$']
LOAD_REGEX = '^\\s*module\\s+load\\s+(\\S+)'
LOAD_TEMPLATE = 'module load %(mod_name)s'
MODULE_FILE_EXTENSION = ''
MODULE_SHEBANG = '#%Module'
SYNTAX = 'Tcl'
check_group(group, error_msg=None)

Generate a check of the software group and the current user, and refuse to load the module if the user don’t belong to the group

Parameters:
  • group – string with the group name
  • error_msg – error message to print for users outside that group
comment(msg)

Return string containing given message as a comment.

conditional_statement(condition, body, negative=False, else_body=None)

Return formatted conditional statement, with given condition and body.

Parameters:
  • condition – string containing the statement for the if condition (in correct syntax)
  • body – (multiline) string with if body (in correct syntax, without indentation)
  • negative – boolean indicating whether the condition should be negated
  • else_body – optional body for ‘else’ part
get_description(conflict=True)

Generate a description.

getenv_cmd(envvar)

Return module-syntax specific code to get value of specific environment variable.

load_module(mod_name, recursive_unload=False, unload_modules=None)

Generate load statement for specified module.

Parameters:
  • mod_name – name of module to generate load statement for
  • recursive_unload – boolean indicating whether the ‘load’ statement should be reverted on unload
  • unload_module – name(s) of module to unload first
msg_on_load(msg)

Add a message that should be printed when loading the module.

set_alias(key, value)

Generate set-alias statement in modulefile for the given key/value pair.

set_as_default(module_folder_path, module_version)

Create a .version file inside the package module folder in order to set the default version for TMod

Parameters:
  • module_folder_path – module folder path, e.g. $HOME/easybuild/modules/all/Bison
  • module_version – module version, e.g. 3.0.4
set_environment(key, value, relpath=False)

Generate a quoted setenv statement for the given key/value pair.

Parameters:
  • key – name of environment variable to define
  • value – value to define environment variable with
  • relpath – value is path relative to installation prefix
swap_module(mod_name_out, mod_name_in, guarded=True)

Generate swap statement for specified module names.

Parameters:
  • mod_name_out – name of module to unload (swap out)
  • mod_name_in – name of module to load (swap in)
  • guarded – guard ‘swap’ statement, fall back to ‘load’ if module being swapped out is not loaded
unload_module(mod_name)

Generate unload statement for specified module.

Parameters:mod_name – name of module to generate unload statement for
update_paths(key, paths, prepend=True, allow_abs=False, expand_relpaths=True)

Generate prepend-path or append-path statements for the given list of paths.

Parameters:
  • key – environment variable to prepend/append paths to
  • paths – list of paths to prepend
  • prepend – whether to prepend (True) or append (False) paths
  • allow_abs – allow providing of absolute paths
  • expand_relpaths – expand relative paths into absolute paths (by prefixing install dir)
use(paths, prefix=None, guarded=False)

Generate module use statements for given list of module paths. :param paths: list of module path extensions to generate use statements for; paths will be quoted :param prefix: optional path prefix; not quoted, i.e., can be a statement :param guarded: use statements will be guarded to only apply if path exists

easybuild.tools.module_generator.avail_module_generators()

Return all known module syntaxes.

easybuild.tools.module_generator.dependencies_for(mod_name, modtool, depth=9223372036854775807)

Obtain a list of dependencies for the given module, determined recursively, up to a specified depth (optionally) :param depth: recursion depth (default is sys.maxint, which should be equivalent to infinite recursion depth)

easybuild.tools.module_generator.module_generator(app, fake=False)

Return ModuleGenerator instance that matches the selected module file syntax to be used

easybuild.tools.module_generator.module_load_regex(modfilepath)

Return the correct (compiled) regex to extract dependencies, depending on the module file type (Lua vs Tcl)