Skip to content

Commit 1c150bf

Browse files
fixup! StableKeywordsCheck: detect packages using stable keywords
Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
1 parent 41bd9a7 commit 1c150bf

1 file changed

Lines changed: 22 additions & 28 deletions

File tree

src/pkgcheck/checks/stable_keywords.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,45 @@
88
from . import OptionalCheck
99

1010

11-
class StableKeywords(results.PackageResult, results.Error):
12-
"""Package uses stable keywords."""
11+
class DisallowedStableKeywords(results.VersionResult, results.Error):
12+
"""Package uses stable keywords, which are disallowed in this repository."""
1313

14-
def __init__(self, versions, arches, **kwargs):
14+
def __init__(self, arches, **kwargs):
1515
super().__init__(**kwargs)
16-
self.versions = tuple(versions)
17-
self.arches = tuple(arches)
16+
self.arches = tuple(sort_keywords(arches))
1817

1918
@property
2019
def desc(self):
2120
s = pluralism(self.arches)
2221
arches = ", ".join(self.arches)
23-
versions = ", ".join(self.versions)
24-
return f"stable keyword{s} [ {arches} ] used on version{s}: [ {versions} ]"
22+
return f"disallowed stable keyword{s}: [ {arches} ]"
2523

2624

27-
class StableKeywordsCheck(OptionalCheck):
28-
"""Scan for packages using stable keywords."""
25+
class DisallowedStableKeywordsCheck(OptionalCheck):
26+
"""Scan for packages using stable keywords in repositories where they are not allowed."""
2927

30-
_source = sources.PackageRepoSource
3128
required_addons = (addons.StableArchesAddon,)
32-
known_results = frozenset([StableKeywords])
29+
known_results = frozenset({DisallowedStableKeywords})
30+
31+
# acct-group and acct-user eclasses define KEYWORDS
32+
# See https://bugs.gentoo.org/342185
33+
ignored_categories = frozenset({"acct-group", "acct-user"})
3334

3435
def __init__(self, *args, stable_arches_addon=None):
3536
super().__init__(*args)
36-
self.arches = {x.strip().lstrip("~") for x in self.options.stable_arches}
37+
self.arches = frozenset({x.strip().lstrip("~") for x in self.options.stable_arches})
3738

3839
self.arch_restricts = {
3940
arch: packages.PackageRestriction("keywords", values.ContainmentMatch2((arch,)))
4041
for arch in self.arches
4142
}
4243

43-
def feed(self, pkgset):
44-
pkgs_arches = defaultdict(set)
45-
for arch, r in self.arch_restricts.items():
46-
for pkg in pkgset:
47-
if r.match(pkg):
48-
pkgs_arches[pkg].add(arch)
49-
50-
# invert
51-
arches_pkgs = defaultdict(list)
52-
for pkg, arches in pkgs_arches.items():
53-
arches_pkgs[frozenset(arches)].append(pkg)
54-
55-
# collapse reports by sets of arches
56-
for arches, pkgs in arches_pkgs.items():
57-
versions = (pkg.fullver for pkg in sorted(pkgs))
58-
yield StableKeywords(versions, sort_keywords(arches), pkg=pkgs[0])
44+
def feed(self, pkg):
45+
if pkg.category in self.ignored_categories:
46+
return
47+
48+
arches = frozenset({arch for arch, r in self.arch_restricts.items() if r.match(pkg)})
49+
if not arches:
50+
return
51+
52+
yield DisallowedStableKeywords(arches, pkg=pkg)

0 commit comments

Comments
 (0)