Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #887 by raising an informative exception when version is not a string #889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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,
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
Loading