cli/pkgcheck: filter by message or keywords
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Anna “CyberTailor” 2024-01-15 09:42:13 +05:00
parent 9c0702e032
commit 9dfac70fa1
Signed by: CyberTaIlor
GPG Key ID: E7B76EDC50864BB1
7 changed files with 47 additions and 17 deletions

View File

@ -5,6 +5,11 @@
Release Notes
=============
0.6.0
-----
* **New:** Filter ``pkgcheck`` results by keyword or message.
0.5.0
-----

View File

@ -84,15 +84,22 @@ def pgo(options: Options) -> None:
@cli.group(aliases=["chk", "c"], cls=ClickAliasedGroup)
@click.option("-M", "--message", metavar="LIST",
help="Warning message to search for.")
@click.option("-k", "--keywords", metavar="LIST",
help="Keywords to scan for.")
@click.option("-r", "--repo", metavar="REPO", required=True,
help="Repository name or absolute path.")
@click.pass_obj
def pkgcheck(options: Options, repo: str) -> None:
def pkgcheck(options: Options, message: str | None, keywords: str | None,
repo: str) -> None:
""" Use pkgcheck to find work. """
options.cache_key.feed("pkgcheck")
options.pkgcheck.repo = repo
options.pkgcheck.keywords = (keywords or "").split(",")
options.pkgcheck.message = message or ""
for key in options.pkgcheck.cache_order:
options.cache_key.feed_option(key, options.pkgcheck[key])

View File

@ -31,12 +31,14 @@ class CacheKey:
True
>>> key.feed_option("flag", True)
True
>>> key.feed_option("keywords", ["wow", "amazing"])
True
>>> bytes(key)
b'bytes\\x00string\\x00count:42\\x00flag:1\\x00'
>>> key.feed([1, 2, 3])
b'bytes\\x00string\\x00count:42\\x00flag:1\\x00keywords:amazing\\x19wow\\x00'
>>> key.feed({1, 2, 3})
Traceback (most recent call last):
...
TypeError: Unsupported type: list
TypeError: Unsupported type: set
"""
data: bytes = b""
@ -52,6 +54,8 @@ class CacheKey:
return value
case str():
return value.encode()
case list():
return b"\31".join(map(cls._encode, sorted(value)))
case bool():
return b"1" if value else b"0"
case int():
@ -62,7 +66,7 @@ class CacheKey:
@classmethod
def _feedable(cls, value: Any) -> bool:
match value:
case bytes() | str():
case bytes() | str() | list():
return bool(value)
case bool() | int():
return True

View File

@ -101,9 +101,15 @@ class PkgcheckOptions(ModuleOptionsBase):
# Repository name or absolute path.
repo: str = ""
# Class of the pkgcheck warning, e.g. DeprecatedEapi
keywords: list[str] = field(default_factory=list)
# Message of the pkgcheck warning, e.g. 'uses deprecated EAPI 5'
message: str = ""
@cached_property
def cache_order(self) -> list[str]:
return ["repo"]
return ["repo", "keywords", "message"]
@dataclass

View File

@ -10,7 +10,6 @@ import pkgcheck
from sortedcontainers import SortedDict, SortedSet
from find_work.cli import Message, Options, ProgressDots
from find_work.constants import PKGCHECK_MIN_PACKAGE_SCOPE
def _do_scan(options: Options) -> SortedDict[str, SortedSet]:
@ -20,12 +19,16 @@ def _do_scan(options: Options) -> SortedDict[str, SortedSet]:
repo_obj = pm.repositories[options.pkgcheck.repo]
cli_opts = [
"-r", options.pkgcheck.repo,
"-f", "latest", # TODO: become version-aware
"--repo", options.pkgcheck.repo,
"--scope", "pkg,ver",
"--filter", "latest", # TODO: become version-aware
]
if options.pkgcheck.keywords:
cli_opts += ["--keywords", ",".join(options.pkgcheck.keywords)]
data: SortedDict[str, SortedSet] = SortedDict()
for result in pkgcheck.scan(cli_opts):
if result.scope.level < PKGCHECK_MIN_PACKAGE_SCOPE:
if options.pkgcheck.message not in result.desc:
continue
package = "/".join([result.category, result.package])

View File

@ -30,6 +30,3 @@ PGO_BASE_URL = "https://packages.gentoo.org"
# Gentoo Packages API location.
PGO_API_URL = f"{PGO_BASE_URL}/api/graphql/"
# Scope level for `pkgcheck.base.package_scope`.
PKGCHECK_MIN_PACKAGE_SCOPE = 3

View File

@ -93,6 +93,8 @@ Find stabilization candidates.
.It Xo
.Cm pkgcheck
.Fl r Ar repo
.Op Fl M Ar text
.Op Fl k Ar keyword
.Ar command
.Xc
.Dl Pq alias: Cm chk , Cm c
@ -109,8 +111,14 @@ The options for
.Cm find-work pkgcheck
are as follows:
.Bl -tag -width Ds
.It Fl M Ar text , Fl -message Ar text
Message of the pkgcheck warning, e.g.
.Qq uses deprecated EAPI 5 .
.It Fl k Ar keyword , Fl -keywords Ar keyword
Comma-separated list of pkgcheck keywords, e.g. DeprecatedEapi.
.It Fl r Ar repo , Fl -repo Ar repo
Repository name or absolute path.
This option is required.
.El
.
.It Xo
@ -139,13 +147,13 @@ This option is required.
Some examples for Gentoo include:
.Bl -bullet -compact -width 1n
.It
.Ql gentoo
.Qq gentoo
.It
.Ql gentoo_ovl_guru
.Qq gentoo_ovl_guru
.It
.Ql gentoo_ovl_pentoo
.Qq gentoo_ovl_pentoo
.It
.Ql gentoo_ovl_science
.Qq gentoo_ovl_science
.El
.El
.El