This commit is contained in:
Charlie Marsh 2025-11-11 21:19:41 -05:00
parent f2513e4f8f
commit 4e25397b04
4 changed files with 8 additions and 60 deletions

View File

@ -704,10 +704,7 @@ impl RegistryClient {
pub async fn fetch_simple_index( pub async fn fetch_simple_index(
&self, &self,
index_url: &IndexUrl, index_url: &IndexUrl,
download_concurrency: &Semaphore,
) -> Result<SimpleIndexMetadata, Error> { ) -> Result<SimpleIndexMetadata, Error> {
let _permit = download_concurrency.acquire().await;
// Format the URL for PyPI. // Format the URL for PyPI.
let mut url = index_url.url().clone(); let mut url = index_url.url().clone();
url.path_segments_mut() url.path_segments_mut()
@ -1309,10 +1306,15 @@ pub struct VersionSourceDist {
#[rkyv(derive(Debug))] #[rkyv(derive(Debug))]
pub struct SimpleIndexMetadata { pub struct SimpleIndexMetadata {
/// The list of project names available in the index. /// The list of project names available in the index.
pub projects: Vec<PackageName>, projects: Vec<PackageName>,
} }
impl SimpleIndexMetadata { impl SimpleIndexMetadata {
/// Iterate over the projects in the index.
pub fn iter(&self) -> impl Iterator<Item = &PackageName> {
self.projects.iter()
}
/// Create a [`SimpleIndexMetadata`] from a [`PypiSimpleIndex`]. /// Create a [`SimpleIndexMetadata`] from a [`PypiSimpleIndex`].
fn from_pypi_index(index: PypiSimpleIndex) -> Self { fn from_pypi_index(index: PypiSimpleIndex) -> Self {
Self { Self {

View File

@ -1,7 +1,6 @@
use anstream::println; use anstream::println;
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Parser;
use tokio::sync::Semaphore;
use uv_cache::{Cache, CacheArgs}; use uv_cache::{Cache, CacheArgs};
use uv_client::{BaseClientBuilder, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, RegistryClientBuilder};
@ -28,10 +27,9 @@ pub(crate) async fn list_packages(
.build(); .build();
let index_url = IndexUrl::parse(&args.url, None)?; let index_url = IndexUrl::parse(&args.url, None)?;
let concurrency = Semaphore::new(Semaphore::MAX_PERMITS); let index = client.fetch_simple_index(&index_url).await?;
let index = client.fetch_simple_index(&index_url, &concurrency).await?;
for package_name in &index.projects { for package_name in index.iter() {
println!("{}", package_name); println!("{}", package_name);
} }

View File

@ -1536,8 +1536,6 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
return Err(Error::HashesNotSupportedGit(source.to_string())); return Err(Error::HashesNotSupportedGit(source.to_string()));
} }
// STOPSHIP(charlie): Here, we can fetch the pre-built wheel.
// Fetch the Git repository. // Fetch the Git repository.
let fetch = self let fetch = self
.build_context .build_context

View File

@ -1,50 +0,0 @@
from hashlib import blake2b
from os import fspath
from typing import Optional, Union
Pathish = Union[str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"]
def git_cache_digest(repository: str, precise: str, subdirectory: Optional[Pathish] = None) -> str:
"""
Reproduces the Rust digest() exactly:
- blake2b with 32-byte (256-bit) digest
- bytes fed in this order:
repository + "/" + precise [+ "?subdirectory=" + subdirectory]
- subdirectory is included only if it is representable as UTF-8
(mirrors Rust Path::to_str() -> Option<&str>)
- hex output is lowercase
"""
h = blake2b(digest_size=32)
# repository and precise are Rust &str equivalents: encode as UTF-8
h.update(repository.encode("utf-8"))
h.update(b"/")
h.update(precise.encode("utf-8"))
if subdirectory is not None:
# Normalize to either str or bytes using fspath (handles PathLike)
p = fspath(subdirectory)
# Try to get a UTF-8 string like Path::to_str()
if isinstance(p, bytes):
try:
p_str = p.decode("utf-8")
except UnicodeDecodeError:
p_str = None
else:
# Already a str
p_str = p
if p_str is not None:
h.update(b"?subdirectory=")
h.update(p_str.encode("utf-8"))
return h.hexdigest()
digest = git_cache_digest(
repository="https://github.com/agronholm/anyio",
precise="64b753b19c9a49e3ae395cde457cf82d51f7e999",
subdirectory=None
)
print(digest) # lowercase hex, identical to the Rust version