Skip to content

Commit

Permalink
Move check for --extra and --all-extras outside loop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dragly committed Sep 4, 2023
1 parent 6ebcaff commit 72e84af
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ("-",):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 72e84af

Please sign in to comment.