Avoid writing duplicate index URLs with --emit-index-url (#8226)

closes #8116

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
Aditya Pratap Singh 2024-10-16 18:15:25 +05:30 committed by GitHub
parent 0c445eb11d
commit 0bd6e46bcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View file

@ -4,6 +4,7 @@ use std::path::Path;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use itertools::Itertools; use itertools::Itertools;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use rustc_hash::FxHashSet;
use tracing::debug; use tracing::debug;
use uv_cache::Cache; use uv_cache::Cache;
@ -466,9 +467,12 @@ pub(crate) async fn pip_compile(
writeln!(writer, "--index-url {}", index.url().verbatim())?; writeln!(writer, "--index-url {}", index.url().verbatim())?;
wrote_preamble = true; wrote_preamble = true;
} }
let mut seen = FxHashSet::default();
for extra_index in index_locations.implicit_indexes() { for extra_index in index_locations.implicit_indexes() {
writeln!(writer, "--extra-index-url {}", extra_index.url().verbatim())?; if seen.insert(extra_index.url()) {
wrote_preamble = true; writeln!(writer, "--extra-index-url {}", extra_index.url().verbatim())?;
wrote_preamble = true;
}
} }
} }

View file

@ -5263,7 +5263,8 @@ fn emit_index_urls() -> Result<()> {
.arg("--index-url") .arg("--index-url")
.arg("https://test.pypi.org/simple/") .arg("https://test.pypi.org/simple/")
.arg("--extra-index-url") .arg("--extra-index-url")
.arg("https://pypi.org/simple"), @r###" .arg("https://pypi.org/simple")
.env("UV_EXTRA_INDEX_URL", "https://pypi.org/simple"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----