diff --git a/crates/distribution-types/src/index_url.rs b/crates/distribution-types/src/index_url.rs index b625b2ec2..a61458fef 100644 --- a/crates/distribution-types/src/index_url.rs +++ b/crates/distribution-types/src/index_url.rs @@ -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 + 'a { self.index.iter().chain(self.extra_index.iter()) } + /// Return an iterator over the [`FlatIndexLocation`] entries. pub fn flat_indexes(&'a self) -> impl Iterator + '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 + '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() } diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index 02b741f51..c7f20e646 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -252,7 +252,8 @@ struct PipSyncArgs { #[clap(long)] find_links: Vec, - /// 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, diff --git a/crates/puffin-cli/tests/pip_compile.rs b/crates/puffin-cli/tests/pip_compile.rs index 17acab63f..295aec0f1 100644 --- a/crates/puffin-cli/tests/pip_compile.rs +++ b/crates/puffin-cli/tests/pip_compile.rs @@ -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 ----- diff --git a/crates/puffin-client/src/registry_client.rs b/crates/puffin-client/src/registry_client.rs index bd94da469..ad0360376 100644 --- a/crates/puffin-client/src/registry_client.rs +++ b/crates/puffin-client/src/registry_client.rs @@ -265,10 +265,6 @@ impl RegistryClient { file: &File, url: &Url, ) -> Result { - 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 { - 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, Error> { - if self.index_urls.no_index() { - return Err(Error::NoIndex(url.to_string())); - } - Ok(Box::new( self.client .uncached() diff --git a/crates/puffin-resolver/src/resolver/provider.rs b/crates/puffin-resolver/src/resolver/provider.rs index 75f95913e..caacbabbd 100644 --- a/crates/puffin-resolver/src/resolver/provider.rs +++ b/crates/puffin-resolver/src/resolver/provider.rs @@ -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 {