Skip to content

Commit

Permalink
Fixes alisw#887 by raising an informative exception when version is n…
Browse files Browse the repository at this point in the history
…ot a string (e.g., float).
  • Loading branch information
maxim.borisyak committed Nov 21, 2024
1 parent 771e866 commit 8c6ce17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 8c6ce17

Please sign in to comment.