summaryrefslogtreecommitdiff
path: root/src/hydrilla/item_infos.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/item_infos.py')
-rw-r--r--src/hydrilla/item_infos.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/hydrilla/item_infos.py b/src/hydrilla/item_infos.py
index c8c5deb..21b7136 100644
--- a/src/hydrilla/item_infos.py
+++ b/src/hydrilla/item_infos.py
@@ -135,6 +135,17 @@ def make_cors_bypass_permission(perms_obj: t.Any, schema_compat: int) -> bool:
return perms_obj.get('cors_bypass', False)
+def make_version_constraint(
+ ver: t.Any,
+ schema_compat: int,
+ default: t.Sequence[int]
+) -> versions.VerTuple:
+ if schema_compat < 2 or ver is None:
+ return versions.normalize(default)
+
+ return versions.normalize(ver)
+
+
class Categorizable(Protocol):
"""...."""
uuid: t.Optional[str]
@@ -147,6 +158,7 @@ class ItemIdentity:
version: versions.VerTuple
identifier: str
+
# mypy needs to be corrected:
# https://stackoverflow.com/questions/70999513/conflict-between-mix-ins-for-abstract-dataclasses/70999704#70999704
@dc.dataclass(frozen=True) # type: ignore[misc]
@@ -159,6 +171,8 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
description: str = dc.field(hash=False, compare=False)
allows_eval: bool = dc.field(hash=False, compare=False)
allows_cors_bypass: bool = dc.field(hash=False, compare=False)
+ min_haketilo_ver: versions.VerTuple = dc.field(hash=False, compare=False)
+ max_haketilo_ver: versions.VerTuple = dc.field(hash=False, compare=False)
required_mappings: tuple[ItemSpecifier, ...] = dc.field(hash=False, compare=False)
generated_by: t.Optional[GeneratedBy] = dc.field(hash=False, compare=False)
@@ -175,6 +189,11 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
def files(self) -> tuple[FileSpecifier, ...]:
return self.source_copyright
+ @property
+ def compatible(self) -> bool:
+ return (self.min_haketilo_ver <= versions.haketilo_version and
+ self.max_haketilo_ver >= versions.haketilo_version)
+
@staticmethod
def _get_base_init_kwargs(
item_obj: t.Mapping[str, t.Any],
@@ -194,6 +213,17 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
eval_perm = make_eval_permission(perms_obj, schema_compat)
cors_bypass_perm = make_cors_bypass_permission(perms_obj, schema_compat)
+ min_haketilo_ver = make_version_constraint(
+ ver = item_obj.get('min_haketilo_version'),
+ schema_compat = schema_compat,
+ default = versions.int_ver_min
+ )
+ max_haketilo_ver = make_version_constraint(
+ ver = item_obj.get('max_haketilo_version'),
+ schema_compat = schema_compat,
+ default = versions.int_ver_max
+ )
+
required_mappings = make_required_mappings(
item_obj.get('required_mappings', []),
schema_compat
@@ -213,6 +243,8 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
description = item_obj['description'],
allows_eval = eval_perm,
allows_cors_bypass = cors_bypass_perm,
+ min_haketilo_ver = min_haketilo_ver,
+ max_haketilo_ver = max_haketilo_ver,
required_mappings = required_mappings,
generated_by = generated_by
)