Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-strip-extras and warn about strip extras by default #1954

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
)
atugushev marked this conversation as resolved.
Show resolved Hide resolved

##
# 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