Skip to content
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
4 changes: 2 additions & 2 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,12 +1681,12 @@ def make_module_req(self):

if self.make_module_req_guess.__qualname__ != "EasyBlock.make_module_req_guess":
# Deprecated make_module_req_guess method used in child Easyblock
# Update environment with custom make_module_req_guess
# adjust environment with custom make_module_req_guess
self.log.deprecated(
"make_module_req_guess() is deprecated, use EasyBlock.module_load_environment instead.",
"6.0",
)
self.module_load_environment.update(self.make_module_req_guess())
self.module_load_environment.replace(self.make_module_req_guess())

# Expand and inject path-like environment variables into module file
env_var_requirements = {
Expand Down
6 changes: 6 additions & 0 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ def update(self, new_env):
except AttributeError as err:
raise EasyBuildError("Cannot update ModuleLoadEnvironment from a non-dict variable") from err

def replace(self, new_env):
"""Replace contents of environment with given dictionary"""
for var in self.vars:
self.remove(var)
self.update(new_env)

def remove(self, var_name):
"""
Remove ModuleEnvironmentVariable attribute from instance
Expand Down
13 changes: 13 additions & 0 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,19 @@ def test_module_load_environment(self):
self.assertFalse(hasattr(mod_load_env, 'TEST_VARTYPE'))
mod_load_env.remove('NONEXISTENT')

# test replacing of env vars
env_vars = sorted(mod_load_env.as_dict.keys())
expected = ['ACLOCAL_PATH', 'CLASSPATH', 'CMAKE_LIBRARY_PATH', 'CMAKE_PREFIX_PATH', 'GI_TYPELIB_PATH',
'LD_LIBRARY_PATH', 'LIBRARY_PATH', 'MANPATH', 'PATH', 'PKG_CONFIG_PATH', 'TEST_NEW_VAR',
'TEST_STR', 'TEST_VAR', 'XDG_DATA_DIRS']
self.assertEqual(env_vars, expected)

mod_load_env.replace({'FOO': 'foo', 'BAR': 'bar'})
env_vars = sorted(mod_load_env.as_dict.keys())
self.assertEqual(env_vars, ['BAR', 'FOO'])
self.assertEqual(mod_load_env.BAR.contents, ['bar'])
self.assertEqual(mod_load_env.FOO.contents, ['foo'])

# test aliases
aliases = {
'ALIAS1': ['ALIAS_VAR11', 'ALIAS_VAR12'],
Expand Down
Loading