aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/simple_dependency_satisfying.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/simple_dependency_satisfying.py')
-rw-r--r--src/hydrilla/proxy/simple_dependency_satisfying.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/hydrilla/proxy/simple_dependency_satisfying.py b/src/hydrilla/proxy/simple_dependency_satisfying.py
index 9716fe5..889ae98 100644
--- a/src/hydrilla/proxy/simple_dependency_satisfying.py
+++ b/src/hydrilla/proxy/simple_dependency_satisfying.py
@@ -57,7 +57,7 @@ ComputedPayloadsDict = dict[
empty_identifiers_set: set[str] = set()
@dc.dataclass(frozen=True)
-class ItemsCollection:
+class _ItemsCollection:
resources: t.Mapping[str, item_infos.ResourceInfo]
mappings: t.Mapping[str, item_infos.MappingInfo]
@@ -187,3 +187,30 @@ class ItemsCollection:
computed_result.pop(self.mappings[identifier], None)
return computed_result
+
+AnyInfoVar = t.TypeVar(
+ 'AnyInfoVar',
+ item_infos.ResourceInfo,
+ item_infos.MappingInfo
+)
+
+def _choose_newest(infos: t.Iterable[AnyInfoVar]) -> dict[str, AnyInfoVar]:
+ best_versions: dict[str, AnyInfoVar] = {}
+
+ for info in infos:
+ other = best_versions.setdefault(info.identifier, info)
+
+ if (other.version, other.repo, info.repo_iteration) < \
+ (info.version, info.repo, other.repo_iteration):
+ best_versions[info.identifier] = info
+
+ return best_versions
+
+def compute_payloads(
+ resources: t.Iterable[item_infos.ResourceInfo],
+ mappings: t.Iterable[item_infos.MappingInfo]
+) -> ComputedPayloadsDict:
+ best_resources = _choose_newest(resources)
+ best_mappings = _choose_newest(mappings)
+
+ return _ItemsCollection(best_resources, best_mappings).compute_payloads()