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

Fix propagation of include_prerelease when calculating VersionRange intersection #16986

Merged
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
6 changes: 5 additions & 1 deletion conans/model/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def _calculate_limits(operator, lhs, rhs):
if limits:
return sorted(limits, reverse=operator == ">")[0]

prerelease = True
for lhs_conditions in self.condition_sets:
for rhs_conditions in other.condition_sets:
internal_conditions = []
Expand All @@ -207,10 +208,13 @@ def _calculate_limits(operator, lhs, rhs):
internal_conditions.append(upper_limit)
if internal_conditions and (not lower_limit or not upper_limit or lower_limit <= upper_limit):
conditions.append(internal_conditions)
# conservative approach: if any of the conditions forbid prereleases, forbid them in the result
if not lhs_conditions.prerelease or not rhs_conditions.prerelease:
prerelease = False

if not conditions:
return None
expression = ' || '.join(' '.join(str(c) for c in cs) for cs in conditions)
expression = ' || '.join(' '.join(str(c) for c in cs) for cs in conditions) + (', include_prerelease' if prerelease else '')
result = VersionRange(expression)
# TODO: Direct definition of conditions not reparsing
# result.condition_sets = self.condition_sets + other.condition_sets
Expand Down
32 changes: 32 additions & 0 deletions test/unittests/model/version/test_version_range_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,35 @@ def test_range_intersection_incompatible(range1, range2):
assert inter is None
inter = r2.intersection(r1) # Test reverse order, result should be the same
assert inter is None


prerelease_values = [
[">=1.0-pre.1 <1.0-pre.99, include_prerelease",
">=1.0-pre.1 <1.0-pre.99, include_prerelease",
">=1.0-pre.1 <1.0-pre.99, include_prerelease"],
[">=1.0-pre.1 <1.0-pre.99, include_prerelease",
">=1.0-pre.12 <1.0-pre.98, include_prerelease",
">=1.0-pre.12 <1.0-pre.98, include_prerelease"],
[">=1.0-pre.12 <1.0-pre.99, include_prerelease",
">=1.0-pre.1 <1.0-pre.98, include_prerelease",
">=1.0-pre.12 <1.0-pre.98, include_prerelease"],
[">=1.0-pre.1 <1.0-pre.99",
">=1.0-pre.1 <1.0-pre.99, include_prerelease",
">=1.0-pre.1 <1.0-pre.99"],
[">=1.0-pre.1 <1.0-pre.99, include_prerelease",
">=1.0-pre.12 <1.0-pre.98",
">=1.0-pre.12 <1.0-pre.98"],
[">=1.0-pre.12 <1.0-pre.99",
">=1.0-pre.1 <1.0-pre.98",
">=1.0-pre.12 <1.0-pre.98"]
]


@pytest.mark.parametrize("range1, range2, result", prerelease_values)
def test_range_intersection_prerelease(range1, range2, result):
r1 = VersionRange(range1)
r2 = VersionRange(range2)
inter = r1.intersection(r2)
assert str(inter.version()) == f'[{result}]'
inter = r2.intersection(r1) # Test reverse order, result should be the same
assert str(inter.version()) == f'[{result}]'