summaryrefslogtreecommitdiff
path: root/src/hydrilla
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-10-07 13:27:42 +0200
committerWojtek Kosior <koszko@koszko.org>2022-10-08 19:08:39 +0200
commit30bc5459ff765af98d8b1439c034bcf1b6488b04 (patch)
treef5003385114863d192cd2022db3ce6f9418ed43f /src/hydrilla
parent9ab39cd31422636b4678bcea2363f178a7e298d7 (diff)
downloadhaketilo-hydrilla-30bc5459ff765af98d8b1439c034bcf1b6488b04.tar.gz
haketilo-hydrilla-30bc5459ff765af98d8b1439c034bcf1b6488b04.zip
[builder][server][proxy] represent Haketilo version constraints in data structures that represent resources and mappings
Diffstat (limited to 'src/hydrilla')
-rw-r--r--src/hydrilla/item_infos.py32
-rw-r--r--src/hydrilla/versions.py3
2 files changed, 35 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
)
diff --git a/src/hydrilla/versions.py b/src/hydrilla/versions.py
index 065ccca..ddaa146 100644
--- a/src/hydrilla/versions.py
+++ b/src/hydrilla/versions.py
@@ -76,3 +76,6 @@ haketilo_version = normalize(tuple(takewhile(
lambda i: isinstance(i, int),
_version.version_tuple # type: ignore
)))
+
+int_ver_min = normalize([1])
+int_ver_max = normalize([65536])