Skip to content

Commit c8235ac

Browse files
committed
pkgcheck scan: add initial latest pkgs filter support to -f/--filter
Fixes #184.
1 parent b3cc0cc commit c8235ac

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/pkgcheck/scripts/pkgcheck.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,17 @@ def __call__(self, parser, namespace, values, option_string=None):
136136
action=commandline.StoreRepoObject, repo_type='ebuild-raw', allow_external_repos=True,
137137
help='repo to pull packages from')
138138
main_options.add_argument(
139-
'-f', '--filter', choices=('repo',),
140-
help="enable all license and visibility filtering for packages",
139+
'-f', '--filter', choices=('latest', 'repo',),
140+
help='limit targeted packages for scanning',
141141
docs="""
142-
Enable all package filtering mechanisms such as ACCEPT_KEYWORDS,
143-
ACCEPT_LICENSE, and package.mask.
142+
Support limiting targeted packages for scanning using a chosen filter.
143+
144+
If the 'repo' argument is used, all package visibility mechanisms used
145+
by the package manager when resolving package dependencies such as
146+
ACCEPT_KEYWORDS, ACCEPT_LICENSE, and package.mask will be enabled.
147+
148+
If the 'latest' argument is used, only the latest package per slot of
149+
both VCS and non-VCS types will be scanned.
144150
""")
145151
main_options.add_argument(
146152
'--sorted', action='store_true',
@@ -514,6 +520,11 @@ def restrictions():
514520
namespace.enabled_checks = [
515521
c for c in namespace.enabled_checks if not c.skip(namespace)]
516522

523+
# only run version scope checks when using a package filter
524+
if namespace.filter in ('latest',):
525+
namespace.enabled_checks = [
526+
c for c in namespace.enabled_checks if c.scope == base.version_scope]
527+
517528
if not namespace.enabled_checks:
518529
parser.error('no active checks')
519530

src/pkgcheck/sources.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def source(self):
4646
def itermatch(self, restrict, **kwargs):
4747
"""Yield packages matching the given restriction from the selected source."""
4848
kwargs.setdefault('sorter', sorted)
49-
yield from self.source.itermatch(restrict, **kwargs)
49+
unfiltered_iter = self.source.itermatch(restrict, **kwargs)
50+
if self._options.filter == 'latest':
51+
yield from LatestPkgsFilter(unfiltered_iter)
52+
else:
53+
yield from unfiltered_iter
5054

5155

5256
class EmptySource(Source):
@@ -153,10 +157,13 @@ class RawRepoSource(RepoSource):
153157

154158
def __init__(self, *args):
155159
super().__init__(*args)
156-
self._repo = _RawRepo(self._repo)
157160

158161
def itermatch(self, restrict, **kwargs):
159-
yield from super().itermatch(restrict, raw_pkg_cls=RawCPV, **kwargs)
162+
if self._options.filter == 'latest':
163+
yield from LatestPkgsFilter(super().itermatch(restrict, **kwargs))
164+
else:
165+
self._repo = _RawRepo(self._repo)
166+
yield from super().itermatch(restrict, raw_pkg_cls=RawCPV, **kwargs)
160167

161168

162169
class RestrictionRepoSource(RepoSource):

0 commit comments

Comments
 (0)