diff --git a/alibuild_helpers/utilities.py b/alibuild_helpers/utilities.py index 4df262dc..a4b8912e 100644 --- a/alibuild_helpers/utilities.py +++ b/alibuild_helpers/utilities.py @@ -145,7 +145,16 @@ 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")) - return spec["version"] % { + 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 version % { "commit_hash": commit_hash, "short_hash": commit_hash[0:10], "tag": tag, diff --git a/tests/test_utilities.py b/tests/test_utilities.py index f0cc2051..2a52aee6 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -400,6 +400,16 @@ def fake_abspath(n): self.assertEqual(resolveFilename({}, "zlib", "alidost"), (None, None)) self.assertEqual(resolveFilename({}, "python", "alidist"), ("/bar/python.sh", "/bar")) + 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."""