diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-10 21:07:54 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-08-10 21:07:54 +0200 |
commit | 72fcc76cc75ccb7e180886170db01dae637e250e (patch) | |
tree | 7224c4ac0d10d9b668749285d57f938f9c11c0ad /src/hydrilla/proxy/simple_dependency_satisfying.py | |
parent | 879c41927171efc8d77d1de2739b18e2eb57580f (diff) | |
download | haketilo-hydrilla-72fcc76cc75ccb7e180886170db01dae637e250e.tar.gz haketilo-hydrilla-72fcc76cc75ccb7e180886170db01dae637e250e.zip |
small clean up for item definitions handling before dependency resolution happens
Diffstat (limited to 'src/hydrilla/proxy/simple_dependency_satisfying.py')
-rw-r--r-- | src/hydrilla/proxy/simple_dependency_satisfying.py | 29 |
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() |