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

Remove deprecated "--index/--no-index" option from compile command #1234

Merged
merged 2 commits into from Mar 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.rst
Expand Up @@ -472,9 +472,6 @@ Deprecations

This section lists ``pip-tools`` features that are currently deprecated.

- ``--index/--no-index`` command-line options, use instead
``--emit-index-url/--no-emit-index-url`` (since 5.2.0).

- In future versions, the ``--allow-unsafe`` behavior will be enabled by
default. Use ``--no-allow-unsafe`` to keep the old behavior. It is
recommended to pass the ``--allow-unsafe`` now to adapt to the upcoming
Expand Down
47 changes: 1 addition & 46 deletions piptools/scripts/compile.py
Expand Up @@ -2,11 +2,9 @@
import shlex
import sys
import tempfile
import warnings
from typing import Any

import click
from click import Command
from click.utils import safecall
from pip._internal.commands import create_command
from pip._internal.req.constructors import install_req_from_line
Expand Down Expand Up @@ -36,30 +34,7 @@ def _get_default_option(option_name: str) -> Any:
return getattr(default_values, option_name)


class BaseCommand(Command):
_os_args = None

def parse_args(self, ctx, args):
"""
Override base `parse_args` to store the argument part of `sys.argv`.
"""
self._os_args = set(args)
return super().parse_args(ctx, args)

def has_arg(self, arg_name):
"""
Detect whether a given arg name (including negative counterparts
to the arg, e.g. --no-arg) is present in the argument part of `sys.argv`.
"""
command_options = {option.name: option for option in self.params}
option = command_options[arg_name]
args = set(option.opts + option.secondary_opts)
return bool(self._os_args & args)


@click.command(
cls=BaseCommand, context_settings={"help_option_names": ("-h", "--help")}
)
@click.command(context_settings={"help_option_names": ("-h", "--help")})
@click.version_option()
@click.pass_context
@click.option("-v", "--verbose", count=True, help="Show more output")
Expand Down Expand Up @@ -117,12 +92,6 @@ def has_arg(self, arg_name):
default=True,
help="Add header to generated file",
)
@click.option(
"--index/--no-index",
is_flag=True,
default=True,
help="DEPRECATED: Add index URL to generated file",
)
@click.option(
"--emit-trusted-host/--no-emit-trusted-host",
is_flag=True,
Expand Down Expand Up @@ -237,7 +206,6 @@ def cli(
client_cert,
trusted_host,
header,
index,
emit_trusted_host,
annotate,
upgrade,
Expand Down Expand Up @@ -294,19 +262,6 @@ def cli(
# Close the file at the end of the context execution
ctx.call_on_close(safecall(output_file.close_intelligently))

if cli.has_arg("index") and cli.has_arg("emit_index_url"):
raise click.BadParameter(
"--index/--no-index and --emit-index-url/--no-emit-index-url "
"are mutually exclusive."
)
elif cli.has_arg("index"):
warnings.warn(
"--index and --no-index are deprecated and will be removed "
"in future versions. Use --emit-index-url/--no-emit-index-url instead.",
category=FutureWarning,
)
emit_index_url = index

###
# Setup
###
Expand Down
37 changes: 8 additions & 29 deletions tests/test_cli_compile.py
@@ -1,4 +1,3 @@
import itertools
import os
import subprocess
import sys
Expand Down Expand Up @@ -277,41 +276,23 @@ def test_all_no_emit_options(runner, options):
@pytest.mark.parametrize(
("option", "expected_output"),
(
pytest.param("--index", ["--index-url https://index-url"], id="index url"),
pytest.param("--no-index", [], id="no index"),
pytest.param(
"--emit-index-url", ["--index-url https://index-url"], id="index url"
),
pytest.param("--no-emit-index-url", [], id="no index"),
),
)
def test_index_option(runner, option, expected_output):
def test_emit_index_url_option(runner, option, expected_output):
with open("requirements.in", "w"):
pass

with pytest.warns(FutureWarning, match="--index and --no-index are deprecated"):
out = runner.invoke(
cli, ["--no-header", "--index-url", "https://index-url", option]
)
out = runner.invoke(
cli, ["--no-header", "--index-url", "https://index-url", option]
)

assert out.stderr.strip().splitlines() == expected_output


@pytest.mark.parametrize(
"options",
itertools.product(
("--index", "--no-index"), ("--emit-index-url", "--no-emit-index-url")
),
)
def test_mutual_exclusive_index_options(runner, options):
with open("requirements.in", "w"):
pass

out = runner.invoke(cli, options)

assert out.exit_code == 2
assert (
"--index/--no-index and --emit-index-url/--no-emit-index-url "
"are mutually exclusive"
) in out.stderr


@pytest.mark.network
def test_realistic_complex_sub_dependencies(runner):
wheels_dir = "wheels"
Expand Down Expand Up @@ -1264,8 +1245,6 @@ def test_upgrade_package_doesnt_remove_annotation(pip_conf, runner):
@pytest.mark.parametrize(
"options",
(
# TODO add --no-index support in OutputWriter
# "--no-index",
"--index-url https://example.com",
"--extra-index-url https://example.com",
"--find-links ./libs1",
Expand Down
2 changes: 0 additions & 2 deletions tests/test_utils.py
Expand Up @@ -239,15 +239,13 @@ def test_name_from_req_with_project_name(from_line):
(["--pre"], "pip-compile --pre"),
(["--allow-unsafe"], "pip-compile --allow-unsafe"),
# Check negative flags
(["--no-index"], "pip-compile --no-index"),
(["--no-emit-index-url"], "pip-compile --no-emit-index-url"),
(["--no-emit-trusted-host"], "pip-compile --no-emit-trusted-host"),
(["--no-annotate"], "pip-compile --no-annotate"),
(["--no-allow-unsafe"], "pip-compile"),
# Check that default values will be removed from the command
(["--emit-trusted-host"], "pip-compile"),
(["--annotate"], "pip-compile"),
(["--index"], "pip-compile"),
(["--emit-index-url"], "pip-compile"),
(["--max-rounds=10"], "pip-compile"),
(["--build-isolation"], "pip-compile"),
Expand Down