Skip to content

Commit

Permalink
Force platform deduplication on group instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Nov 3, 2024
1 parent a0e11d3 commit 3eb9526
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
> [!IMPORTANT]
> This version is not released yet and is under active development.
- Deduplicate platforms on `Group` instantiation.

## [1.4.0 (2024-10-21)](https://github.com/kdeldycke/extra-platforms/compare/v1.3.1...v1.4.0)

- Allow set comparison between groups and single platform.
Expand Down
9 changes: 5 additions & 4 deletions extra_platforms/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ class Group:
"""

def __post_init__(self):
"""Keep the platforms sorted by IDs."""
"""Deduplicate platforms and sort them by IDs."""
object.__setattr__(
self,
"platforms",
tuple(sorted(self.platforms, key=lambda p: p.id)),
tuple(sorted(set(self.platforms), key=lambda p: p.id)),
)
object.__setattr__(
self,
"platform_ids",
frozenset({p.id for p in self.platforms}),
)
# Double-check there is no duplicate platforms.
assert len(self.platforms) == len(self.platform_ids)
assert len(self.platforms) == len(
self.platform_ids
), "The group contain platforms with duplicate IDs"

def __iter__(self) -> Iterator[Platform]:
"""Iterate over the platforms of the group."""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
from extra_platforms import groups as groups_module


def test_platform_deduplication():
my_group = Group("my_group", "My Group", "✅", (AIX, AIX))
assert len(my_group) == 1


def test_group_definitions():
for group in ALL_GROUPS:
# ID.
Expand Down

0 comments on commit 3eb9526

Please sign in to comment.