Skip to content

Commit

Permalink
better version ranges errors (#16289)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored May 17, 2024
1 parent 915c834 commit 381218d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion conans/client/graph/range_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def __init__(self, conan_app, global_conf, editable_packages):
self._resolve_prereleases = global_conf.get('core.version_ranges:resolve_prereleases')

def resolve(self, require, base_conanref, remotes, update):
version_range = require.version_range
try:
version_range = require.version_range
except Exception as e:
base = base_conanref or "conanfile"
raise ConanException(f"\n Recipe '{base}' requires '{require.ref}' "
f"version-range definition error:\n {e}")
if version_range is None:
return
assert isinstance(version_range, VersionRange)
Expand Down
21 changes: 20 additions & 1 deletion conans/test/unittests/model/version/test_version_range.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import textwrap

import pytest

from conans.errors import ConanException
from conans.model.version import Version
from conans.model.version_range import VersionRange
from conans.test.utils.tools import TestClient

values = [
['=1.0.0', [[['=', '1.0.0']]], ["1.0.0"], ["0.1"]],
Expand Down Expand Up @@ -42,7 +45,7 @@
['>=1.0.0+2', [[['>=', '1.0.0+2']]], ["1.0.0+2", "1.0.0+3"], ["1.0.0+1"]],
['>=1.0.0', [[['>=', '1.0.0-']]], ["1.0.0+2", "1.0.0+3"], []],
# Build metadata and pre-releases
['>=1.0.0-pre.1+2', [[['>=', '1.0.0-pre.1+2']]], ["1.0.0+1", "1.0.0+2"], ["1.0.0-pre.1+3"]], # excluded 1+3 because is a pre-release!
['>=1.0.0-pre.1+2', [[['>=', '1.0.0-pre.1+2']]], ["1.0.0+1", "1.0.0+2"], ["1.0.0-pre.1+3"]], # excluded 1+3 because is a pre-release!
['>=1.0.0-pre.1+2, include_prerelease=True', [[['>=', '1.0.0-pre.1+2']]], ["1.0.0+1", "1.0.0+2", "1.0.0-pre.1+3"], ["1.0.0-pre.1+1"]],
['<1.0.1-pre.1+2', [[['<', '1.0.1-pre.1+2']]], ["1.0.0+1", "1.0.0+2"], ["1.0.0-pre.1+2"]],
['<1.0.1-pre.1+2, include_prerelease=True', [[['<', '1.0.1-pre.1+2']]], ["1.0.0+1", "1.0.0+2", "1.0.1-pre.1+1"], ["1.0.1-pre.1+2"]],
Expand Down Expand Up @@ -129,3 +132,19 @@ def test_wrong_range_option_syntax(version_range):
but for now this test ensures we don't change it without realizing"""
vr = VersionRange(version_range)
assert all(cs.prerelease for cs in vr.condition_sets)


def test_version_range_error_ux():
# https://github.com/conan-io/conan/issues/16288
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
requires = "mydep/[>1.0 < 3]"
""")
c.save({"conanfile.py": conanfile})
c.run("install .", assert_error=True)
assert "Recipe 'conanfile' requires 'mydep/[>1.0 < 3]' version-range definition error" in c.out
c.run("export . --name=mypkg --version=0.1")
c.run("install --requires=mypkg/0.1", assert_error=True)
assert "Recipe 'mypkg/0.1' requires 'mydep/[>1.0 < 3]' version-range definition error" in c.out

0 comments on commit 381218d

Please sign in to comment.