From ed0e64cf59493f3f54a792db99880d07a7ebec22 Mon Sep 17 00:00:00 2001 From: Marco Sirabella Date: Mon, 4 Mar 2024 17:17:53 -0800 Subject: [PATCH] Properly filter out specified inverse flags in output header Fixes: #2065 See: #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. --- piptools/utils.py | 7 ++++++- tests/test_utils.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/piptools/utils.py b/piptools/utils.py index 3b2061f7..667c3880 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -371,9 +371,14 @@ 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: + # get inverse flag --no-{option_long_name} + negative_option = option.secondary_opts[-1] + # 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 diff --git a/tests/test_utils.py b/tests/test_utils.py index edf012aa..3f47dfca 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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"),