@@ -10,9 +10,9 @@ use distribution_types::{
10
10
BuiltDist , CachedDirectUrlDist , CachedDist , Dist , IndexLocations , InstalledDist ,
11
11
InstalledMetadata , InstalledVersion , Name , SourceDist ,
12
12
} ;
13
- use pep508_rs:: { Requirement , VersionOrUrl } ;
13
+ use pep508_rs:: { Requirement , VersionOrUrl , VersionOrUrlRef } ;
14
14
use platform_tags:: Tags ;
15
- use uv_cache:: { ArchiveTarget , ArchiveTimestamp , Cache , CacheBucket , WheelCache } ;
15
+ use uv_cache:: { ArchiveTimestamp , Cache , CacheBucket , WheelCache } ;
16
16
use uv_configuration:: { NoBinary , Reinstall } ;
17
17
use uv_distribution:: {
18
18
BuiltWheelIndex , HttpArchivePointer , LocalArchivePointer , RegistryWheelIndex ,
@@ -21,6 +21,7 @@ use uv_fs::Simplified;
21
21
use uv_interpreter:: PythonEnvironment ;
22
22
use uv_types:: HashStrategy ;
23
23
24
+ use crate :: satisfies:: RequirementSatisfaction ;
24
25
use crate :: { ResolvedEditable , SitePackages } ;
25
26
26
27
/// A planner to generate an [`Plan`] based on a set of requirements.
@@ -182,10 +183,23 @@ impl<'a> Planner<'a> {
182
183
match installed_dists. as_slice ( ) {
183
184
[ ] => { }
184
185
[ distribution] => {
185
- if installed_satisfies_requirement ( distribution, requirement) ? {
186
- debug ! ( "Requirement already installed: {distribution}" ) ;
187
- installed. push ( distribution. clone ( ) ) ;
188
- continue ;
186
+ match RequirementSatisfaction :: check (
187
+ distribution,
188
+ requirement
189
+ . version_or_url
190
+ . as_ref ( )
191
+ . map ( VersionOrUrlRef :: from) ,
192
+ requirement,
193
+ ) ? {
194
+ RequirementSatisfaction :: Mismatch => { }
195
+ RequirementSatisfaction :: Satisfied => {
196
+ debug ! ( "Requirement already installed: {distribution}" ) ;
197
+ installed. push ( distribution. clone ( ) ) ;
198
+ continue ;
199
+ }
200
+ RequirementSatisfaction :: OutOfDate => {
201
+ debug ! ( "Requirement installed, but not fresh: {distribution}" ) ;
202
+ }
189
203
}
190
204
reinstalls. push ( distribution. clone ( ) ) ;
191
205
}
@@ -416,53 +430,3 @@ pub struct Plan {
416
430
/// _not_ necessary to satisfy the requirements.
417
431
pub extraneous : Vec < InstalledDist > ,
418
432
}
419
-
420
- /// Returns true if a requirement is satisfied by an installed distribution.
421
- ///
422
- /// Returns an error if IO fails during a freshness check for a local path.
423
- fn installed_satisfies_requirement (
424
- distribution : & InstalledDist ,
425
- requirement : & Requirement ,
426
- ) -> Result < bool > {
427
- // Filter out already-installed packages.
428
- match requirement. version_or_url . as_ref ( ) {
429
- // Accept any version of the package.
430
- None => return Ok ( true ) ,
431
-
432
- // If the requirement comes from a registry, check by name.
433
- Some ( VersionOrUrl :: VersionSpecifier ( version_specifier) ) => {
434
- if version_specifier. contains ( distribution. version ( ) ) {
435
- debug ! ( "Requirement already satisfied: {distribution}" ) ;
436
- return Ok ( true ) ;
437
- }
438
- }
439
-
440
- // If the requirement comes from a direct URL, check by URL.
441
- Some ( VersionOrUrl :: Url ( url) ) => {
442
- if let InstalledDist :: Url ( installed) = & distribution {
443
- if !installed. editable && & installed. url == url. raw ( ) {
444
- // If the requirement came from a local path, check freshness.
445
- if let Some ( archive) = ( url. scheme ( ) == "file" )
446
- . then ( || url. to_file_path ( ) . ok ( ) )
447
- . flatten ( )
448
- {
449
- if ArchiveTimestamp :: up_to_date_with (
450
- & archive,
451
- ArchiveTarget :: Install ( distribution) ,
452
- ) ? {
453
- debug ! ( "Requirement already satisfied (and up-to-date): {installed}" ) ;
454
- return Ok ( true ) ;
455
- }
456
- debug ! ( "Requirement already satisfied (but not up-to-date): {installed}" ) ;
457
- } else {
458
- // Otherwise, assume the requirement is up-to-date.
459
- debug ! ( "Requirement already satisfied (assumed up-to-date): {installed}" ) ;
460
- return Ok ( true ) ;
461
- }
462
- }
463
- }
464
- }
465
- }
466
-
467
- Ok ( false )
468
- }
0 commit comments