mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
parent
89bef7bf09
commit
d7f195fdc9
3 changed files with 72 additions and 76 deletions
|
@ -132,6 +132,18 @@ impl PubGrubPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the name of this PubGrub package, if it is not the root package or a Python version
|
||||
/// constraint.
|
||||
pub(crate) fn name_no_root(&self) -> Option<&PackageName> {
|
||||
match &**self {
|
||||
PubGrubPackageInner::Root(_) | PubGrubPackageInner::Python(_) => None,
|
||||
PubGrubPackageInner::Package { name, .. }
|
||||
| PubGrubPackageInner::Extra { name, .. }
|
||||
| PubGrubPackageInner::Dev { name, .. }
|
||||
| PubGrubPackageInner::Marker { name, .. } => Some(name),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the marker expression associated with this PubGrub package, if
|
||||
/// it has one.
|
||||
pub(crate) fn marker(&self) -> Option<&MarkerTree> {
|
||||
|
|
|
@ -31,53 +31,49 @@ impl PubGrubPriorities {
|
|||
urls: &ForkUrls,
|
||||
) {
|
||||
let next = self.0.len();
|
||||
match &**package {
|
||||
PubGrubPackageInner::Root(_) => {}
|
||||
PubGrubPackageInner::Python(_) => {}
|
||||
// The root package and Python constraints have no explicit priority, the root package is
|
||||
// always first and the Python version (range) is fixed.
|
||||
let Some(name) = package.name_no_root() else {
|
||||
return;
|
||||
};
|
||||
|
||||
PubGrubPackageInner::Marker { name, .. }
|
||||
| PubGrubPackageInner::Extra { name, .. }
|
||||
| PubGrubPackageInner::Dev { name, .. }
|
||||
| PubGrubPackageInner::Package { name, .. } => {
|
||||
match self.0.entry(name.clone()) {
|
||||
std::collections::hash_map::Entry::Occupied(mut entry) => {
|
||||
// Preserve the original index.
|
||||
let index = match entry.get() {
|
||||
PubGrubPriority::Unspecified(Reverse(index)) => *index,
|
||||
PubGrubPriority::Singleton(Reverse(index)) => *index,
|
||||
PubGrubPriority::DirectUrl(Reverse(index)) => *index,
|
||||
PubGrubPriority::Root => next,
|
||||
};
|
||||
match self.0.entry(name.clone()) {
|
||||
std::collections::hash_map::Entry::Occupied(mut entry) => {
|
||||
// Preserve the original index.
|
||||
let index = match entry.get() {
|
||||
PubGrubPriority::Unspecified(Reverse(index)) => *index,
|
||||
PubGrubPriority::Singleton(Reverse(index)) => *index,
|
||||
PubGrubPriority::DirectUrl(Reverse(index)) => *index,
|
||||
PubGrubPriority::Root => next,
|
||||
};
|
||||
|
||||
// Compute the priority.
|
||||
let priority = if urls.get(name).is_some() {
|
||||
PubGrubPriority::DirectUrl(Reverse(index))
|
||||
} else if version.as_singleton().is_some() {
|
||||
PubGrubPriority::Singleton(Reverse(index))
|
||||
} else {
|
||||
PubGrubPriority::Unspecified(Reverse(index))
|
||||
};
|
||||
// Compute the priority.
|
||||
let priority = if urls.get(name).is_some() {
|
||||
PubGrubPriority::DirectUrl(Reverse(index))
|
||||
} else if version.as_singleton().is_some() {
|
||||
PubGrubPriority::Singleton(Reverse(index))
|
||||
} else {
|
||||
PubGrubPriority::Unspecified(Reverse(index))
|
||||
};
|
||||
|
||||
// Take the maximum of the new and existing priorities.
|
||||
if priority > *entry.get() {
|
||||
entry.insert(priority);
|
||||
}
|
||||
}
|
||||
std::collections::hash_map::Entry::Vacant(entry) => {
|
||||
// Compute the priority.
|
||||
let priority = if urls.get(name).is_some() {
|
||||
PubGrubPriority::DirectUrl(Reverse(next))
|
||||
} else if version.as_singleton().is_some() {
|
||||
PubGrubPriority::Singleton(Reverse(next))
|
||||
} else {
|
||||
PubGrubPriority::Unspecified(Reverse(next))
|
||||
};
|
||||
|
||||
// Insert the priority.
|
||||
entry.insert(priority);
|
||||
}
|
||||
// Take the maximum of the new and existing priorities.
|
||||
if priority > *entry.get() {
|
||||
entry.insert(priority);
|
||||
}
|
||||
}
|
||||
std::collections::hash_map::Entry::Vacant(entry) => {
|
||||
// Compute the priority.
|
||||
let priority = if urls.get(name).is_some() {
|
||||
PubGrubPriority::DirectUrl(Reverse(next))
|
||||
} else if version.as_singleton().is_some() {
|
||||
PubGrubPriority::Singleton(Reverse(next))
|
||||
} else {
|
||||
PubGrubPriority::Unspecified(Reverse(next))
|
||||
};
|
||||
|
||||
// Insert the priority.
|
||||
entry.insert(priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -667,43 +667,31 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
|||
url: Option<&VerbatimParsedUrl>,
|
||||
request_sink: &Sender<Request>,
|
||||
) -> Result<(), ResolveError> {
|
||||
match (&**package, url) {
|
||||
(PubGrubPackageInner::Root(_), _) => {}
|
||||
(PubGrubPackageInner::Python(_), _) => {}
|
||||
(
|
||||
PubGrubPackageInner::Marker { name, .. }
|
||||
| PubGrubPackageInner::Extra { name, .. }
|
||||
| PubGrubPackageInner::Dev { name, .. }
|
||||
| PubGrubPackageInner::Package { name, .. },
|
||||
None,
|
||||
) => {
|
||||
// Verify that the package is allowed under the hash-checking policy.
|
||||
if !self.hasher.allows_package(name) {
|
||||
return Err(ResolveError::UnhashedPackage(name.clone()));
|
||||
}
|
||||
// Only request real package
|
||||
let Some(name) = package.name_no_root() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
// Emit a request to fetch the metadata for this package.
|
||||
if self.index.packages().register(name.clone()) {
|
||||
request_sink.blocking_send(Request::Package(name.clone()))?;
|
||||
}
|
||||
if let Some(url) = url {
|
||||
// Verify that the package is allowed under the hash-checking policy.
|
||||
if !self.hasher.allows_url(&url.verbatim) {
|
||||
return Err(ResolveError::UnhashedPackage(name.clone()));
|
||||
}
|
||||
(
|
||||
PubGrubPackageInner::Marker { name, .. }
|
||||
| PubGrubPackageInner::Extra { name, .. }
|
||||
| PubGrubPackageInner::Dev { name, .. }
|
||||
| PubGrubPackageInner::Package { name, .. },
|
||||
Some(url),
|
||||
) => {
|
||||
// Verify that the package is allowed under the hash-checking policy.
|
||||
if !self.hasher.allows_url(&url.verbatim) {
|
||||
return Err(ResolveError::UnhashedPackage(name.clone()));
|
||||
}
|
||||
|
||||
// Emit a request to fetch the metadata for this distribution.
|
||||
let dist = Dist::from_url(name.clone(), url.clone())?;
|
||||
if self.index.distributions().register(dist.version_id()) {
|
||||
request_sink.blocking_send(Request::Dist(dist))?;
|
||||
}
|
||||
// Emit a request to fetch the metadata for this distribution.
|
||||
let dist = Dist::from_url(name.clone(), url.clone())?;
|
||||
if self.index.distributions().register(dist.version_id()) {
|
||||
request_sink.blocking_send(Request::Dist(dist))?;
|
||||
}
|
||||
} else {
|
||||
// Verify that the package is allowed under the hash-checking policy.
|
||||
if !self.hasher.allows_package(name) {
|
||||
return Err(ResolveError::UnhashedPackage(name.clone()));
|
||||
}
|
||||
|
||||
// Emit a request to fetch the metadata for this package.
|
||||
if self.index.packages().register(name.clone()) {
|
||||
request_sink.blocking_send(Request::Package(name.clone()))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue