From 9e78074fcfba0e18ba139e9fd4c8718b18fc4bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Sun, 20 Aug 2023 13:24:04 +0200 Subject: [PATCH] Warn of unknown version range options (#14493) * 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 --- conans/model/version_range.py | 7 +++++++ .../integration/graph/core/test_version_ranges.py | 12 ++++++++++++ .../integration/py_requires/python_requires_test.py | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/conans/model/version_range.py b/conans/model/version_range.py index 62e98947adc..89be16976b0 100644 --- a/conans/model/version_range.py +++ b/conans/model/version_range.py @@ -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("||"): diff --git a/conans/test/integration/graph/core/test_version_ranges.py b/conans/test/integration/graph/core/test_version_ranges.py index f537e21b7fc..7e1114c9e8d 100644 --- a/conans/test/integration/graph/core/test_version_ranges.py +++ b/conans/test/integration/graph/core/test_version_ranges.py @@ -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 diff --git a/conans/test/integration/py_requires/python_requires_test.py b/conans/test/integration/py_requires/python_requires_test.py index b86d3a4f279..4b2d080dbe7 100644 --- a/conans/test/integration/py_requires/python_requires_test.py +++ b/conans/test/integration/py_requires/python_requires_test.py @@ -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" """)