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

Warn on empty version ranges #17405

Merged
merged 3 commits into from
Dec 5, 2024
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
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
Loading