From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 583A415800F for ; Sun, 5 Feb 2023 17:57:01 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 63F14E07D1; Sun, 5 Feb 2023 17:57:00 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4531DE07D1 for ; Sun, 5 Feb 2023 17:57:00 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 597D9335D4C for ; Sun, 5 Feb 2023 17:56:59 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A622483C for ; Sun, 5 Feb 2023 17:56:57 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1675619612.5727b3be6b1b99ae6d47873585a8e92e96147a9f.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/ X-VCS-Repository: proj/pkgcore/pkgcheck X-VCS-Files: src/pkgcheck/checks/codingstyle.py X-VCS-Directories: src/pkgcheck/checks/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: 5727b3be6b1b99ae6d47873585a8e92e96147a9f X-VCS-Branch: master Date: Sun, 5 Feb 2023 17:56:57 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 4fc18253-53a7-43db-ad3b-8136b5b27d02 X-Archives-Hash: b1c0aca5683580c413eafcf163bedaed commit: 5727b3be6b1b99ae6d47873585a8e92e96147a9f Author: Arthur Zamarin gentoo org> AuthorDate: Sun Feb 5 17:53:32 2023 +0000 Commit: Arthur Zamarin gentoo 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 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)