commit: 6b162965a4df53510babbff48c5e59226e77cee5 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Tue Oct 11 20:04:45 2022 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Wed Oct 12 17:40:27 2022 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=6b162965
RedundantVersionCheck: consider profile masks during check When checking for redundant version, also check that on a profile doesn't exist where the package is visible, but all later versions aren't, which means that this package isn't redundant on that profile. Resolves: https://github.com/pkgcore/pkgcheck/issues/465 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/addons/profiles.py | 4 +++ src/pkgcheck/checks/cleanup.py | 37 ++++++++++++++++++++-- .../RedundantVersion/expected.json | 3 ++ .../RedundantVersion/RedundantVersion-1.ebuild | 5 +++ .../RedundantVersion/RedundantVersion-2.ebuild | 5 +++ .../RedundantVersion/RedundantVersion-3.ebuild | 5 +++ .../RedundantVersion/RedundantVersion-4.ebuild | 5 +++ .../RedundantVersion/RedundantVersion-5.ebuild | 5 +++ .../RedundantVersion/RedundantVersion-6.ebuild | 5 +++ testdata/repos/profiledir/profiles/arch.list | 1 + testdata/repos/profiledir/profiles/profiles.desc | 4 +++ .../repos/profiledir/profiles/redundant/amd64/eapi | 1 + .../profiledir/profiles/redundant/amd64/musl/eapi | 1 + .../profiles/redundant/amd64/musl/package.mask | 2 ++ .../profiles/redundant/amd64/musl/parent | 1 + .../profiles/redundant/amd64/package.mask | 3 ++ .../profiledir/profiles/redundant/amd64/parent | 1 + testdata/repos/profiledir/profiles/redundant/eapi | 1 + .../profiledir/profiles/redundant/package.mask | 1 + .../repos/profiledir/profiles/redundant/x86/eapi | 1 + .../profiledir/profiles/redundant/x86/package.mask | 2 ++ .../repos/profiledir/profiles/redundant/x86/parent | 1 + tests/checks/test_cleanup.py | 4 +-- 23 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/pkgcheck/addons/profiles.py b/src/pkgcheck/addons/profiles.py index 4e3fc3e1..02b31eda 100644 --- a/src/pkgcheck/addons/profiles.py +++ b/src/pkgcheck/addons/profiles.py @@ -396,6 +396,10 @@ class ProfileAddon(caches.CachedAddon): except KeyError: return default + def items(self): + """Iterate over all keywords and profiles.""" + return self.profile_filters.items() + def __iter__(self): """Iterate over all profile data objects.""" return chain.from_iterable(self.profile_filters.values()) diff --git a/src/pkgcheck/checks/cleanup.py b/src/pkgcheck/checks/cleanup.py index 8d02db7d..076d56be 100644 --- a/src/pkgcheck/checks/cleanup.py +++ b/src/pkgcheck/checks/cleanup.py @@ -1,6 +1,9 @@ +from operator import attrgetter + +from snakeoil.mappings import defaultdictkey from snakeoil.strings import pluralism -from .. import results, sources +from .. import addons, results, sources from . import Check @@ -31,6 +34,7 @@ class RedundantVersionCheck(Check): """ _source = sources.PackageRepoSource + required_addons = (addons.profiles.ProfileAddon,) known_results = frozenset([RedundantVersion]) @staticmethod @@ -44,6 +48,31 @@ class RedundantVersionCheck(Check): successful stabilization. """) + def __init__(self, *args, profile_addon): + super().__init__(*args) + self.keywords_profiles = { + keyword: sorted(profiles, key=attrgetter('name')) + for keyword, profiles in profile_addon.items()} + + def filter_later_profiles_masks(self, visible_cache, pkg, later_versions): + # check both stable/unstable profiles for stable KEYWORDS and only + # unstable profiles for unstable KEYWORDS + keywords = [] + for keyword in pkg.sorted_keywords: + if keyword[0] != '~': + keywords.append('~' + keyword) + keywords.append(keyword) + + # if a profile exists, where the package is visible, but the later aren't + # then it isn't redundant + visible_profiles = tuple(profile + for keyword in keywords + for profile in self.keywords_profiles.get(keyword, ()) + if visible_cache[(profile, pkg)]) + return tuple( + later for later in later_versions + if all(visible_cache[(profile, later)] for profile in visible_profiles)) + def feed(self, pkgset): if len(pkgset) == 1: return @@ -77,8 +106,10 @@ class RedundantVersionCheck(Check): if matches: bad.append((pkg, matches)) + visible_cache = defaultdictkey(lambda profile_pkg: profile_pkg[0].visible(profile_pkg[1])) for pkg, matches in reversed(bad): - later_versions = (x.fullver for x in sorted(matches)) if self.options.stable_only and all(key.startswith('~') for x in matches for key in x.keywords): continue - yield RedundantVersion(pkg.slot, later_versions, pkg=pkg) + if matches := self.filter_later_profiles_masks(visible_cache, pkg, matches): + later_versions = (x.fullver for x in sorted(matches)) + yield RedundantVersion(pkg.slot, later_versions, pkg=pkg) diff --git a/testdata/data/repos/profiledir/RedundantVersionCheck/RedundantVersion/expected.json b/testdata/data/repos/profiledir/RedundantVersionCheck/RedundantVersion/expected.json new file mode 100644 index 00000000..cb467108 --- /dev/null +++ b/testdata/data/repos/profiledir/RedundantVersionCheck/RedundantVersion/expected.json @@ -0,0 +1,3 @@ +{"__class__": "RedundantVersion", "category": "RedundantVersionCheck", "package": "RedundantVersion", "version": "3", "slot": "0", "later_versions": ["6"]} +{"__class__": "RedundantVersion", "category": "RedundantVersionCheck", "package": "RedundantVersion", "version": "4", "slot": "0", "later_versions": ["6"]} +{"__class__": "RedundantVersion", "category": "RedundantVersionCheck", "package": "RedundantVersion", "version": "5", "slot": "0", "later_versions": ["6"]} diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-1.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-1.ebuild new file mode 100644 index 00000000..2e970b4a --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-1.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="amd64 x86" diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-2.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-2.ebuild new file mode 100644 index 00000000..2e970b4a --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-2.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="amd64 x86" diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-3.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-3.ebuild new file mode 100644 index 00000000..407949a6 --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-3.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="~amd64 ~x86" diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-4.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-4.ebuild new file mode 100644 index 00000000..407949a6 --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-4.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="~amd64 ~x86" diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-5.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-5.ebuild new file mode 100644 index 00000000..407949a6 --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-5.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="~amd64 ~x86" diff --git a/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-6.ebuild b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-6.ebuild new file mode 100644 index 00000000..407949a6 --- /dev/null +++ b/testdata/repos/profiledir/RedundantVersionCheck/RedundantVersion/RedundantVersion-6.ebuild @@ -0,0 +1,5 @@ +DESCRIPTION="Stub ebuild used for RedundantVersion checks" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" +KEYWORDS="~amd64 ~x86" diff --git a/testdata/repos/profiledir/profiles/arch.list b/testdata/repos/profiledir/profiles/arch.list index 0d9b169f..fe8e46db 100644 --- a/testdata/repos/profiledir/profiles/arch.list +++ b/testdata/repos/profiledir/profiles/arch.list @@ -1,2 +1,3 @@ amd64 unknown_arch +x86 diff --git a/testdata/repos/profiledir/profiles/profiles.desc b/testdata/repos/profiledir/profiles/profiles.desc index ea649fd9..53c9769b 100644 --- a/testdata/repos/profiledir/profiles/profiles.desc +++ b/testdata/repos/profiledir/profiles/profiles.desc @@ -15,3 +15,7 @@ amd64 deprecated/nonexistent exp amd64 banned-eapi dev amd64 deprecated-eapi stable + +amd64 redundant/amd64 stable +amd64 redundant/amd64/musl dev +x86 redundant/x86 stable diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/eapi b/testdata/repos/profiledir/profiles/redundant/amd64/eapi new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/eapi @@ -0,0 +1 @@ +7 diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/musl/eapi b/testdata/repos/profiledir/profiles/redundant/amd64/musl/eapi new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/musl/eapi @@ -0,0 +1 @@ +7 diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/musl/package.mask b/testdata/repos/profiledir/profiles/redundant/amd64/musl/package.mask new file mode 100644 index 00000000..3fb5e793 --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/musl/package.mask @@ -0,0 +1,2 @@ +-=RedundantVersionCheck/RedundantVersion-4 +=RedundantVersionCheck/RedundantVersion-5 diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/musl/parent b/testdata/repos/profiledir/profiles/redundant/amd64/musl/parent new file mode 100644 index 00000000..f3229c5b --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/musl/parent @@ -0,0 +1 @@ +.. diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/package.mask b/testdata/repos/profiledir/profiles/redundant/amd64/package.mask new file mode 100644 index 00000000..67f4343e --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/package.mask @@ -0,0 +1,3 @@ +=RedundantVersionCheck/RedundantVersion-2 +=RedundantVersionCheck/RedundantVersion-4 +-=RedundantVersionCheck/RedundantVersion-6 diff --git a/testdata/repos/profiledir/profiles/redundant/amd64/parent b/testdata/repos/profiledir/profiles/redundant/amd64/parent new file mode 100644 index 00000000..f3229c5b --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/amd64/parent @@ -0,0 +1 @@ +.. diff --git a/testdata/repos/profiledir/profiles/redundant/eapi b/testdata/repos/profiledir/profiles/redundant/eapi new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/eapi @@ -0,0 +1 @@ +7 diff --git a/testdata/repos/profiledir/profiles/redundant/package.mask b/testdata/repos/profiledir/profiles/redundant/package.mask new file mode 100644 index 00000000..f0d7d751 --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/package.mask @@ -0,0 +1 @@ +=RedundantVersionCheck/RedundantVersion-6 diff --git a/testdata/repos/profiledir/profiles/redundant/x86/eapi b/testdata/repos/profiledir/profiles/redundant/x86/eapi new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/x86/eapi @@ -0,0 +1 @@ +7 diff --git a/testdata/repos/profiledir/profiles/redundant/x86/package.mask b/testdata/repos/profiledir/profiles/redundant/x86/package.mask new file mode 100644 index 00000000..724f1a6a --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/x86/package.mask @@ -0,0 +1,2 @@ +=RedundantVersionCheck/RedundantVersion-2 +-=RedundantVersionCheck/RedundantVersion-6 diff --git a/testdata/repos/profiledir/profiles/redundant/x86/parent b/testdata/repos/profiledir/profiles/redundant/x86/parent new file mode 100644 index 00000000..f3229c5b --- /dev/null +++ b/testdata/repos/profiledir/profiles/redundant/x86/parent @@ -0,0 +1 @@ +.. diff --git a/tests/checks/test_cleanup.py b/tests/checks/test_cleanup.py index 15da8a87..4e1aa2b3 100644 --- a/tests/checks/test_cleanup.py +++ b/tests/checks/test_cleanup.py @@ -11,7 +11,7 @@ def mk_pkg(ver, keywords=("x86", "amd64"), slot="0", **kwds): class TestRedundantVersion(misc.ReportTestCase): check_kls = cleanup.RedundantVersionCheck - check = cleanup.RedundantVersionCheck(arghparse.Namespace(stable_only=None)) + check = check_kls(arghparse.Namespace(stable_only=True), profile_addon={}) def test_single_version(self): self.assertNoReport(self.check, [mk_pkg("0.7.1")]) @@ -68,7 +68,7 @@ class TestRedundantVersion(misc.ReportTestCase): class TestRedundantVersionByStable(misc.ReportTestCase): check_kls = cleanup.RedundantVersionCheck - check = cleanup.RedundantVersionCheck(arghparse.Namespace(stable_only=True)) + check = cleanup.RedundantVersionCheck(arghparse.Namespace(stable_only=True), profile_addon={}) def test_only_unstable(self): l = [mk_pkg("0.1", keywords=("~x86", "~amd64")),
