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-index flag to pip-compile #1745

Merged
merged 4 commits into from
Dec 11, 2022
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
19 changes: 15 additions & 4 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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("")
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down