Skip to content

Commit b6193fd

Browse files
ryanhiebertatugushevwebknjaz
authored
Merge pull request #1954 from jazzband/always-strip-extras-warning
* Warn about strip extras by default * Use stdout as an output in test_compile_recursive_extras --------- Co-authored-by: Albert Tugushev <albert@tugushev.ru> Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
2 parents d1e9215 + adfd994 commit b6193fd

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,12 @@ This section lists `pip-tools` features that are currently deprecated.
564564
- In the next major release, the `--allow-unsafe` behavior will be enabled by
565565
default (https://github.com/jazzband/pip-tools/issues/989).
566566
Use `--no-allow-unsafe` to keep the old behavior. It is recommended
567-
to pass the `--allow-unsafe` now to adapt to the upcoming change.
567+
to pass `--allow-unsafe` now to adapt to the upcoming change.
568568
- The legacy resolver is deprecated and will be removed in future versions.
569569
The new default is `--resolver=backtracking`.
570+
- In the next major release, the `--strip-extras` behavior will be enabled by
571+
default (https://github.com/jazzband/pip-tools/issues/1613).
572+
Use `--no-strip-extras` to keep the old behavior.
570573

571574
### A Note on Resolvers
572575

piptools/scripts/compile.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ def _determine_linesep(
226226
),
227227
)
228228
@click.option(
229-
"--strip-extras",
229+
"--strip-extras/--no-strip-extras",
230230
is_flag=True,
231-
default=False,
231+
default=None,
232232
help="Assure output file is constraints compatible, avoiding use of extras.",
233233
)
234234
@click.option(
@@ -367,7 +367,7 @@ def cli(
367367
output_file: LazyFile | IO[Any] | None,
368368
newline: str,
369369
allow_unsafe: bool,
370-
strip_extras: bool,
370+
strip_extras: bool | None,
371371
generate_hashes: bool,
372372
reuse_hashes: bool,
373373
src_files: tuple[str, ...],
@@ -678,6 +678,15 @@ def cli(
678678
strategy=newline, filenames=(output_file.name, *src_files)
679679
)
680680

681+
if strip_extras is None:
682+
strip_extras = False
683+
log.warning(
684+
"WARNING: --strip-extras is becoming the default "
685+
"in version 8.0.0. To silence this warning, "
686+
"either use --strip-extras to opt into the new default "
687+
"or use --no-strip-extras to retain the existing behavior."
688+
)
689+
681690
##
682691
# Output
683692
##

tests/test_cli_compile.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,20 +2950,22 @@ def test_compile_recursive_extras(runner, tmp_path, current_resolver):
29502950
[
29512951
"--no-header",
29522952
"--no-annotate",
2953-
"--no-emit-find-links",
2953+
"--no-emit-options",
29542954
"--extra",
29552955
"dev",
29562956
"--find-links",
29572957
os.fspath(MINIMAL_WHEELS_PATH),
29582958
os.fspath(tmp_path / "pyproject.toml"),
2959+
"--output-file",
2960+
"-",
29592961
],
29602962
)
29612963
expected = rf"""foo[footest] @ {tmp_path.as_uri()}
29622964
small-fake-a==0.2
29632965
small-fake-b==0.3
29642966
"""
29652967
assert out.exit_code == 0
2966-
assert expected == out.stderr
2968+
assert expected == out.stdout
29672969

29682970

29692971
def test_config_option(pip_conf, runner, tmp_path, make_config_file):
@@ -3115,3 +3117,33 @@ def test_invalid_cli_boolean_flag_config_option_captured(
31153117

31163118
assert out.exit_code == 2
31173119
assert "No such config key 'no_annnotate'." in out.stderr
3120+
3121+
3122+
strip_extras_warning = (
3123+
"WARNING: --strip-extras is becoming the default in version 8.0.0."
3124+
)
3125+
3126+
3127+
def test_show_warning_on_default_strip_extras_option(
3128+
runner, make_package, make_sdist, tmp_path
3129+
):
3130+
req_in = tmp_path / "requirements.in"
3131+
req_in.touch()
3132+
3133+
out = runner.invoke(cli, req_in.as_posix())
3134+
3135+
assert out.exit_code == 0
3136+
assert strip_extras_warning in out.stderr
3137+
3138+
3139+
@pytest.mark.parametrize("option", ("--strip-extras", "--no-strip-extras"))
3140+
def test_do_not_show_warning_on_explicit_strip_extras_option(
3141+
runner, make_package, make_sdist, tmp_path, option
3142+
):
3143+
req_in = tmp_path / "requirements.in"
3144+
req_in.touch()
3145+
3146+
out = runner.invoke(cli, [option, req_in.as_posix()])
3147+
3148+
assert out.exit_code == 0
3149+
assert strip_extras_warning not in out.stderr

0 commit comments

Comments
 (0)