mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 22:38:54 -06:00
refactor: one owner order for cited repositories
This commit is contained in:
1 parent
b0f7d6c661
commit
409cc843f9
5 files changed
+116
-19
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""Which declared repository a cited part belongs to, by its role word."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def field_role(field: str) -> str:
|
||||
"""source or upstream: the profile field a repository comes from."""
|
||||
return "upstream" if field == "upstream" else "source"
|
||||
|
||||
|
||||
def answers(field: str, mode: str, role: str) -> bool:
|
||||
"""Whether a part written under *role* means this repository: the field
|
||||
it comes from, or the build mode a keyed source declares it under."""
|
||||
return bool(role) and role in (field_role(field), mode)
|
||||
|
||||
|
||||
def owner_order(
|
||||
repositories: Iterable[T], role: str, declared: Callable[[T], tuple[str, str]]
|
||||
) -> list[T]:
|
||||
"""Repositories in the order a cited part claims them.
|
||||
|
||||
Those its role names come first, then the rest, each group in
|
||||
declaration order: between two trees that carry the cited path, the
|
||||
one declared first owns a part that names none. `declared` gives the
|
||||
(field, build mode) a repository was declared under.
|
||||
"""
|
||||
items = list(repositories)
|
||||
if not role:
|
||||
return items
|
||||
return sorted(items, key=lambda item: not answers(*declared(item), role))
|
||||
Reference in new issue
Block a user