Skip to content

Commit

Permalink
Merge branch 'fix/version_constraints_with_unequal' into 'main'
Browse files Browse the repository at this point in the history
fix: union of constraints of unequal clauses

Closes PACMAN-943

See merge request espressif/idf-component-manager!424
  • Loading branch information
kumekay committed Aug 9, 2024
2 parents b4fc561 + 61055f0 commit 233ac11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions idf_component_manager/version_solver/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_single_constraint(
elif _range.operator == _range.OP_GTE:
return Range(min=version, include_min=True, string=str(_range))
elif _range.operator == _range.OP_NEQ:
return Union(Range(min=version, string=str(_range)), Range(max=version, string=str(_range)))
return Union(Range(max=version, string=str(_range)), Range(min=version, string=str(_range)))
else:
return Range(version, version, True, True, str(_range))

Expand Down Expand Up @@ -168,7 +168,7 @@ def convert_dependency(self, dependency: Dependency) -> Constraint:
)
for r in dependency.constraint.ranges
]
constraint = Union.of(ranges)
constraint = Union.of(*ranges)
else:
raise ValueError('should be "Union" or "Range"')

Expand Down
22 changes: 22 additions & 0 deletions tests/version_solver/test_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

from idf_component_manager.version_solver.helper import parse_constraint


def test_parse_union_of_multiple_unequal():
assert parse_constraint('!=5.0.2,!=5.1.3,!=5.2.1')


def test_union_of_multiple_unequal():
a = parse_constraint('!=5.0.2')
b = parse_constraint('!=5.1.3')
c = parse_constraint('!=5.2.1')

d = a.intersect(b).intersect(c)

assert str(d) == '<5.0.2 || >5.0.2,<5.1.3 || >5.1.3,<5.2.1 || >5.2.1'
assert d.ranges[0] == parse_constraint('<5.0.2')
assert d.ranges[1] == parse_constraint('>5.0.2,<5.1.3')
assert d.ranges[2] == parse_constraint('>5.1.3,<5.2.1')
assert d.ranges[3] == parse_constraint('>5.2.1')

0 comments on commit 233ac11

Please sign in to comment.