Allow dependency metadata entries for direct URL requirements (#7846)
## Summary This is part of making https://github.com/astral-sh/uv/issues/7299#issuecomment-2385286341 better. You can now use `tool.uv.dependency-metadata` for direct URL requirements. Unfortunately, you _must_ include a version, since we need one to perform resolution.
This commit is contained in:
@@ -38,6 +38,50 @@ impl GitResolver {
|
||||
self.0.get(reference)
|
||||
}
|
||||
|
||||
/// Resolve a Git URL to a specific commit.
|
||||
pub async fn resolve(
|
||||
&self,
|
||||
url: &GitUrl,
|
||||
client: ClientWithMiddleware,
|
||||
cache: PathBuf,
|
||||
reporter: Option<impl Reporter + 'static>,
|
||||
) -> Result<GitSha, GitResolverError> {
|
||||
debug!("Resolving source distribution from Git: {url}");
|
||||
|
||||
let reference = RepositoryReference::from(url);
|
||||
|
||||
// If we know the precise commit already, return it.
|
||||
if let Some(precise) = self.get(&reference) {
|
||||
return Ok(*precise);
|
||||
}
|
||||
|
||||
// Avoid races between different processes, too.
|
||||
let lock_dir = cache.join("locks");
|
||||
fs::create_dir_all(&lock_dir).await?;
|
||||
let repository_url = RepositoryUrl::new(url.repository());
|
||||
let _lock = LockedFile::acquire(
|
||||
lock_dir.join(cache_digest(&repository_url)),
|
||||
&repository_url,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Fetch the Git repository.
|
||||
let source = if let Some(reporter) = reporter {
|
||||
GitSource::new(url.clone(), client, cache).with_reporter(reporter)
|
||||
} else {
|
||||
GitSource::new(url.clone(), client, cache)
|
||||
};
|
||||
let precise = tokio::task::spawn_blocking(move || source.resolve())
|
||||
.await?
|
||||
.map_err(GitResolverError::Git)?;
|
||||
|
||||
// Insert the resolved URL into the in-memory cache. This ensures that subsequent fetches
|
||||
// resolve to the same precise commit.
|
||||
self.insert(reference, precise);
|
||||
|
||||
Ok(precise)
|
||||
}
|
||||
|
||||
/// Fetch a remote Git repository.
|
||||
pub async fn fetch(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user