Skip to content

Commit

Permalink
Icons are not allowed to be unset
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Nov 12, 2024
1 parent 7ab536a commit 6f4258b
Show file tree
Hide file tree
Showing 4 changed files with 17 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.
- Do not allow icons on platforms and groups to be empty.

## [1.6.0 (2024-11-11)](https://github.com/kdeldycke/extra-platforms/compare/v1.5.0...v1.6.0)

- Add a new `copy()` method to `Group`.
Expand Down
5 changes: 3 additions & 2 deletions extra_platforms/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ class Group:
"""Set of platform IDs that belong to this group."""

def __post_init__(self):
"""Validate and normalize the group's fields:
"""Validate and normalize the group fields:
- Ensure the group ID and name are not empty.
- Ensure the group ID, name and icon are not empty.
- Deduplicate platforms and sort them by IDs
- Populate the set of platform IDs and check for duplicates
"""
assert self.id, "Group ID cannot be empty."
assert self.name, "Group name cannot be empty."
assert self.icon, "Group icon cannot be empty."

object.__setattr__(
self,
Expand Down
12 changes: 11 additions & 1 deletion extra_platforms/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,18 @@ class Platform:
"""`True` if current environment runs on this platform."""

def __post_init__(self):
"""Set the ``current`` attribute to identifying the current platform."""
"""Validate and normalize platform fields:
- Ensure the platform ID, name and icon are not empty.
- Set the ``current`` field.
- Populate the docstring.
"""
assert self.id, "Platform ID cannot be empty."
assert self.name, "Platform name cannot be empty."
assert self.icon, "Platform icon cannot be empty."

object.__setattr__(self, "current", detection.__dict__[f"is_{self.id}"]())

object.__setattr__(self, "__doc__", f"Identify {self.name}.")

def info(self) -> dict[str, str | bool | None | dict[str, str | None]]:
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f4258b

Please sign in to comment.