mirror of https://github.com/astral-sh/uv
Continue to respect `--find-links` with `--no-index` (#931)
Like `pip`, we should allow `--find-links` with `--no-index`.
This commit is contained in:
parent
42888a9609
commit
e54fdea93f
|
|
@ -137,11 +137,10 @@ impl IndexLocations {
|
|||
no_index: bool,
|
||||
) -> Self {
|
||||
if no_index {
|
||||
// TODO(charlie): Warn if the user passes in arguments here alongside `--no-index`.
|
||||
Self {
|
||||
index: None,
|
||||
extra_index: Vec::new(),
|
||||
flat_index: Vec::new(),
|
||||
flat_index,
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
|
|
@ -154,14 +153,17 @@ impl IndexLocations {
|
|||
}
|
||||
|
||||
impl<'a> IndexLocations {
|
||||
/// Return an iterator over the [`IndexUrl`] entries.
|
||||
pub fn indexes(&'a self) -> impl Iterator<Item = &'a IndexUrl> + 'a {
|
||||
self.index.iter().chain(self.extra_index.iter())
|
||||
}
|
||||
|
||||
/// Return an iterator over the [`FlatIndexLocation`] entries.
|
||||
pub fn flat_indexes(&'a self) -> impl Iterator<Item = &'a FlatIndexLocation> + 'a {
|
||||
self.flat_index.iter()
|
||||
}
|
||||
|
||||
/// Clone the index locations into a [`IndexUrls`] instance.
|
||||
pub fn index_urls(&'a self) -> IndexUrls {
|
||||
IndexUrls {
|
||||
index: self.index.clone(),
|
||||
|
|
@ -190,10 +192,12 @@ impl Default for IndexUrls {
|
|||
}
|
||||
|
||||
impl<'a> IndexUrls {
|
||||
/// Return an iterator over the [`IndexUrl`] entries.
|
||||
pub fn indexes(&'a self) -> impl Iterator<Item = &'a IndexUrl> + 'a {
|
||||
self.index.iter().chain(self.extra_index.iter())
|
||||
}
|
||||
|
||||
/// Return `true` if no index is configured.
|
||||
pub fn no_index(&self) -> bool {
|
||||
self.index.is_none() && self.extra_index.is_empty()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,7 +252,8 @@ struct PipSyncArgs {
|
|||
#[clap(long)]
|
||||
find_links: Vec<FlatIndexLocation>,
|
||||
|
||||
/// Ignore the package index, instead relying on local archives and caches.
|
||||
/// Ignore the registry index (e.g., PyPI), instead relying on local caches and `--find-links`
|
||||
/// directories and URLs.
|
||||
#[clap(long, conflicts_with = "index_url", conflicts_with = "extra_index_url")]
|
||||
no_index: bool,
|
||||
|
||||
|
|
|
|||
|
|
@ -3089,8 +3089,7 @@ fn find_links_directory() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Compile using `--find-links` with a URL by resolving `tqdm` from the `PyTorch` wheels index,
|
||||
/// and pointing `--index-url` to the test `PyPI` (which doesn't have `tqdm`).
|
||||
/// Compile using `--find-links` with a URL by resolving `tqdm` from the `PyTorch` wheels index.
|
||||
#[test]
|
||||
fn find_links_url() -> Result<()> {
|
||||
let temp_dir = TempDir::new()?;
|
||||
|
|
@ -3106,8 +3105,7 @@ fn find_links_url() -> Result<()> {
|
|||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.arg("pip-compile")
|
||||
.arg("requirements.in")
|
||||
.arg("--index-url")
|
||||
.arg("https://test.pypi.org/simple")
|
||||
.arg("--no-index")
|
||||
.arg("--find-links")
|
||||
.arg("https://download.pytorch.org/whl/torch_stable.html")
|
||||
.arg("--cache-dir")
|
||||
|
|
@ -3120,7 +3118,7 @@ fn find_links_url() -> Result<()> {
|
|||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by Puffin v0.0.1 via the following command:
|
||||
# puffin pip-compile requirements.in --index-url https://test.pypi.org/simple --find-links https://download.pytorch.org/whl/torch_stable.html --cache-dir [CACHE_DIR]
|
||||
# puffin pip-compile requirements.in --no-index --find-links https://download.pytorch.org/whl/torch_stable.html --cache-dir [CACHE_DIR]
|
||||
tqdm==4.64.1
|
||||
|
||||
----- stderr -----
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@ impl RegistryClient {
|
|||
file: &File,
|
||||
url: &Url,
|
||||
) -> Result<Metadata21, Error> {
|
||||
if self.index_urls.no_index() {
|
||||
return Err(Error::NoIndex(file.filename.clone()));
|
||||
}
|
||||
|
||||
// If the metadata file is available at its own url (PEP 658), download it from there.
|
||||
let filename = WheelFilename::from_str(&file.filename)?;
|
||||
if file
|
||||
|
|
@ -314,10 +310,6 @@ impl RegistryClient {
|
|||
url: &'data Url,
|
||||
cache_shard: WheelCache<'data>,
|
||||
) -> Result<Metadata21, Error> {
|
||||
if self.index_urls.no_index() {
|
||||
return Err(Error::NoIndex(url.to_string()));
|
||||
}
|
||||
|
||||
let cache_entry = self.cache.entry(
|
||||
CacheBucket::Wheels,
|
||||
cache_shard.remote_wheel_dir(filename.name.as_ref()),
|
||||
|
|
@ -380,10 +372,6 @@ impl RegistryClient {
|
|||
&self,
|
||||
url: &Url,
|
||||
) -> Result<Box<dyn futures::AsyncRead + Unpin + Send + Sync>, Error> {
|
||||
if self.index_urls.no_index() {
|
||||
return Err(Error::NoIndex(url.to_string()));
|
||||
}
|
||||
|
||||
Ok(Box::new(
|
||||
self.client
|
||||
.uncached()
|
||||
|
|
|
|||
|
|
@ -100,7 +100,10 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
|
|||
self.exclude_newer.as_ref(),
|
||||
self.flat_index.get(package_name).cloned(),
|
||||
)),
|
||||
Err(err @ puffin_client::Error::PackageNotFound(_)) => {
|
||||
Err(
|
||||
err @ (puffin_client::Error::PackageNotFound(_)
|
||||
| puffin_client::Error::NoIndex(_)),
|
||||
) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionMap::from(flat_index))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue