Skip to content

Commit

Permalink
Merge pull request #1954 from jazzband/always-strip-extras-warning
Browse files Browse the repository at this point in the history
* Warn about strip extras by default
* Use stdout as an output in test_compile_recursive_extras

---------

Co-authored-by: Albert Tugushev <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2023
2 parents d1e9215 + adfd994 commit b6193fd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 12 additions & 3 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -367,7 +367,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, ...],
Expand Down Expand Up @@ -678,6 +678,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 "
"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."
)

##
# Output
##
Expand Down
36 changes: 34 additions & 2 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2950,20 +2950,22 @@ 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[footest] @ {tmp_path.as_uri()}
small-fake-a==0.2
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):
Expand Down Expand Up @@ -3115,3 +3117,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

0 comments on commit b6193fd

Please sign in to comment.