diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2022-09-23 09:57:53 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2022-09-30 18:52:26 +0300 |
commit | 5dec06660f822e3f73fe3180298efdc2684922a5 (patch) | |
tree | 7c11f5aabf893fec2f5870743e7835deb1eadd67 /src/pkgcheck/scripts | |
parent | StaticSrcUri: handle more cases (diff) | |
download | pkgcheck-5dec06660f822e3f73fe3180298efdc2684922a5.tar.gz pkgcheck-5dec06660f822e3f73fe3180298efdc2684922a5.tar.bz2 pkgcheck-5dec06660f822e3f73fe3180298efdc2684922a5.zip |
scan: respect jobs count from MAKEOPTS
When selecting the default `--jobs` value for `pkgcheck scan`, respect
`MAKEOPTS`. As a result, it selects the correct value during tests
phase.
Bug: https://bugs.gentoo.org/799314
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'src/pkgcheck/scripts')
-rw-r--r-- | src/pkgcheck/scripts/pkgcheck_scan.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/pkgcheck/scripts/pkgcheck_scan.py b/src/pkgcheck/scripts/pkgcheck_scan.py index 4598c511..c6300b5b 100644 --- a/src/pkgcheck/scripts/pkgcheck_scan.py +++ b/src/pkgcheck/scripts/pkgcheck_scan.py @@ -1,5 +1,6 @@ import argparse import os +import shlex from contextlib import ExitStack from pkgcore import const as pkgcore_const @@ -63,14 +64,14 @@ main_options.add_argument( 'no' argument. """) main_options.add_argument( - '-j', '--jobs', type=arghparse.positive_int, default=os.cpu_count(), + '-j', '--jobs', type=arghparse.positive_int, help='number of checks to run in parallel', docs=""" Number of checks to run in parallel, defaults to using all available processors. """) main_options.add_argument( - '-t', '--tasks', type=arghparse.positive_int, default=os.cpu_count() * 5, + '-t', '--tasks', type=arghparse.positive_int, help='number of asynchronous tasks to run concurrently', docs=""" Number of asynchronous tasks to run concurrently (defaults to 5 * CPU count). @@ -381,6 +382,21 @@ def generate_restricts(repo, targets): raise PkgcheckUserException(str(e)) +@scan.bind_delayed_default(1000, 'jobs') +def _default_jobs(namespace, attr): + """Extract jobs count from MAKEOPTS.""" + parser = argparse.ArgumentParser() + parser.add_argument('-j', '--jobs', type=arghparse.positive_int, default=os.cpu_count()) + makeopts, _ = parser.parse_known_args(shlex.split(os.getenv('MAKEOPTS', ''))) + setattr(namespace, attr, makeopts.jobs) + + +@scan.bind_delayed_default(1001, 'tasks') +def _default_tasks(namespace, attr): + """Set based on jobs count.""" + setattr(namespace, attr, namespace.jobs * 5) + + @scan.bind_delayed_default(1000, 'filter') def _default_filter(namespace, attr): """Use source filtering for keywords requesting it by default.""" |