commit: 5727b3be6b1b99ae6d47873585a8e92e96147a9f Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Sun Feb 5 17:53:32 2023 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Sun Feb 5 17:53:32 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=5727b3be
UnusedInherits: fix false positives for eclasses defining special vars Skip unused warning for eclasses which define special variables like SRC_URI, HOMEPAGE, etc. In practice it makes any inherit for pypi, ruby-fakegem, ruby-ng-gnome2, gstreamer-meson to never be considered unused. Resolves: https://github.com/pkgcore/pkgcheck/issues/361 Resolves: https://github.com/pkgcore/pkgcheck/issues/540 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/codingstyle.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py index 6fec22ca..a9eb70fa 100644 --- a/src/pkgcheck/checks/codingstyle.py +++ b/src/pkgcheck/checks/codingstyle.py @@ -3,7 +3,7 @@ import re from collections import defaultdict -from pkgcore.ebuild.eapi import EAPI +from pkgcore.ebuild.eapi import EAPI, common_mandatory_metadata_keys from snakeoil.mappings import ImmutableDict from snakeoil.sequences import stable_unique from snakeoil.strings import pluralism @@ -758,10 +758,9 @@ class InheritsCheck(Check): # register EAPI-related vars to ignore # TODO: add ebuild env vars via pkgcore setting, e.g. PN, PV, P, FILESDIR, etc - self.eapi_vars = {} - for eapi in EAPI.known_eapis.values(): - s = set(eapi.eclass_keys) - self.eapi_vars[eapi] = frozenset(s) + self.eapi_vars = {eapi: frozenset(eapi.eclass_keys) for eapi in EAPI.known_eapis.values()} + + self.unused_eclass_skiplist = frozenset(common_mandatory_metadata_keys) - {"IUSE"} def get_eclass(self, export, pkg): """Return the eclass related to a given exported variable or function name.""" @@ -851,10 +850,12 @@ class InheritsCheck(Check): # ignore eclasses with parsing failures unused.discard(eclass) else: - exported_eclass_keys = pkg.eapi.eclass_keys.intersection( + exported_eclass_keys: set[str] = pkg.eapi.eclass_keys.intersection( self.eclass_cache[eclass].exported_variable_names ) - if not self.eclass_cache[eclass].exported_function_names and exported_eclass_keys: + if exported_eclass_keys.intersection(self.unused_eclass_skiplist): + unused.discard(eclass) + elif not self.eclass_cache[eclass].exported_function_names and exported_eclass_keys: # ignore eclasses that export ebuild metadata (e.g. # SRC_URI, S, ...) and no functions unused.discard(eclass)
