aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/item_infos.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-10-11 10:26:55 +0200
committerWojtek Kosior <koszko@koszko.org>2022-10-11 13:12:11 +0200
commit0c8d70daae4c4dfc989edad465db94ffc665416d (patch)
tree86f1b23e863b2dae1efd00686d46890b4b72ccb2 /src/hydrilla/item_infos.py
parent9074d98f711b6ccc099df8bccb1ed28390bcf0da (diff)
downloadhaketilo-hydrilla-0c8d70daae4c4dfc989edad465db94ffc665416d.tar.gz
haketilo-hydrilla-0c8d70daae4c4dfc989edad465db94ffc665416d.zip
[builder][server] restore compatibility with python 3.7
Diffstat (limited to 'src/hydrilla/item_infos.py')
-rw-r--r--src/hydrilla/item_infos.py58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/hydrilla/item_infos.py b/src/hydrilla/item_infos.py
index 9638dab..d4cafe5 100644
--- a/src/hydrilla/item_infos.py
+++ b/src/hydrilla/item_infos.py
@@ -59,16 +59,14 @@ class ItemSpecifier:
"""...."""
identifier: str
+ItemSpecs = t.Tuple[ItemSpecifier, ...]
+
SpecifierObjs = t.Sequence[t.Mapping[str, t.Any]]
-def make_item_specifiers_seq(spec_objs: SpecifierObjs) \
- -> tuple[ItemSpecifier, ...]:
- """...."""
+def make_item_specifiers_seq(spec_objs: SpecifierObjs) -> ItemSpecs:
return tuple(ItemSpecifier(obj['identifier']) for obj in spec_objs)
-def make_required_mappings(spec_objs: t.Any, schema_compat: int) \
- -> tuple[ItemSpecifier, ...]:
- """...."""
+def make_required_mappings(spec_objs: t.Any, schema_compat: int) -> ItemSpecs:
if schema_compat < 2:
return ()
@@ -80,6 +78,8 @@ class FileSpecifier:
name: str
sha256: str
+FileSpecs = t.Tuple[FileSpecifier, ...]
+
def normalize_filename(name: str):
"""
This function eliminated double slashes in file name and ensures it does not
@@ -93,9 +93,7 @@ def normalize_filename(name: str):
return str(path)
-def make_file_specifiers_seq(spec_objs: SpecifierObjs) \
- -> tuple[FileSpecifier, ...]:
- """...."""
+def make_file_specifiers_seq(spec_objs: SpecifierObjs) -> FileSpecs:
return tuple(
FileSpecifier(normalize_filename(obj['file']), obj['sha256'])
for obj
@@ -164,17 +162,17 @@ class ItemIdentity:
@dc.dataclass(frozen=True) # type: ignore[misc]
class ItemInfoBase(ABC, ItemIdentity, Categorizable):
"""...."""
- source_name: str = dc.field(hash=False, compare=False)
- source_copyright: tuple[FileSpecifier, ...] = dc.field(hash=False, compare=False)
- uuid: t.Optional[str] = dc.field(hash=False, compare=False)
- long_name: str = dc.field(hash=False, compare=False)
- 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)
+ source_name: str = dc.field(hash=False, compare=False)
+ source_copyright: FileSpecs = dc.field(hash=False, compare=False)
+ uuid: t.Optional[str] = dc.field(hash=False, compare=False)
+ long_name: str = dc.field(hash=False, compare=False)
+ 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: ItemSpecs = dc.field(hash=False, compare=False)
+ generated_by: t.Optional[GeneratedBy] = dc.field(hash=False, compare=False)
@property
def version_string(self) -> str:
@@ -186,7 +184,7 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
return f'{self.identifier}-{self.version_string}'
@property
- def files(self) -> tuple[FileSpecifier, ...]:
+ def files(self) -> FileSpecs:
return self.source_copyright
@property
@@ -287,16 +285,16 @@ class CorrespondsToMappingDCMixin:
@dc.dataclass(frozen=True, unsafe_hash=True)
class ResourceInfo(ItemInfoBase, CorrespondsToResourceDCMixin):
"""...."""
- revision: int = dc.field(hash=False, compare=False)
- dependencies: tuple[ItemSpecifier, ...] = dc.field(hash=False, compare=False)
- scripts: tuple[FileSpecifier, ...] = dc.field(hash=False, compare=False)
+ revision: int = dc.field(hash=False, compare=False)
+ dependencies: ItemSpecs = dc.field(hash=False, compare=False)
+ scripts: FileSpecs = dc.field(hash=False, compare=False)
@property
def version_string(self) -> str:
return f'{super().version_string}-{self.revision}'
@property
- def files(self) -> tuple[FileSpecifier, ...]:
+ def files(self) -> FileSpecs:
return tuple((*self.source_copyright, *self.scripts))
@staticmethod
@@ -363,7 +361,7 @@ class ResourceInfo(ItemInfoBase, CorrespondsToResourceDCMixin):
def make_payloads(payloads_obj: t.Mapping[str, t.Any]) \
-> t.Mapping[ParsedPattern, ItemSpecifier]:
"""...."""
- mapping: list[tuple[ParsedPattern, ItemSpecifier]] = []
+ mapping: t.List[t.Tuple[ParsedPattern, ItemSpecifier]] = []
for pattern, spec_obj in payloads_obj.items():
ref = ItemSpecifier(spec_obj['identifier'])
@@ -447,7 +445,7 @@ def _load_item_info(
# We know from successful validation that instance is a dict.
return info_type.make(
- t.cast('dict[str, t.Any]', instance),
+ t.cast('t.Dict[str, t.Any]', instance),
schema_compat,
repo,
repo_iteration
@@ -611,7 +609,7 @@ class MultirepoItemInfo(
CategorizedItemInfo[
CategorizedInfoType,
VersionedItemInfo[CategorizedInfoType],
- tuple[str, int]
+ t.Tuple[str, int]
],
t.Generic[CategorizedInfoType]
):
@@ -649,7 +647,7 @@ class MultirepoItemInfo(
return self.get_all(reverse_repos=True)[-1]
- def options(self, reverse: bool = False) -> t.Sequence[tuple[str, int]]:
+ def options(self, reverse: bool = False) -> t.Sequence[t.Tuple[str, int]]:
return sorted(
self.items.keys(),
key = (lambda tuple: (tuple[0], 1 - tuple[1])),
@@ -665,7 +663,7 @@ class MultirepoItemInfo(
Generate item info for all its versions and options, from oldest to
newest version and from.
"""
- all_versions: set[versions.VerTuple] = set()
+ all_versions: t.Set[versions.VerTuple] = set()
for versioned in self.items.values():
all_versions.update(versioned.versions())