Skip to content

Commit 9adb90b

Browse files
committed
skip annotations for version results
Add support for an ebuild to declare a skip annotation for a class of *version* results. This skip annotation must be declared before any non-comment non-empty line (most of the times it would be before the EAPI declaration). Empty lines between the copyright and the annotation are allowed. The annotation line must be precise, only one class per line and every space is required. For example, it would look like: # Copyright 2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # pkgcheck skip: PythonCompatUpdate EAPI=8 Resolves: #478 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent b383af2 commit 9adb90b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/pkgcheck/results.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ def __init__(self, pkg, **kwargs):
225225
self.version = pkg.fullver
226226
self._attr = "version"
227227

228+
if self.__class__.__name__ in getattr(pkg, "skipped_results", ()):
229+
self._filtered = True
230+
228231
@klass.jit_attr
229232
def ver_rev(self):
230233
version, _, revision = self.version.partition("-r")

src/pkgcheck/sources.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,21 @@ def itermatch(self, restrict, **kwargs):
292292
class _SourcePkg(WrappedPkg):
293293
"""Package object with file contents injected as an attribute."""
294294

295-
__slots__ = ("lines",)
295+
__slots__ = ("lines", "skipped_results")
296296

297297
def __init__(self, pkg):
298298
super().__init__(pkg)
299299
with pkg.ebuild.text_fileobj() as fileobj:
300300
self.lines = tuple(fileobj)
301301

302+
skipped_results: set[str] = set()
303+
for line in map(str.rstrip, self.lines):
304+
if line and not line.startswith("#"):
305+
break # stop after first non-comment non-empty line
306+
elif line.startswith("# pkgcheck skip:"):
307+
skipped_results.add(line[16:].strip())
308+
self.skipped_results = frozenset(skipped_results)
309+
302310

303311
class EbuildFileRepoSource(RepoSource):
304312
"""Ebuild repository source yielding package objects and their file contents."""
@@ -311,6 +319,17 @@ def itermatch(self, restrict, **kwargs):
311319
class _ParsedPkg(ParseTree, WrappedPkg):
312320
"""Parsed package object."""
313321

322+
def __init__(self, data: bytes, **kwargs):
323+
super().__init__(data, **kwargs)
324+
325+
skipped_results: set[str] = set()
326+
for line in data.splitlines():
327+
if line and not line.startswith(b"#"):
328+
break # stop after first non-comment non-empty line
329+
elif line.startswith(b"# pkgcheck skip:"):
330+
skipped_results.add(line[16:].strip().decode("utf8"))
331+
self.skipped_results = frozenset(skipped_results)
332+
314333

315334
class EbuildParseRepoSource(RepoSource):
316335
"""Ebuild repository source yielding parsed packages."""

0 commit comments

Comments
 (0)