-
Notifications
You must be signed in to change notification settings - Fork 32
StableKeywordsCheck: detect packages using stable keywords #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.""" | ||||||
|
|
||||||
| 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, ...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be package scope; the only results it generates are package scope already. |
||||||
| required_addons = (addons.StableArchesAddon,) | ||||||
| known_results = frozenset([StableKeywords]) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| def __init__(self, *args, stable_arches_addon=None): | ||||||
| super().__init__(*args) | ||||||
| self.arches = {x.strip().lstrip("~") for x in self.options.stable_arches} | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I like immutability
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request to make this immutable may sound pedantic, but I fixed an issue the other day where code was incorrectly mutating a Result object, so that pattern we maintain, exists for a valid reason. It's not python standard, but the defensive approach has prevented a surprisingly large amount of fuckups. TL;DR: please make it immutable. Frankly a tuple is fine rather than a frozenset also, but whatever convention is, go with that. |
||||||
|
|
||||||
| 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]) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move Encapsulation wise, it shouldn't expect that creators of the instance know to sort that value. Your code does, other code absolutely won't. :) |
||||||
| 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" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| masters = | ||
| cache-formats = |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| amd64 | ||
| x86 |
| 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" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| amd64 default/amd64 stable | ||
| x86 default/x86 stable |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| stable_keywords |
There was a problem hiding this comment.
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.