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

Improve error messages for invalid version ranges operators #16069

Merged
Merged
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
6 changes: 4 additions & 2 deletions conans/model/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def _parse_expression(expression):
if expression[1] == "=":
operator += "="
index = 2
elif expression[1] == "=":
raise ConanException(f"Invalid version range operator '{operator}=' in {expression}, you should probably use {operator} instead.")
version = expression[index:]
if version == "":
raise ConanException(f'Error parsing version range "{expression}"')
Expand All @@ -111,7 +113,7 @@ def first_non_zero(main):
else:
return [_Condition(operator, Version(version))]

def _valid(self, version, conf_resolve_prepreleases):
def valid(self, version, conf_resolve_prepreleases):
if version.pre:
# Follow the expression desires only if core.version_ranges:resolve_prereleases is None,
# else force to the conf's value
Expand Down Expand Up @@ -180,7 +182,7 @@ def contains(self, version: Version, resolve_prerelease: Optional[bool]):
"""
assert isinstance(version, Version), type(version)
for condition_set in self.condition_sets:
if condition_set._valid(version, resolve_prerelease):
if condition_set.valid(version, resolve_prerelease):
return True
return False

Expand Down
4 changes: 3 additions & 1 deletion conans/test/unittests/model/version/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from conans.model.version_range import VersionRange

values = [
['=1.0.0', [[['=', '1.0.0']]], ["1.0.0"], ["0.1"]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so [=1.0.0] is supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was a bit surprised too, seems more an unexpected result of the parsing, but I am concerned that removing now might break someone, so probably not worth it.

['>1.0.0', [[['>', '1.0.0']]], ["1.0.1"], ["0.1"]],
['<2.0', [[['<', '2.0-']]], ["1.0.1"], ["2.1"]],
['>1 <2.0', [[['>', '1'], ['<', '2.0-']]], ["1.5.1"], ["0.1", "2.1"]],
Expand Down Expand Up @@ -109,7 +110,8 @@ def test_range_prereleases_conf(version_range, resolve_prereleases, versions_in,

@pytest.mark.parametrize("version_range", [
">= 1.0", # https://github.com/conan-io/conan/issues/12692
">=0.0.1 < 1.0" # https://github.com/conan-io/conan/issues/14612
">=0.0.1 < 1.0", # https://github.com/conan-io/conan/issues/14612
"==1.0", "~=1.0", "^=1.0", "v=1.0" # https://github.com/conan-io/conan/issues/16066
])
def test_wrong_range_syntax(version_range):
with pytest.raises(ConanException):
Expand Down