Skip to content

Commit

Permalink
Write default index in --extra-index-url (#1325)
Browse files Browse the repository at this point in the history
If the default index is provided as `--extra-index-url` it can not
safely be dropped from the written output since this changes behavior
when the output is synced.

While #756 Explicitly introduced tests for the
opposite this seems to have been a mistake since otherwise the following
lines comment about making an exception would be nonsensical.
  • Loading branch information
fahrradflucht committed Feb 23, 2021
1 parent a5e257e commit 2be5cbf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion piptools/writer.py
Expand Up @@ -103,7 +103,7 @@ def write_header(self) -> Iterator[str]:
def write_index_options(self) -> Iterator[str]:
if self.emit_index_url:
for index, index_url in enumerate(dedup(self.index_urls)):
if index_url.rstrip("/") == self.default_index_url:
if index == 0 and index_url.rstrip("/") == self.default_index_url:
continue
flag = "--index-url" if index == 0 else "--extra-index-url"
yield f"{flag} {index_url}"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_writer.py
Expand Up @@ -276,7 +276,7 @@ def test_write_format_controls(writer):
"--extra-index-url https://index-url2.com",
],
),
# Ignore URLs equal to the default index-url
# Not ignore URLs equal to the default index-url
# (note: the previous case is exception)
(
[
Expand All @@ -286,6 +286,7 @@ def test_write_format_controls(writer):
],
[
"--index-url https://index-url1.com",
"--extra-index-url https://default-index-url.com",
"--extra-index-url https://index-url2.com",
],
),
Expand Down

0 comments on commit 2be5cbf

Please sign in to comment.