From 72e84afab960c91bc2f551dc54575d3a0db677f5 Mon Sep 17 00:00:00 2001 From: Svenn-Arne Dragly Date: Mon, 4 Sep 2023 19:44:25 +0200 Subject: [PATCH] Move check for --extra and --all-extras outside loop Previously, an error would always be thrown when running `compile` with `--all-extras` on multiple source files containing extras. The reason was that the first iteration over the first source file would fill the `extras` variable, which in the second iteration would trigger an error since both `all_extras` and `extras` would be set. This change moves the check outside the loop and early in the script to avoid unnecessary processing before throwing the error. --- piptools/scripts/compile.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 1e47b8a69..ab04528ff 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -174,6 +174,10 @@ def cli( ).format(", ".join(DEFAULT_REQUIREMENTS_FILES)) ) + if all_extras and extras: + msg = "--extra has no effect when used with --all-extras" + raise click.BadParameter(msg) + if not output_file: # An output file must be provided for stdin if src_files == ("-",): @@ -336,10 +340,7 @@ def cli( ) if all_extras: - if extras: - msg = "--extra has no effect when used with --all-extras" - raise click.BadParameter(msg) - extras = tuple(metadata.get_all("Provides-Extra")) + extras += tuple(metadata.get_all("Provides-Extra")) else: constraints.extend( parse_requirements(