From 3726840e4199f2132274599490e67151f61920d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Such=C3=BD?= Date: Sat, 18 Jan 2025 14:36:37 +0100 Subject: [PATCH] change default value of --process to (number of CPUs)-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related: #2980 Signed-off-by: Miroslav Suchý --- CHANGELOG.rst | 4 ++++ docs/source/cli-reference/help-text-options.rst | 2 +- docs/source/rst_snippets/core_options.rst | 2 +- src/scancode/cli.py | 11 +++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2a1f48480bb..a3437404d13 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -30,6 +30,10 @@ v33.0.0 (next next, roadmap) license detection and reduce false positives. See https://github.com/nexB/scancode-toolkit/issues/3300 +- default value for `--processes` was previously 1. It was changed + to (number of CPUs)-1. + See https://github.com/aboutcode-org/scancode-toolkit/issues/2980 + - File categorization support added, a post scan plugin tagging files with priority levels for review, and also take advantage of these in other summary plugins. diff --git a/docs/source/cli-reference/help-text-options.rst b/docs/source/cli-reference/help-text-options.rst index 5e7a7694601..58f0fe2e88a 100644 --- a/docs/source/cli-reference/help-text-options.rst +++ b/docs/source/cli-reference/help-text-options.rst @@ -165,7 +165,7 @@ The Following Help Text is displayed, i.e. This is the help text for Scancode Ve seconds. [default: 120 seconds] -n, --processes INT Set the number of parallel processes to use. Disable parallel processing if 0. Also disable threading if - -1. [default: 1] + -1. [default: (number of CPUs)-1] -q, --quiet Do not print summary or progress. -v, --verbose Print progress as file-by-file path instead of a progress bar. Print verbose scan counters. diff --git a/docs/source/rst_snippets/core_options.rst b/docs/source/rst_snippets/core_options.rst index 277e9570d1e..453763ca57d 100644 --- a/docs/source/rst_snippets/core_options.rst +++ b/docs/source/rst_snippets/core_options.rst @@ -2,7 +2,7 @@ All "Core" Scan Options ----------------------- -n, --processes INTEGER Scan ```` using n parallel processes. - [Default: 1] + [Default: (number of CPUs)-1] -v, --verbose Print verbose file-by-file progress messages. diff --git a/src/scancode/cli.py b/src/scancode/cli.py index add654f2ec4..9369fe7d91c 100644 --- a/src/scancode/cli.py +++ b/src/scancode/cli.py @@ -201,6 +201,13 @@ def validate_input_path(ctx, param, value): return value +def default_processes(): + """ return number that is used as a default value for --processes """ + cpu_count = os.cpu_count() + if cpu_count > 1: + return cpu_count-1 + else: + return 1 @click.command(name='scancode', epilog=epilog_text, @@ -230,10 +237,10 @@ def validate_input_path(ctx, param, value): @click.option('-n', '--processes', type=int, - default=1, + default=default_processes(), metavar='INT', help='Set the number of parallel processes to use. ' - 'Disable parallel processing if 0. Also disable threading if -1. [default: 1]', + 'Disable parallel processing if 0. Also disable threading if -1. [default: (number of CPUs)-1]', help_group=cliutils.CORE_GROUP, sort_order=10, cls=PluggableCommandLineOption) @click.option('--timeout',