From f0dde62f9cf5db4d9b8ab296d477e8ef52f30ec2 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Tue, 22 Nov 2022 19:18:28 +0100 Subject: [PATCH] Add `--no-index` flag to `pip-compile` --- piptools/scripts/compile.py | 19 +++++++++++++++---- tests/test_cli_compile.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 8438e7f55..82334bcb3 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -126,6 +126,11 @@ def _determine_linesep( index_url=redact_auth_from_url(_get_default_option("index_url")) ), ) +@click.option( + "--no-index", + is_flag=True, + help="Ignore package index (only looking at --find-links URLs instead).", +) @click.option( "--extra-index-url", multiple=True, @@ -302,6 +307,7 @@ def cli( all_extras: bool, find_links: tuple[str, ...], index_url: str, + no_index: bool, extra_index_url: tuple[str, ...], cert: str | None, client_cert: str | None, @@ -392,6 +398,8 @@ def cli( pip_args.extend(["-f", link]) if index_url: pip_args.extend(["-i", index_url]) + if no_index: + pip_args.extend(["--no-index"]) for extra_index in extra_index_url: pip_args.extend(["--extra-index-url", extra_index]) if cert: @@ -526,10 +534,13 @@ def cli( for req in constraints: drop_extras(req) - log.debug("Using indexes:") - with log.indentation(): - for index_url in dedup(repository.finder.index_urls): - log.debug(redact_auth_from_url(index_url)) + if repository.finder.index_urls: + log.debug("Using indexes:") + with log.indentation(): + for index_url in dedup(repository.finder.index_urls): + log.debug(redact_auth_from_url(index_url)) + else: + log.debug("Ignoring indexes.") if repository.finder.find_links: log.debug("") diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 69185354b..e5dfcd171 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -220,6 +220,16 @@ def test_setuptools_preserves_environment_markers( assert out.stdout == 'foo==1.0 ; python_version >= "1"\n' +def test_no_index_option(runner, tmp_path): + req_in = tmp_path / "requirements.in" + req_in.touch() + + out = runner.invoke(cli, [req_in.as_posix(), "--no-index", "--verbose"]) + + assert out.exit_code == 0 + assert "Ignoring indexes." in out.stderr + + def test_find_links_option(runner): with open("requirements.in", "w") as req_in: req_in.write("-f ./libs3")