Skip to content

Commit

Permalink
Properly filter out superfluous inverse flags in pip-compile output h…
Browse files Browse the repository at this point in the history
…eader

Fixes: jazzband#2065
See: jazzband#1197

This is specifically for the --no-reuse-hashes found in
COMPILE_EXCLUDE_OPTIONS but makes way for future inverse flags in the
list too.
  • Loading branch information
mjsir911 committed Mar 5, 2024
1 parent 1197151 commit 7a3e028
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion piptools/utils.py
Expand Up @@ -371,9 +371,13 @@ def get_compile_command(click_ctx: click.Context) -> str:
# Get the latest option name (usually it'll be a long name)
option_long_name = option.opts[-1]

negative_option = None
if option.is_flag and option.secondary_opts:
negative_option = option.secondary_opts[-1] # get inverse flag --no-{option_long_name}

# Exclude one-off options (--upgrade/--upgrade-package/--rebuild/...)
# or options that don't change compile behaviour (--verbose/--dry-run/...)
if option_long_name in COMPILE_EXCLUDE_OPTIONS:
if {option_long_name, negative_option} & COMPILE_EXCLUDE_OPTIONS:
continue

# Exclude config option if it's the default one
Expand Down
2 changes: 2 additions & 0 deletions tests/test_utils.py
Expand Up @@ -374,6 +374,8 @@ def test_is_url_requirement_filename(caplog, from_line, line):
(["--upgrade"], "pip-compile"),
(["-P", "django"], "pip-compile"),
(["--upgrade-package", "django"], "pip-compile"),
(["--reuse-hashes"], "pip-compile"),
(["--no-reuse-hashes"], "pip-compile"),
# Check options
(["--max-rounds", "42"], "pip-compile --max-rounds=42"),
(["--index-url", "https://foo"], "pip-compile --index-url=https://foo"),
Expand Down

0 comments on commit 7a3e028

Please sign in to comment.