debug output includes modulecmd output (#9476)
Debug output now includes the output of modulecmd executions. Only output module content when a failure occurs; always report when a module is loaded/unloaded.
This commit is contained in:
		@@ -99,9 +99,17 @@ def get_module_cmd_from_bash(bashopts=''):
 | 
			
		||||
def unload_module(mod):
 | 
			
		||||
    """Takes a module name and unloads the module from the environment. It does
 | 
			
		||||
    not check whether conflicts arise from the unloaded module"""
 | 
			
		||||
    tty.debug("Unloading module: {0}".format(mod))
 | 
			
		||||
 | 
			
		||||
    modulecmd = get_module_cmd()
 | 
			
		||||
    exec(compile(modulecmd('unload', mod, output=str, error=str), '<string>',
 | 
			
		||||
                 'exec'))
 | 
			
		||||
    unload_output = modulecmd('unload', mod, output=str, error=str)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        exec(compile(unload_output, '<string>', 'exec'))
 | 
			
		||||
    except Exception:
 | 
			
		||||
        tty.debug("Module unload output of {0}:\n{1}\n".format(
 | 
			
		||||
            mod, unload_output))
 | 
			
		||||
        raise
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def load_module(mod):
 | 
			
		||||
@@ -109,6 +117,8 @@ def load_module(mod):
 | 
			
		||||
    load that module. It then loads the provided module. Depends on the
 | 
			
		||||
    modulecmd implementation of modules used in cray and lmod.
 | 
			
		||||
    """
 | 
			
		||||
    tty.debug("Loading module: {0}".format(mod))
 | 
			
		||||
 | 
			
		||||
    # Create an executable of the module command that will output python code
 | 
			
		||||
    modulecmd = get_module_cmd()
 | 
			
		||||
 | 
			
		||||
@@ -116,17 +126,28 @@ def load_module(mod):
 | 
			
		||||
    # We do this without checking that they are already installed
 | 
			
		||||
    # for ease of programming because unloading a module that is not
 | 
			
		||||
    # loaded does nothing.
 | 
			
		||||
    text = modulecmd('show', mod, output=str, error=str).split()
 | 
			
		||||
    for i, word in enumerate(text):
 | 
			
		||||
        if word == 'conflict':
 | 
			
		||||
            unload_module(text[i + 1])
 | 
			
		||||
    module_content = modulecmd('show', mod, output=str, error=str)
 | 
			
		||||
    text = module_content.split()
 | 
			
		||||
    try:
 | 
			
		||||
        for i, word in enumerate(text):
 | 
			
		||||
            if word == 'conflict':
 | 
			
		||||
                unload_module(text[i + 1])
 | 
			
		||||
    except Exception:
 | 
			
		||||
        tty.debug("Module show output of {0}:\n{1}\n".format(
 | 
			
		||||
            mod, module_content))
 | 
			
		||||
        raise
 | 
			
		||||
 | 
			
		||||
    # Load the module now that there are no conflicts
 | 
			
		||||
    # Some module systems use stdout and some use stderr
 | 
			
		||||
    load = modulecmd('load', mod, output=str, error='/dev/null')
 | 
			
		||||
    if not load:
 | 
			
		||||
        load = modulecmd('load', mod, error=str)
 | 
			
		||||
    exec(compile(load, '<string>', 'exec'))
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        exec(compile(load, '<string>', 'exec'))
 | 
			
		||||
    except Exception:
 | 
			
		||||
        tty.debug("Module load output of {0}:\n{1}\n".format(mod, load))
 | 
			
		||||
        raise
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_path_arg_from_module_line(line):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user