Skip to content

Commit

Permalink
Warn on empty version ranges (#17405)
Browse files Browse the repository at this point in the history
* Warn on empty version ranges

* Better message

* Move message to a better place
  • Loading branch information
AbrilRBS authored Dec 5, 2024
1 parent fd1a84a commit 4b4348f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conan/cli/printers/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def _format_resolved(title, reqs_to_print):
"it might be removed in 3.0.")
output.warning("Consider using version-ranges instead.")
_format_resolved("Resolved version ranges", graph.resolved_ranges)
for req in graph.resolved_ranges:
if str(req.version) == "[]":
output.warning("Empty version range usage is discouraged. Use [*] instead", warn_tag="deprecated")
break

overrides = graph.overrides()
if overrides:
Expand Down
10 changes: 10 additions & 0 deletions test/integration/graph/core/test_version_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,13 @@ def test_bad_options_syntax(version_range, should_warn):
assert "its presence unconditionally enables prereleases" in tc.out
else:
assert "its presence unconditionally enables prereleases" not in tc.out


def test_empty_version_ranger():
tc = TestClient(light=True)
tc.save({"lib/conanfile.py": GenConanfile("lib", "1.0"),
"app/conanfile.py": GenConanfile("app", "1.0").with_requires("lib/[]")})
tc.run("export lib")
tc.run("graph info app")
assert "lib/[]: lib/1.0" in tc.out
assert "Empty version range usage is discouraged" in tc.out
4 changes: 4 additions & 0 deletions test/unittests/model/version/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def test_range(version_range, conditions, versions_in, versions_out):
['>1 <=2.0', False, ["1.1", "1.9", "2.0"], ["0.9", "1.0-pre.1", "1.0", "1.1-pre.1", "2.0-pre"]],
# This should be old and new behaviors remain the same
['>1 <=2.0', True, ["1.1-pre.1", "1.1", "1.9", "2.0", "2.0-pre"], ["0.9", "1.0", "1.0-pre.1"]],
# Codified quirks
['', False, ["1.0", "2.0"], ["1.0-pre.1", "2.0-pre.1"]],
['', True, ["1.0", "2.0", "1.0-pre.1", "2.0-pre.1"], []],
])
def test_range_prereleases_conf(version_range, resolve_prereleases, versions_in, versions_out):
r = VersionRange(version_range)
Expand Down

0 comments on commit 4b4348f

Please sign in to comment.