Skip to content

Commit 7342501

Browse files
StableKeywordsCheck: detect packages using stable keywords
Add an optional check to scan for packages using stable keywords. This is useful for overlays like ::guru, which require that all packages be keyworded unstable. Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
1 parent 88c2e6a commit 7342501

14 files changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from collections import defaultdict
2+
3+
from pkgcore.ebuild.misc import sort_keywords
4+
from pkgcore.restrictions import packages, values
5+
from snakeoil.strings import pluralism
6+
7+
from .. import addons, results, sources
8+
from . import OptionalCheck
9+
10+
11+
class StableKeywords(results.PackageResult, results.Error):
12+
"""Package uses stable keywords."""
13+
14+
def __init__(self, versions, arches, **kwargs):
15+
super().__init__(**kwargs)
16+
self.versions = tuple(versions)
17+
self.arches = tuple(arches)
18+
19+
@property
20+
def desc(self):
21+
s = pluralism(self.arches, plural="s")
22+
arches = ", ".join(self.arches)
23+
versions = ", ".join(self.versions)
24+
return f"stable keyword{s} [ {arches} ] used on version{s}: [ {versions} ]"
25+
26+
27+
class StableKeywordsCheck(OptionalCheck):
28+
"""Scan for packages using stable keywords."""
29+
30+
_source = sources.PackageRepoSource
31+
required_addons = (addons.StableArchesAddon,)
32+
known_results = frozenset([StableKeywords])
33+
34+
def __init__(self, *args, stable_arches_addon=None):
35+
super().__init__(*args)
36+
self.arches = {x.strip().lstrip("~") for x in self.options.stable_arches}
37+
38+
self.arch_restricts = {
39+
arch: packages.PackageRestriction("keywords", values.ContainmentMatch2((arch,)))
40+
for arch in self.arches
41+
}
42+
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])
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"__class__": "StableKeywords", "category": "StableKeywordsCheck", "package": "StableKeywords", "versions": ["0"], "arches": ["amd64"]}
2+
{"__class__": "StableKeywords", "category": "StableKeywordsCheck", "package": "StableKeywords", "versions": ["1"], "arches": ["x86"]}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild fixed/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
2+
index fc606dee..52f19ba0 100644
3+
--- stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
4+
+++ fixed/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
5+
@@ -9,4 +9,4 @@ SRC_URI="https://example.com/"
6+
7+
LICENSE="MIT"
8+
SLOT="0"
9+
-KEYWORDS="amd64"
10+
+KEYWORDS="~amd64"
11+
diff --git stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild fixed/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
12+
index e8774608..12e0329a 100644
13+
--- stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
14+
+++ fixed/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
15+
@@ -9,4 +9,4 @@ SRC_URI="https://example.com/"
16+
17+
LICENSE="MIT"
18+
SLOT="0"
19+
-KEYWORDS="~amd64 x86"
20+
+KEYWORDS="~amd64 ~x86"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2026 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
DESCRIPTION="StableKeywords"
7+
HOMEPAGE="https://example.com/"
8+
SRC_URI="https://example.com/"
9+
10+
LICENSE="MIT"
11+
SLOT="0"
12+
KEYWORDS="amd64"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2026 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
DESCRIPTION="StableKeywords"
7+
HOMEPAGE="https://example.com/"
8+
SRC_URI="https://example.com/"
9+
10+
LICENSE="MIT"
11+
SLOT="0"
12+
KEYWORDS="~amd64 x86"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2026 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
DESCRIPTION="StableKeywords"
7+
HOMEPAGE="https://example.com/"
8+
SRC_URI="https://example.com/"
9+
10+
LICENSE="MIT"
11+
SLOT="0"
12+
KEYWORDS="~amd64"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2026 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
DESCRIPTION="StableKeywords"
7+
HOMEPAGE="https://example.com/"
8+
SRC_URI="https://example.com/"
9+
10+
LICENSE="MIT"
11+
SLOT="0"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
masters =
2+
cache-formats =
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
amd64
2+
x86
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
StableKeywordsCheck

0 commit comments

Comments
 (0)