Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/pkgcheck/checks/stable_keywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from collections import defaultdict

from pkgcore.ebuild.misc import sort_keywords
from pkgcore.restrictions import packages, values
from snakeoil.strings import pluralism

from .. import addons, results, sources
from . import OptionalCheck


class StableKeywords(results.PackageResult, results.Error):
"""Package uses stable keywords."""
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a good result name and description - what does it even mean? A developer that gets such error won't understand it's reason.


def __init__(self, versions, arches, **kwargs):
super().__init__(**kwargs)
self.versions = tuple(versions)
self.arches = tuple(arches)

@property
def desc(self):
s = pluralism(self.arches)
arches = ", ".join(self.arches)
versions = ", ".join(self.versions)
return f"stable keyword{s} [ {arches} ] used on version{s}: [ {versions} ]"


class StableKeywordsCheck(OptionalCheck):
"""Scan for packages using stable keywords."""

_source = sources.PackageRepoSource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use here Repo scope and not just Package scope like most other scans? It would be much simpler to handle, group, ...

required_addons = (addons.StableArchesAddon,)
known_results = frozenset([StableKeywords])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
known_results = frozenset([StableKeywords])
known_results = frozenset({StableKeywords})


def __init__(self, *args, stable_arches_addon=None):
super().__init__(*args)
self.arches = {x.strip().lstrip("~") for x in self.options.stable_arches}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.arches = {x.strip().lstrip("~") for x in self.options.stable_arches}
self.arches = frozenset({x.strip().lstrip("~") for x in self.options.stable_arches})

I like immutability


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

def feed(self, pkgset):
pkgs_arches = defaultdict(set)
for arch, r in self.arch_restricts.items():
for pkg in pkgset:
if r.match(pkg):
pkgs_arches[pkg].add(arch)

# invert
arches_pkgs = defaultdict(list)
for pkg, arches in pkgs_arches.items():
arches_pkgs[frozenset(arches)].append(pkg)

# collapse reports by sets of arches
for arches, pkgs in arches_pkgs.items():
versions = (pkg.fullver for pkg in sorted(pkgs))
yield StableKeywords(versions, sort_keywords(arches), pkg=pkgs[0])
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"__class__": "StableKeywords", "category": "StableKeywordsCheck", "package": "StableKeywords", "versions": ["0"], "arches": ["amd64"]}
{"__class__": "StableKeywords", "category": "StableKeywordsCheck", "package": "StableKeywords", "versions": ["1"], "arches": ["x86"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild fixed/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
index fc606dee..52f19ba0 100644
--- stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
+++ fixed/StableKeywordsCheck/StableKeywords/StableKeywords-0.ebuild
@@ -9,4 +9,4 @@ SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
-KEYWORDS="amd64"
+KEYWORDS="~amd64"
diff --git stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild fixed/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
index e8774608..12e0329a 100644
--- stable_keywords/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
+++ fixed/StableKeywordsCheck/StableKeywords/StableKeywords-1.ebuild
@@ -9,4 +9,4 @@ SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
-KEYWORDS="~amd64 x86"
+KEYWORDS="~amd64 ~x86"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="StableKeywords"
HOMEPAGE="https://example.com/"
SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
KEYWORDS="amd64"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="StableKeywords"
HOMEPAGE="https://example.com/"
SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 x86"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="StableKeywords"
HOMEPAGE="https://example.com/"
SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="StableKeywords"
HOMEPAGE="https://example.com/"
SRC_URI="https://example.com/"

LICENSE="MIT"
SLOT="0"
2 changes: 2 additions & 0 deletions testdata/repos/stable_keywords/metadata/layout.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
masters =
cache-formats =
2 changes: 2 additions & 0 deletions testdata/repos/stable_keywords/profiles/arch.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
amd64
x86
1 change: 1 addition & 0 deletions testdata/repos/stable_keywords/profiles/categories
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StableKeywordsCheck
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ARCH="amd64"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ARCH="x86"
2 changes: 2 additions & 0 deletions testdata/repos/stable_keywords/profiles/profiles.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
amd64 default/amd64 stable
x86 default/x86 stable
1 change: 1 addition & 0 deletions testdata/repos/stable_keywords/profiles/repo_name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable_keywords