Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use unload/load in ModuleGeneratorLua.swap_module, since 'swap' is not supported by Lmod #3685

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,10 @@ def swap_module(self, mod_name_out, mod_name_in, guarded=True):
:param mod_name_in: name of module to load (swap in)
:param guarded: guard 'swap' statement, fall back to 'load' if module being swapped out is not loaded
"""
body = 'swap("%s", "%s")' % (mod_name_out, mod_name_in)
body = '\n'.join([
'unload("%s")' % mod_name_out,
'load("%s")' % mod_name_in,
])
if guarded:
alt_body = self.LOAD_TEMPLATE % {'mod_name': mod_name_in}
swap_statement = [self.conditional_statement(self.is_loaded(mod_name_out), body, else_body=alt_body)]
Expand Down
48 changes: 46 additions & 2 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ def test_swap(self):
else:
expected = '\n'.join([
'',
'swap("foo", "bar")',
'unload("foo")',
'load("bar")',
'',
])

Expand All @@ -637,7 +638,8 @@ def test_swap(self):
expected = '\n'.join([
'',
'if isloaded("foo") then',
' swap("foo", "bar")',
' unload("foo")',
' load("bar")',
'else',
' load("bar")',
'end',
Expand Down Expand Up @@ -1460,6 +1462,48 @@ def test_det_installdir(self):

self.assertEqual(self.modgen.det_installdir(test_modfile), expected)

def test_generated_module_file_swap(self):
"""Test loading a generated module file that includes swap statements."""

if self.MODULE_GENERATOR_CLASS == ModuleGeneratorLua:
mod_ext = '.lua'

if not isinstance(self.modtool, Lmod):
# Lua module files are only supported by Lmod,
# so early exit if that's not the case in the test setup
return

else:
mod_ext = ''

# empty test modules
for modname in ('one/1.0', 'one/1.1'):
modfile = os.path.join(self.test_prefix, modname + mod_ext)
write_file(modfile, self.modgen.MODULE_SHEBANG)

modulepath = os.getenv('MODULEPATH')
if modulepath:
self.modtool.unuse(modulepath)

test_mod = os.path.join(self.test_prefix, 'test', '1.0' + mod_ext)
test_mod_txt = '\n'.join([
self.modgen.MODULE_SHEBANG,
self.modgen.swap_module('one', 'one/1.1'),
])
write_file(test_mod, test_mod_txt)

# prepare environment for loading test module
self.modtool.use(self.test_prefix)
self.modtool.load(['one/1.0'])

self.modtool.load(['test/1.0'])

# check whether resulting environment is correct
loaded_mods = self.modtool.list()
self.assertEqual(loaded_mods[-1]['mod_name'], 'test/1.0')
# one/1.0 module was swapped for one/1.1
self.assertEqual(loaded_mods[-2]['mod_name'], 'one/1.1')


class TclModuleGeneratorTest(ModuleGeneratorTest):
"""Test for module_generator module for Tcl syntax."""
Expand Down