diff --git a/alibuild_helpers/utilities.py b/alibuild_helpers/utilities.py index a78c175e..f45c7693 100644 --- a/alibuild_helpers/utilities.py +++ b/alibuild_helpers/utilities.py @@ -123,6 +123,15 @@ def resolve_version(spec, defaults, branch_basename, branch_stream): defaults_upper = defaults != "release" and "_" + defaults.upper().replace("-", "_") or "" commit_hash = spec.get("commit_hash", "hash_unknown") tag = str(spec.get("tag", "tag_unknown")) + version = spec["version"] + if not isinstance(version, str): + raise ValueError( + "Version for the package {package} must be a string, got {version}. " + "Please, make sure the version is quoted in the config file, e.g., \"1.0\"".format( + package=spec.get("package", "package_unknown"), + version=version + ) + ) return spec["version"] % { "commit_hash": commit_hash, "short_hash": commit_hash[0:10], diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 3fc2beef..f67c947a 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -227,6 +227,16 @@ def test_resolver(self): spec["version"] = "NO%(defaults_upper)s" self.assertTrue(resolve_version(spec, "release", "stream/v1", "v1"), "NO") + spec_float_version = {"package": "test-pkg", + "version": 1.0, + "tag": "foo/bar", + "commit_hash": "000000000000000000000000000" + } + self.assertRaises( + ValueError, + lambda: resolve_version(spec_float_version, "release", "stream/v1", "v1") + ) + class TestTopologicalSort(unittest.TestCase): """Check that various properties of topological sorting hold."""