From be866a0b93d1ea58101c07b01b936df64a281b52 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 21 Nov 2020 05:53:19 -0800 Subject: [PATCH] Remove deprecated "--index/--no-index" option from compile command --- README.rst | 3 --- piptools/scripts/compile.py | 47 +------------------------------------ tests/test_cli_compile.py | 37 +++++++---------------------- tests/test_utils.py | 2 -- 4 files changed, 9 insertions(+), 80 deletions(-) diff --git a/README.rst b/README.rst index 5224cbc23..10d5d8538 100644 --- a/README.rst +++ b/README.rst @@ -469,9 +469,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 diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index d21f0dec9..6e4170590 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -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 @@ -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") @@ -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, @@ -237,7 +206,6 @@ def cli( client_cert, trusted_host, header, - index, emit_trusted_host, annotate, upgrade, @@ -292,19 +260,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 ### diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 12db0f422..56102936b 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -1,4 +1,3 @@ -import itertools import os import subprocess import sys @@ -256,41 +255,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" @@ -1243,8 +1224,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", diff --git a/tests/test_utils.py b/tests/test_utils.py index 398198f99..81141b408 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -237,7 +237,6 @@ 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"), @@ -245,7 +244,6 @@ def test_name_from_req_with_project_name(from_line): # 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"),