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

Add better error UX when spaces are found in required_conan_version #12695

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
3 changes: 3 additions & 0 deletions conans/model/version_range.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import namedtuple

from conans.errors import ConanException
from conans.model.recipe_ref import Version


Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions conans/test/integration/conanfile/required_conan_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions conans/test/unittests/model/version/test_version_range.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")