Skip to content

Commit

Permalink
Add --no-index flag to pip-compile (#1745)
Browse files Browse the repository at this point in the history
Co-authored-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
atugushev and ssbarnea authored Dec 11, 2022
1 parent faa37dd commit 9aed54f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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

0 comments on commit 9aed54f

Please sign in to comment.