diff --git a/conans/model/version_range.py b/conans/model/version_range.py index b0076d7b81f..1bdadbe77ad 100644 --- a/conans/model/version_range.py +++ b/conans/model/version_range.py @@ -1,5 +1,6 @@ from collections import namedtuple +from conans.errors import ConanException from conans.model.recipe_ref import Version @@ -35,6 +36,8 @@ def _parse_expression(expression): operator += "=" index = 2 version = expression[index:] + if version == "": + raise ConanException(f"Error parsing version range {expression}") if operator == "~": # tilde minor v = Version(version) index = 1 if len(v.main) > 1 else 0 diff --git a/conans/test/integration/conanfile/required_conan_version_test.py b/conans/test/integration/conanfile/required_conan_version_test.py index d4856e26ac7..afd7e2fc10f 100644 --- a/conans/test/integration/conanfile/required_conan_version_test.py +++ b/conans/test/integration/conanfile/required_conan_version_test.py @@ -77,3 +77,19 @@ class Lib(ConanFile): """) client.save({"conanfile.py": conanfile}) client.run("export . --name=pkg --version=1.0") + + def test_required_conan_version_invalid_syntax(self): + """ required_conan_version used to warn of mismatching versions if spaces were present, + but now we have a nicer error""" + # https://github.com/conan-io/conan/issues/12692 + client = TestClient() + conanfile = textwrap.dedent(""" + from conan import ConanFile + required_conan_version = ">= 1.0" + class Lib(ConanFile): + pass""") + client.save({"conanfile.py": conanfile}) + client.run("export . --name=pkg --version=1.0", assert_error=True) + self.assertNotIn(f"Current Conan version ({__version__}) does not satisfy the defined one " + "(>= 1.0)", client.out) + self.assertIn("Error parsing version range >=", client.out) diff --git a/conans/test/unittests/model/version/test_version_range.py b/conans/test/unittests/model/version/test_version_range.py index 419d0f8e4fd..fb41eeb0d5a 100644 --- a/conans/test/unittests/model/version/test_version_range.py +++ b/conans/test/unittests/model/version/test_version_range.py @@ -1,5 +1,6 @@ import pytest +from conans.errors import ConanException from conans.model.recipe_ref import Version from conans.model.version_range import VersionRange @@ -50,3 +51,8 @@ def test_range(version_range, conditions, versions_in, versions_out): for v in versions_out: assert Version(v) not in r + +def test_wrong_range_syntax(): + # https://github.com/conan-io/conan/issues/12692 + with pytest.raises(ConanException) as e: + VersionRange(">= 1.0")