Convert to RequirementSource rather than Requirement (#9107)

## Summary

This seems like a vestige left over from a refactor.
This commit is contained in:
Charlie Marsh 2024-11-13 20:00:13 -05:00 committed by GitHub
parent 9339e55a11
commit 8c663d2a3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 21 deletions

View file

@ -1,8 +1,7 @@
use std::collections::BTreeMap;
use uv_distribution_filename::DistExtension;
use uv_normalize::{ExtraName, GroupName, PackageName};
use uv_pep508::MarkerTree;
use uv_pypi_types::{HashDigest, Requirement, RequirementSource};
use uv_pypi_types::{HashDigest, RequirementSource};
use crate::{BuiltDist, Diagnostic, Dist, Name, ResolvedDist, SourceDist};
@ -167,9 +166,9 @@ impl Diagnostic for ResolutionDiagnostic {
}
}
impl From<&ResolvedDist> for Requirement {
impl From<&ResolvedDist> for RequirementSource {
fn from(resolved_dist: &ResolvedDist) -> Self {
let source = match resolved_dist {
match resolved_dist {
ResolvedDist::Installable { dist, .. } => match dist {
Dist::Built(BuiltDist::Registry(wheels)) => RequirementSource::Registry {
specifier: uv_pep440::VersionSpecifiers::from(
@ -235,13 +234,6 @@ impl From<&ResolvedDist> for Requirement {
),
index: None,
},
};
Requirement {
name: resolved_dist.name().clone(),
extras: vec![],
marker: MarkerTree::TRUE,
source,
origin: None,
}
}
}

View file

@ -13,7 +13,7 @@ use uv_distribution_types::{
};
use uv_fs::Simplified;
use uv_platform_tags::Tags;
use uv_pypi_types::Requirement;
use uv_pypi_types::RequirementSource;
use uv_python::PythonEnvironment;
use uv_types::HashStrategy;
@ -76,29 +76,28 @@ impl<'a> Planner<'a> {
let no_binary = build_options.no_binary_package(dist.name());
let no_build = build_options.no_build_package(dist.name());
let requirement = Requirement::from(dist);
// Determine whether the distribution is already installed.
let installed_dists = site_packages.remove_packages(&requirement.name);
let installed_dists = site_packages.remove_packages(dist.name());
if reinstall {
reinstalls.extend(installed_dists);
} else {
match installed_dists.as_slice() {
[] => {}
[distribution] => {
match RequirementSatisfaction::check(distribution, &requirement.source)? {
[installed] => {
let source = RequirementSource::from(dist);
match RequirementSatisfaction::check(installed, &source)? {
RequirementSatisfaction::Mismatch => {
debug!("Requirement installed, but mismatched: {distribution:?}");
debug!("Requirement installed, but mismatched: {installed:?}");
}
RequirementSatisfaction::Satisfied => {
debug!("Requirement already installed: {distribution}");
debug!("Requirement already installed: {installed}");
continue;
}
RequirementSatisfaction::OutOfDate => {
debug!("Requirement installed, but not fresh: {distribution}");
debug!("Requirement installed, but not fresh: {installed}");
}
}
reinstalls.push(distribution.clone());
reinstalls.push(installed.clone());
}
// We reinstall installed distributions with multiple versions because
// we do not want to keep multiple incompatible versions but removing