aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2021-02-08 22:52:18 -0700
committerTim Harder <radhermit@gmail.com>2021-02-08 22:53:58 -0700
commit2b820cf5fd85bbc1c96808f695ae42a6e8eaabeb (patch)
treec78729681c333c982a5bafc8b06b0994414ee710 /src/pkgcheck
parentpipeline: minor comment updates (diff)
downloadpkgcheck-2b820cf5fd85bbc1c96808f695ae42a6e8eaabeb.tar.gz
pkgcheck-2b820cf5fd85bbc1c96808f695ae42a6e8eaabeb.tar.bz2
pkgcheck-2b820cf5fd85bbc1c96808f695ae42a6e8eaabeb.zip
pipeline: collapse restrictions to list during generation phase
Diffstat (limited to 'src/pkgcheck')
-rw-r--r--src/pkgcheck/api.py2
-rw-r--r--src/pkgcheck/pipeline.py13
-rw-r--r--src/pkgcheck/scripts/pkgcheck.py36
3 files changed, 23 insertions, 28 deletions
diff --git a/src/pkgcheck/api.py b/src/pkgcheck/api.py
index c4413277..2ead87b7 100644
--- a/src/pkgcheck/api.py
+++ b/src/pkgcheck/api.py
@@ -31,4 +31,4 @@ def scan(args=None, /, *, base_args=None):
with patch('argparse.ArgumentParser.exit', parser_exit):
options = pkgcheck.argparser.parse_args(base_args + ['scan'] + args)
- return Pipeline(options, options.restrictions)
+ return Pipeline(options)
diff --git a/src/pkgcheck/pipeline.py b/src/pkgcheck/pipeline.py
index 8c5779f4..207470bc 100644
--- a/src/pkgcheck/pipeline.py
+++ b/src/pkgcheck/pipeline.py
@@ -28,22 +28,17 @@ class Pipeline:
group to end when an exception is raised.
"""
- def __init__(self, options, restrictions):
+ def __init__(self, options):
self.options = options
# number of error results encountered (used with --exit option)
self.errors = 0
- # Note that this blocks scanning until piped-in targets are read.
- restrictions = list(restrictions)
- if not restrictions:
- raise base.PkgcheckUserException('no targets piped in')
-
# pkgcheck currently requires the fork start method (#254)
self._mp_ctx = multiprocessing.get_context('fork')
self._results_q = self._mp_ctx.SimpleQueue()
# create checkrunners
- self._pipes = self._create_runners(restrictions)
+ self._pipes = self._create_runners()
# initialize settings used by iterator support
self._pid = None
@@ -85,7 +80,7 @@ class Pipeline:
# package level.
yield check
- def _create_runners(self, restrictions):
+ def _create_runners(self):
"""Initialize and categorize checkrunners for results pipeline."""
runner_cls = {'async': AsyncCheckRunner, 'sync': SyncCheckRunner}
pipes = {'async': [], 'sync': []}
@@ -94,7 +89,7 @@ class Pipeline:
addons_map = {}
source_map = {}
- for scope, restriction in restrictions:
+ for scope, restriction in self.options.restrictions:
# initialize enabled checks
addons = list(base.get_addons(self._filter_checks(scope)))
if not addons:
diff --git a/src/pkgcheck/scripts/pkgcheck.py b/src/pkgcheck/scripts/pkgcheck.py
index eb1c7778..3412005b 100644
--- a/src/pkgcheck/scripts/pkgcheck.py
+++ b/src/pkgcheck/scripts/pkgcheck.py
@@ -480,23 +480,23 @@ def _default_filtered_keywords(namespace, attr):
def _determine_restrictions(namespace, attr):
"""Determine restrictions for untargeted scans and generate collapsed restriction for targeted scans."""
if namespace.targets:
- # Collapse restrictions for passed in targets while keeping the
- # generator intact for piped in targets.
- restrictions = generate_restricts(namespace.target_repo, namespace.targets)
- if isinstance(namespace.targets, list):
- restrictions = list(restrictions)
-
- # collapse restrictions in order to run them in parallel
- if len(restrictions) > 1:
- # multiple targets are restricted to a single scanning scope
- scopes = {scope for scope, restrict in restrictions}
- if len(scopes) > 1:
- scan_scopes = ', '.join(sorted(s.desc for s in scopes))
- raise PkgcheckUserException(
- f'targets specify multiple scan scope levels: {scan_scopes}')
-
- combined_restrict = boolean.OrRestriction(*(r for s, r in restrictions))
- restrictions = [(scopes.pop(), combined_restrict)]
+ # Generate restrictions for all targets. Note that this blocks scanning
+ # until piped-in targets are read.
+ restrictions = list(generate_restricts(namespace.target_repo, namespace.targets))
+ if not restrictions:
+ raise PkgcheckUserException('no targets')
+
+ # collapse restrictions in order to run them in parallel
+ if len(restrictions) > 1:
+ # multiple targets are restricted to a single scanning scope
+ scopes = {scope for scope, restrict in restrictions}
+ if len(scopes) > 1:
+ scan_scopes = ', '.join(sorted(s.desc for s in scopes))
+ raise PkgcheckUserException(
+ f'targets specify multiple scan scope levels: {scan_scopes}')
+
+ combined_restrict = boolean.OrRestriction(*(r for s, r in restrictions))
+ restrictions = [(scopes.pop(), combined_restrict)]
else:
if namespace.cwd in namespace.target_repo:
scope, restrict = _path_restrict(namespace.cwd, namespace.target_repo)
@@ -515,7 +515,7 @@ def _scan(options, out, err):
reporter = options.reporter(out)
for c in options.pop('contexts') + [reporter]:
stack.enter_context(c)
- pipe = Pipeline(options, options.restrictions)
+ pipe = Pipeline(options)
for result in pipe:
reporter.report(result)
return int(bool(pipe.errors))