Skip to content

Commit

Permalink
Adapt VERSION_REGEXP for EnvironmentModules
Browse files Browse the repository at this point in the history
When using an Environment Modules version built from git repository,
version number contains git branch name, number of commit since last
released version and commit hash.

This commit adapts VERSION_REGEXP for EnvironmentModules class to allow
using development or locally adapted versions of Environment Modules
with EasyBuild.

Fixes #4126
  • Loading branch information
xdelaruelle committed Dec 27, 2023
1 parent d977648 commit 1fad79e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ class EnvironmentModules(EnvironmentModulesTcl):
COMMAND_ENVIRONMENT = 'MODULES_CMD'
REQ_VERSION = '4.0.0'
MAX_VERSION = None
VERSION_REGEXP = r'^Modules\s+Release\s+(?P<version>\d\S*)\s'
VERSION_REGEXP = r'^Modules\s+Release\s+(?P<version>\d[^+\s]*)(\+\S*)?\s'

def __init__(self, *args, **kwargs):
"""Constructor, set Environment Modules-specific class variable values."""
Expand Down
15 changes: 15 additions & 0 deletions test/framework/modulestool.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ def test_environment_modules_specific(self):
mt = EnvironmentModules(testing=True)
self.assertIsInstance(mt.loaded_modules(), list) # dummy usage

# initialize Environment Modules tool with non-official version number
# pass (fake) full path to 'modulecmd.tcl' via $MODULES_CMD
fake_path = os.path.join(self.test_installpath, 'libexec', 'modulecmd.tcl')
fake_modulecmd_txt = '\n'.join([
'puts stderr {Modules Release 5.3.1+unload-188-g14b6b59b (2023-10-21)}',
"puts {os.environ['FOO'] = 'foo'}",
])
write_file(fake_path, fake_modulecmd_txt)
os.chmod(fake_path, stat.S_IRUSR | stat.S_IXUSR)
os.environ['_module_raw'] = "() { eval `%s' bash $*`;\n}" % fake_path
os.environ['MODULES_CMD'] = fake_path
EnvironmentModules.COMMAND = fake_path
mt = EnvironmentModules(testing=True)
self.assertTrue(os.path.samefile(mt.cmd, fake_path), "%s - %s" % (mt.cmd, fake_path))

def tearDown(self):
"""Testcase cleanup."""
super(ModulesToolTest, self).tearDown()
Expand Down

0 comments on commit 1fad79e

Please sign in to comment.