Skip to content

Commit

Permalink
check type of versionsuffix value in det_full_ec_version, and raise u…
Browse files Browse the repository at this point in the history
…seful error message if it's not a string (fixes #4181)
  • Loading branch information
boegel committed Jan 18, 2023
1 parent e9b7cea commit 0e5ba5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion easybuild/tools/module_naming_scheme/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import string

from easybuild.base import fancylogger
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.module_naming_scheme.mns import ModuleNamingScheme
from easybuild.tools.py2vs3 import string_type
from easybuild.tools.toolchain.toolchain import SYSTEM_TOOLCHAIN_NAME, is_system_toolchain
Expand All @@ -62,7 +63,17 @@ def det_full_ec_version(ec):
ecver = "%s-%s-%s" % (ec['version'], toolchain['name'], toolchain['version'])

# prepend/append version prefix/suffix
ecver = ''.join([x for x in [ec.get('versionprefix', ''), ecver, ec.get('versionsuffix', '')] if x])
versionprefix = ec.get('versionprefix', '')
if not isinstance(versionprefix, string_type):
raise EasyBuildError("versionprefix value should be a string, found '%s': %s (full spec: %s)",
type(versionprefix).__name__, versionprefix, ec)

versionsuffix = ec.get('versionsuffix', '')
if not isinstance(versionsuffix, string_type):
raise EasyBuildError("versionsuffix value should be a string, found '%s': %s (full spec: %s)",
type(versionsuffix).__name__, versionsuffix, ec)

ecver = ''.join([x for x in [versionprefix, ecver, versionsuffix] if x])

return ecver

Expand Down
9 changes: 9 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@ def test_installversion(self):
# only version key is strictly needed
self.assertEqual(det_full_ec_version({'version': '1.2.3'}), '1.2.3')

# check how faulty dep spec is handled
faulty_dep_spec = {
'name': 'test',
'version': '1.2.3',
'versionsuffix': {'name': 'system', 'version': 'system'},
}
error_pattern = "versionsuffix value should be a string, found 'dict'"
self.assertErrorRegex(EasyBuildError, error_pattern, det_full_ec_version, faulty_dep_spec)

def test_obtain_easyconfig(self):
"""test obtaining an easyconfig file given certain specifications"""
init_config(build_options={'silent': True})
Expand Down
11 changes: 11 additions & 0 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,17 @@ def test_mns():
ec2mod_map = default_ec2mod_map
test_mns()

# check how an incorrect dependency specification is handled;
# accidentally using SYSTEM as 3rd tuple element should trigger a useful error,
# not a nasty crash; cfr. https://github.com/easybuilders/easybuild-framework/issues/4181
faulty_dep_spec = {
'name': 'test',
'version': '1.2.3',
'versionsuffix': {'name': 'system', 'version': 'system'},
}
error_pattern = "versionsuffix value should be a string, found 'dict'"
self.assertErrorRegex(EasyBuildError, error_pattern, ActiveMNS().det_full_module_name, faulty_dep_spec)

def test_mod_name_validation(self):
"""Test module naming validation."""
# module name must be a string
Expand Down

0 comments on commit 0e5ba5c

Please sign in to comment.