mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 02:40:11 +00:00
Rename to uv (#1302)
First, replace all usages in files in-place. I used my editor for this. If someone wants to add a one-liner that'd be fun. Then, update directory and file names: ``` # Run twice for nested directories find . -type d -print0 | xargs -0 rename s/puffin/uv/g find . -type d -print0 | xargs -0 rename s/puffin/uv/g # Update files find . -type f -print0 | xargs -0 rename s/puffin/uv/g ``` Then add all the files again ``` # Add all the files again git add crates git add python/uv # This one needs a force-add git add -f crates/uv-trampoline ```
This commit is contained in:
parent
328b116d5d
commit
2586f655bb
229 changed files with 1796 additions and 1818 deletions
17
crates/uv-resolver/src/resolver/allowed_urls.rs
Normal file
17
crates/uv-resolver/src/resolver/allowed_urls.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use rustc_hash::FxHashSet;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct AllowedUrls(FxHashSet<cache_key::CanonicalUrl>);
|
||||
|
||||
impl AllowedUrls {
|
||||
pub(crate) fn contains(&self, url: &Url) -> bool {
|
||||
self.0.contains(&cache_key::CanonicalUrl::new(url))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromIterator<&'a Url> for AllowedUrls {
|
||||
fn from_iter<T: IntoIterator<Item = &'a Url>>(iter: T) -> Self {
|
||||
Self(iter.into_iter().map(cache_key::CanonicalUrl::new).collect())
|
||||
}
|
||||
}
|
||||
25
crates/uv-resolver/src/resolver/index.rs
Normal file
25
crates/uv-resolver/src/resolver/index.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use dashmap::DashMap;
|
||||
use url::Url;
|
||||
|
||||
use distribution_types::PackageId;
|
||||
use once_map::OnceMap;
|
||||
use pypi_types::Metadata21;
|
||||
use uv_normalize::PackageName;
|
||||
|
||||
use super::provider::VersionsResponse;
|
||||
|
||||
/// In-memory index of package metadata.
|
||||
#[derive(Default)]
|
||||
pub struct InMemoryIndex {
|
||||
/// A map from package name to the metadata for that package and the index where the metadata
|
||||
/// came from.
|
||||
pub(crate) packages: OnceMap<PackageName, VersionsResponse>,
|
||||
|
||||
/// A map from package ID to metadata for that distribution.
|
||||
pub(crate) distributions: OnceMap<PackageId, Metadata21>,
|
||||
|
||||
/// A map from source URL to precise URL. For example, the source URL
|
||||
/// `git+https://github.com/pallets/flask.git` could be redirected to
|
||||
/// `git+https://github.com/pallets/flask.git@c2f65dd1cfff0672b902fd5b30815f0b4137214c`.
|
||||
pub(crate) redirects: DashMap<Url, Url>,
|
||||
}
|
||||
1150
crates/uv-resolver/src/resolver/mod.rs
Normal file
1150
crates/uv-resolver/src/resolver/mod.rs
Normal file
File diff suppressed because it is too large
Load diff
190
crates/uv-resolver/src/resolver/provider.rs
Normal file
190
crates/uv-resolver/src/resolver/provider.rs
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
use std::future::Future;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Utc};
|
||||
use url::Url;
|
||||
|
||||
use distribution_types::{Dist, IndexLocations};
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::Metadata21;
|
||||
use uv_client::{FlatIndex, RegistryClient};
|
||||
use uv_distribution::DistributionDatabase;
|
||||
use uv_normalize::PackageName;
|
||||
use uv_traits::{BuildContext, NoBinary};
|
||||
|
||||
use crate::python_requirement::PythonRequirement;
|
||||
use crate::version_map::VersionMap;
|
||||
|
||||
type PackageVersionsResult = Result<VersionsResponse, uv_client::Error>;
|
||||
type WheelMetadataResult = Result<(Metadata21, Option<Url>), uv_distribution::Error>;
|
||||
|
||||
/// The response when requesting versions for a package
|
||||
#[derive(Debug)]
|
||||
pub enum VersionsResponse {
|
||||
/// The package was found in the registry with the included versions
|
||||
Found(VersionMap),
|
||||
/// The package was not found in the registry
|
||||
NotFound,
|
||||
/// The package was not found in the local registry
|
||||
NoIndex,
|
||||
/// The package was not found in the cache and the network is not available.
|
||||
Offline,
|
||||
}
|
||||
|
||||
pub trait ResolverProvider: Send + Sync {
|
||||
/// Get the version map for a package.
|
||||
fn get_package_versions<'io>(
|
||||
&'io self,
|
||||
package_name: &'io PackageName,
|
||||
) -> impl Future<Output = PackageVersionsResult> + Send + 'io;
|
||||
|
||||
/// Get the metadata for a distribution.
|
||||
///
|
||||
/// For a wheel, this is done by querying it's (remote) metadata, for a source dist we
|
||||
/// (fetch and) build the source distribution and return the metadata from the built
|
||||
/// distribution.
|
||||
fn get_or_build_wheel_metadata<'io>(
|
||||
&'io self,
|
||||
dist: &'io Dist,
|
||||
) -> impl Future<Output = WheelMetadataResult> + Send + 'io;
|
||||
|
||||
fn index_locations(&self) -> &IndexLocations;
|
||||
|
||||
/// Set the [`uv_distribution::Reporter`] to use for this installer.
|
||||
#[must_use]
|
||||
fn with_reporter(self, reporter: impl uv_distribution::Reporter + 'static) -> Self;
|
||||
}
|
||||
|
||||
/// The main IO backend for the resolver, which does cached requests network requests using the
|
||||
/// [`RegistryClient`] and [`DistributionDatabase`].
|
||||
pub struct DefaultResolverProvider<'a, Context: BuildContext + Send + Sync> {
|
||||
/// The [`DistributionDatabase`] used to build source distributions.
|
||||
fetcher: DistributionDatabase<'a, Context>,
|
||||
/// Allow moving the parameters to `VersionMap::from_metadata` to a different thread.
|
||||
inner: Arc<DefaultResolverProviderInner>,
|
||||
}
|
||||
|
||||
pub struct DefaultResolverProviderInner {
|
||||
/// The [`RegistryClient`] used to query the index.
|
||||
client: RegistryClient,
|
||||
/// These are the entries from `--find-links` that act as overrides for index responses.
|
||||
flat_index: FlatIndex,
|
||||
tags: Tags,
|
||||
python_requirement: PythonRequirement,
|
||||
exclude_newer: Option<DateTime<Utc>>,
|
||||
no_binary: NoBinary,
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> Deref for DefaultResolverProvider<'a, Context> {
|
||||
type Target = DefaultResolverProviderInner;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.inner.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> DefaultResolverProvider<'a, Context> {
|
||||
/// Reads the flat index entries and builds the provider.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
client: &'a RegistryClient,
|
||||
fetcher: DistributionDatabase<'a, Context>,
|
||||
flat_index: &'a FlatIndex,
|
||||
tags: &'a Tags,
|
||||
python_requirement: PythonRequirement,
|
||||
exclude_newer: Option<DateTime<Utc>>,
|
||||
no_binary: &'a NoBinary,
|
||||
) -> Self {
|
||||
Self {
|
||||
fetcher,
|
||||
inner: Arc::new(DefaultResolverProviderInner {
|
||||
client: client.clone(),
|
||||
flat_index: flat_index.clone(),
|
||||
tags: tags.clone(),
|
||||
python_requirement,
|
||||
exclude_newer,
|
||||
no_binary: no_binary.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
|
||||
for DefaultResolverProvider<'a, Context>
|
||||
{
|
||||
/// Make a "Simple API" request for the package and convert the result to a [`VersionMap`].
|
||||
async fn get_package_versions<'io>(
|
||||
&'io self,
|
||||
package_name: &'io PackageName,
|
||||
) -> PackageVersionsResult {
|
||||
let result = self.client.simple(package_name).await;
|
||||
|
||||
// If the "Simple API" request was successful, convert to `VersionMap` on the Tokio
|
||||
// threadpool, since it can be slow.
|
||||
match result {
|
||||
Ok((index, metadata)) => {
|
||||
let self_send = self.inner.clone();
|
||||
let package_name_owned = package_name.clone();
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
VersionsResponse::Found(VersionMap::from_metadata(
|
||||
metadata,
|
||||
&package_name_owned,
|
||||
&index,
|
||||
&self_send.tags,
|
||||
&self_send.python_requirement,
|
||||
self_send.exclude_newer.as_ref(),
|
||||
self_send.flat_index.get(&package_name_owned).cloned(),
|
||||
&self_send.no_binary,
|
||||
))
|
||||
})
|
||||
.await
|
||||
.expect("Tokio executor failed, was there a panic?"))
|
||||
}
|
||||
Err(err) => match err.into_kind() {
|
||||
uv_client::ErrorKind::PackageNotFound(_) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionsResponse::Found(VersionMap::from(flat_index)))
|
||||
} else {
|
||||
Ok(VersionsResponse::NotFound)
|
||||
}
|
||||
}
|
||||
uv_client::ErrorKind::NoIndex(_) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionsResponse::Found(VersionMap::from(flat_index)))
|
||||
} else if self.flat_index.offline() {
|
||||
Ok(VersionsResponse::Offline)
|
||||
} else {
|
||||
Ok(VersionsResponse::NoIndex)
|
||||
}
|
||||
}
|
||||
uv_client::ErrorKind::Offline(_) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionsResponse::Found(VersionMap::from(flat_index)))
|
||||
} else {
|
||||
Ok(VersionsResponse::Offline)
|
||||
}
|
||||
}
|
||||
kind => Err(kind.into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_or_build_wheel_metadata<'io>(&'io self, dist: &'io Dist) -> WheelMetadataResult {
|
||||
self.fetcher.get_or_build_wheel_metadata(dist).await
|
||||
}
|
||||
|
||||
fn index_locations(&self) -> &IndexLocations {
|
||||
self.fetcher.index_locations()
|
||||
}
|
||||
|
||||
/// Set the [`uv_distribution::Reporter`] to use for this installer.
|
||||
#[must_use]
|
||||
fn with_reporter(self, reporter: impl uv_distribution::Reporter + 'static) -> Self {
|
||||
Self {
|
||||
fetcher: self.fetcher.with_reporter(reporter),
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
51
crates/uv-resolver/src/resolver/reporter.rs
Normal file
51
crates/uv-resolver/src/resolver/reporter.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use url::Url;
|
||||
|
||||
use distribution_types::{SourceDist, VersionOrUrl};
|
||||
use uv_normalize::PackageName;
|
||||
|
||||
pub type BuildId = usize;
|
||||
|
||||
pub trait Reporter: Send + Sync {
|
||||
/// Callback to invoke when a dependency is resolved.
|
||||
fn on_progress(&self, name: &PackageName, version: VersionOrUrl);
|
||||
|
||||
/// Callback to invoke when the resolution is complete.
|
||||
fn on_complete(&self);
|
||||
|
||||
/// Callback to invoke when a source distribution build is kicked off.
|
||||
fn on_build_start(&self, dist: &SourceDist) -> usize;
|
||||
|
||||
/// Callback to invoke when a source distribution build is complete.
|
||||
fn on_build_complete(&self, dist: &SourceDist, id: usize);
|
||||
|
||||
/// Callback to invoke when a repository checkout begins.
|
||||
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;
|
||||
|
||||
/// Callback to invoke when a repository checkout completes.
|
||||
fn on_checkout_complete(&self, url: &Url, rev: &str, index: usize);
|
||||
}
|
||||
|
||||
/// A facade for converting from [`Reporter`] to [`uv_distribution::Reporter`].
|
||||
pub(crate) struct Facade {
|
||||
pub(crate) reporter: Arc<dyn Reporter>,
|
||||
}
|
||||
|
||||
impl uv_distribution::Reporter for Facade {
|
||||
fn on_build_start(&self, dist: &SourceDist) -> usize {
|
||||
self.reporter.on_build_start(dist)
|
||||
}
|
||||
|
||||
fn on_build_complete(&self, dist: &SourceDist, id: usize) {
|
||||
self.reporter.on_build_complete(dist, id);
|
||||
}
|
||||
|
||||
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize {
|
||||
self.reporter.on_checkout_start(url, rev)
|
||||
}
|
||||
|
||||
fn on_checkout_complete(&self, url: &Url, rev: &str, index: usize) {
|
||||
self.reporter.on_checkout_complete(url, rev, index);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue