Skip to content

Commit

Permalink
Warn of unknown version range options (#14493)
Browse files Browse the repository at this point in the history
* Warn of unknown range options

* Differenciate between unknown option and not even an option

* Raise on no option

* Let the test resolve

* Typo placement

* Fix version check in test
  • Loading branch information
AbrilRBS authored Aug 20, 2023
1 parent 6f6481d commit 9e78074
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions conans/model/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def __init__(self, expression):
if "include_prerelease" in t:
prereleases = True
break
else:
t = t.strip()
if len(t) > 0 and t[0].isalpha():
from conan.api.output import ConanOutput
ConanOutput().warning(f'Unrecognized version range option "{t}" in "{expression}"')
else:
raise ConanException(f'"{t}" in version range "{expression}" is not a valid option')
version_expr = tokens[0]
self.condition_sets = []
for alternative in version_expr.split("||"):
Expand Down
12 changes: 12 additions & 0 deletions conans/test/integration/graph/core/test_version_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,15 @@ def test_different_user_channel_resolved_correctly():
client2.run("install --requires=lib/[>=1.0]@conan/testing")
assert f"lib/1.0@conan/testing: Retrieving package {NO_SETTINGS_PACKAGE_ID} " \
f"from remote 'server2' " in client2.out


def test_unknown_options():
c = TestClient()
c.save({"conanfile.py": GenConanfile("lib", "2.0")})
c.run("create .")

c.run("graph info --requires=lib/[>1.2,<1.4]", assert_error=True)
assert '"<1.4" in version range ">1.2,<1.4" is not a valid option' in c.out

c.run("graph info --requires=lib/[>1.2,unknown_conf]")
assert 'WARN: Unrecognized version range option "unknown_conf" in ">1.2,unknown_conf"' in c.out
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_reuse_version_ranges(self):
reuse = textwrap.dedent("""
from conan import ConanFile
class PkgTest(ConanFile):
python_requires = "base/[>1.0,<1.2]@user/testing"
python_requires = "base/[>1.0 <1.2]@user/testing"
python_requires_extend = "base.MyConanfileBase"
""")

Expand Down

0 comments on commit 9e78074

Please sign in to comment.