Skip to content

Commit

Permalink
Merge pull request #3 from boegel/modules-unload-deps
Browse files Browse the repository at this point in the history
don't include 'if is-loaded' guard when recursive module unloading is requested
  • Loading branch information
pescobar committed Feb 10, 2014
2 parents df6c6e6 + f39f192 commit cdf7507
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
20 changes: 10 additions & 10 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ def load_module(self, mod_name, recursive_unload=False):
Generate load statements for module.
"""
if recursive_unload:
# wrapping the module name in single quotes enables auto-unloading of dependencies on unload
condition = "is-loaded '%(mod_name)s'"
# not wrapping the 'module load' with an is-loaded guard ensures recursive unloading;
# when "module unload" is called on the module in which the depedency "module load" is present,
# it will get translated to "module unload"
load_statement = ["module load %(mod_name)s"]
else:
condition = "is-loaded %(mod_name)s"
return '\n'.join([
"",
"if { ![%s] } {" % condition,
" module load %(mod_name)s",
"}",
"",
]) % {'mod_name': mod_name}
load_statement = [
"if { ![is-loaded %(mod_name)s] } {",
" module load %(mod_name)s",
"}",
]
return '\n'.join([""] + load_statement + [""]) % {'mod_name': mod_name}

def unload_module(self, mod_name):
"""
Expand Down
8 changes: 6 additions & 2 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ def test_load(self):
]
self.assertEqual('\n'.join(expected), self.modgen.load_module("mod_name"))

# with recursive unloading: module name wrapped in single quotes
expected[1] = "if { ![is-loaded 'mod_name'] } {"
# with recursive unloading: no if is-loaded guard
expected = [
"",
"module load mod_name",
"",
]
self.assertEqual('\n'.join(expected), self.modgen.load_module("mod_name", recursive_unload=True))

def test_unload(self):
Expand Down
6 changes: 3 additions & 3 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,10 @@ def test_recursive_module_unload(self):
except (SystemExit, Exception), err:
pass

toy_module = os.path.join(installpath, 'modules', 'all', 'toy', '0.0')
toy_module = os.path.join(installpath, 'modules', 'all', 'toy', '0.0-deps')
toy_module_txt = read_file(toy_module)
is_loaded_regex = re.compile(r"if { !\[is-loaded 'gompi/1.3.12'\] }", re.M)
self.assertTrue(is_loaded_regex.search(toy_module_txt), "Recursive unloading is used: %s" % toy_module_txt)
is_loaded_regex = re.compile(r"if { !\[is-loaded gompi/1.3.12\] }", re.M)
self.assertFalse(is_loaded_regex.search(toy_module_txt), "Recursive unloading is used: %s" % toy_module_txt)

# cleanup
shutil.rmtree(buildpath)
Expand Down

0 comments on commit cdf7507

Please sign in to comment.