From f1304aa41031c0eb96d7174de40148dcf500a3c7 Mon Sep 17 00:00:00 2001 From: Ryan Hiebert Date: Sun, 6 Aug 2023 14:33:08 +0000 Subject: [PATCH 1/4] Warn about strip extras by default --- README.md | 5 ++++- piptools/scripts/compile.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 60503afe6..a04e02eed 100644 --- a/README.md +++ b/README.md @@ -564,9 +564,12 @@ This section lists `pip-tools` features that are currently deprecated. - In the next major release, the `--allow-unsafe` behavior will be enabled by default (https://github.com/jazzband/pip-tools/issues/989). Use `--no-allow-unsafe` to keep the old behavior. It is recommended - to pass the `--allow-unsafe` now to adapt to the upcoming change. + to pass `--allow-unsafe` now to adapt to the upcoming change. - The legacy resolver is deprecated and will be removed in future versions. The new default is `--resolver=backtracking`. +- In the next major release, the `--strip-extras` behavior will be enabled by + default (https://github.com/jazzband/pip-tools/issues/1613). + Use `--no-strip-extras` to keep the old behavior. ### A Note on Resolvers diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 697c45074..3fbdacde7 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -226,9 +226,9 @@ def _determine_linesep( ), ) @click.option( - "--strip-extras", + "--strip-extras/--no-strip-extras", is_flag=True, - default=False, + default=None, help="Assure output file is constraints compatible, avoiding use of extras.", ) @click.option( @@ -365,7 +365,7 @@ def cli( output_file: LazyFile | IO[Any] | None, newline: str, allow_unsafe: bool, - strip_extras: bool, + strip_extras: bool | None, generate_hashes: bool, reuse_hashes: bool, src_files: tuple[str, ...], @@ -676,6 +676,15 @@ def cli( strategy=newline, filenames=(output_file.name, *src_files) ) + if strip_extras is None: + strip_extras = False + log.warning( + "WARNING: --strip-extras is becoming the default. " + "To silence this warning, " + "either use --strip-extras to opt into the new default " + "or use --no-strip-extras to retain the existing behavior." + ) + ## # Output ## From d4074d1f36f8552ff248ed4134749da7452d1541 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Sun, 6 Aug 2023 20:47:49 +0200 Subject: [PATCH 2/4] Use stdout as an output in test_compile_recursive_extras --- tests/test_cli_compile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index ac75927ea..534894395 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -2947,12 +2947,14 @@ def test_compile_recursive_extras(runner, tmp_path, current_resolver): [ "--no-header", "--no-annotate", - "--no-emit-find-links", + "--no-emit-options", "--extra", "dev", "--find-links", os.fspath(MINIMAL_WHEELS_PATH), os.fspath(tmp_path / "pyproject.toml"), + "--output-file", + "-", ], ) expected = rf"""foo @ {tmp_path.as_uri()} @@ -2960,7 +2962,7 @@ def test_compile_recursive_extras(runner, tmp_path, current_resolver): small-fake-b==0.3 """ assert out.exit_code == 0 - assert expected == out.stderr + assert expected == out.stdout def test_config_option(pip_conf, runner, tmp_path, make_config_file): From c5b447d5539fe2a71dabb1282c915ba717e79f09 Mon Sep 17 00:00:00 2001 From: Ryan Hiebert Date: Sun, 6 Aug 2023 23:35:10 +0000 Subject: [PATCH 3/4] Add version to warning --- piptools/scripts/compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 3fbdacde7..0afebf61d 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -679,8 +679,8 @@ def cli( if strip_extras is None: strip_extras = False log.warning( - "WARNING: --strip-extras is becoming the default. " - "To silence this warning, " + "WARNING: --strip-extras is becoming the default " + "in version 8.0.0. To silence this warning, " "either use --strip-extras to opt into the new default " "or use --no-strip-extras to retain the existing behavior." ) From 9c5853033b6d9bad69b5eb7f0f2203fdf4fa17c0 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Tue, 8 Aug 2023 20:57:38 +0200 Subject: [PATCH 4/4] Add tests --- tests/test_cli_compile.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 534894395..6b7e9eb3b 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3102,3 +3102,33 @@ def test_invalid_cli_boolean_flag_config_option_captured( assert out.exit_code == 2 assert "No such config key 'no_annnotate'." in out.stderr + + +strip_extras_warning = ( + "WARNING: --strip-extras is becoming the default in version 8.0.0." +) + + +def test_show_warning_on_default_strip_extras_option( + runner, make_package, make_sdist, tmp_path +): + req_in = tmp_path / "requirements.in" + req_in.touch() + + out = runner.invoke(cli, req_in.as_posix()) + + assert out.exit_code == 0 + assert strip_extras_warning in out.stderr + + +@pytest.mark.parametrize("option", ("--strip-extras", "--no-strip-extras")) +def test_do_not_show_warning_on_explicit_strip_extras_option( + runner, make_package, make_sdist, tmp_path, option +): + req_in = tmp_path / "requirements.in" + req_in.touch() + + out = runner.invoke(cli, [option, req_in.as_posix()]) + + assert out.exit_code == 0 + assert strip_extras_warning not in out.stderr