Skip to content

Commit b4b42bb

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: pkgcore#478 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent eb6a62d commit b4b42bb

File tree

6 files changed

+80
-1
lines changed

6 files changed

+80
-1
lines changed

doc/index.rst

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Contents:
1010
news
1111
api
1212
man/pkgcheck
13+
man/pkgcheck/scan
14+
man/pkgcheck/keywords
15+
man/pkgcheck/checks
16+
man/config
17+
man/skip
18+
19+
Reporting Bugs
20+
==============
21+
22+
Please submit an issue via github:
23+
24+
https://github.com/pkgcore/pkgcheck/issues
1325

1426
Indices and tables
1527
==================

doc/man/pkgcheck.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pkgcheck
1212
.. include:: pkgcheck/reporters.rst
1313

1414
.. include:: config.rst
15+
.. include:: skip.rst
1516

1617
Reporting Bugs
1718
==============

doc/man/skip.rst

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Skip results annotations
2+
========================
3+
4+
pkgcheck supports skipping ebuilds results via special annotation. This is
5+
useful in cases where you are aware of false positive in pkgcheck check, and
6+
fixing pkgcheck is hard or impossible.
7+
8+
The annotation must appear in the ebuild before any non-comment non-empty line
9+
(most of the times it would be just before the EAPI declaration line and after
10+
the copyright lines). Empty lines between the copyright and the annotation are
11+
allowed.
12+
13+
You can't skip *error* level results. Skipping *warning* level results requires
14+
QA team member approval (should include name and RFC 3339 data). *info* and
15+
*style* level can be skipped without approval. Do consider to just ignore them
16+
instead of skipping.
17+
18+
An example of skipping a *info* and *warning* level results::
19+
20+
# Copyright 2023 Gentoo Authors
21+
# Distributed under the terms of the GNU General Public License v2
22+
23+
# pkgcheck skip: PythonCompatUpdate
24+
25+
# Approved by larry 2023-04-31
26+
# pkgcheck skip: VariableScope
27+
28+
EAPI=8

src/pkgcheck/results.py

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ def __init__(self, pkg, **kwargs):
225225
self.version = pkg.fullver
226226
self._attr = "version"
227227

228+
if (
229+
self.__class__.__name__ in getattr(pkg, "skipped_results", ())
230+
and getattr(self, "level", "") != "error"
231+
):
232+
self._filtered = True
233+
228234
@klass.jit_attr
229235
def ver_rev(self):
230236
version, _, revision = self.version.partition("-r")

src/pkgcheck/sources.py

+20-1
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."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pkgcheck skip: InstallCompressedInfo
2+
3+
EAPI=7
4+
5+
DESCRIPTION="Ebuild installing compressed info, but with result marked skipped"
6+
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
7+
SLOT="0"
8+
LICENSE="BSD"
9+
10+
src_install() {
11+
doinfo 'test.gz' "${PN}.bz2"
12+
doinfo "${PN}"
13+
}

0 commit comments

Comments
 (0)