Skip to content

Commit

Permalink
allow to customize delimiter in ModuleEnvironmentVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
lexming committed Nov 22, 2024
1 parent 561d89e commit a514a42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,22 @@ class ModuleEnvironmentVariable:
Contents of environment variable is a list of unique strings
"""

def __init__(self, contents, top_level_file=False):
def __init__(self, contents, top_level_file=False, delim=os.pathsep):
"""
Initialize new environment variable
Actual contents of the environment variable are held in self.contents
"""
self.contents = contents
self.top_level_file = bool(top_level_file)
self.delim = delim

self.log = fancylogger.getLogger(self.__class__.__name__, fname=False)

def __repr__(self):
return repr(self.contents)

def __str__(self):
return ":".join(self.contents)
return self.delim.join(self.contents)

def __iter__(self):
return iter(self.contents)
Expand Down
6 changes: 6 additions & 0 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,10 +1594,16 @@ def test_module_environment_variable(self):
mod_envar = mod.ModuleEnvironmentVariable(test_paths)
self.assertTrue(hasattr(mod_envar, "contents"))
self.assertTrue(hasattr(mod_envar, "top_level_file"))
self.assertTrue(hasattr(mod_envar, "delim"))
self.assertEqual(mod_envar.contents, test_paths)
self.assertEqual(repr(mod_envar), repr(test_paths))
self.assertEqual(str(mod_envar), "lib:lib64")

mod_envar_custom_delim = mod.ModuleEnvironmentVariable(test_paths, delim="|")
self.assertEqual(mod_envar_custom_delim.contents, test_paths)
self.assertEqual(repr(mod_envar_custom_delim), repr(test_paths))
self.assertEqual(str(mod_envar_custom_delim), "lib|lib64")

mod_envar.contents = []
self.assertEqual(mod_envar.contents, [])
self.assertRaises(TypeError, setattr, mod_envar, "contents", None)
Expand Down

0 comments on commit a514a42

Please sign in to comment.