@@ -553,16 +553,47 @@ def satisfies(
553
553
"""
554
554
Helper method to check if this package satisfies a given dependency.
555
555
556
- This is determined by assessing if this instance provides the package and
557
- features specified by the given dependency. Further, version and source
558
- types are checked.
556
+ This is determined by assessing if this instance provides the package specified
557
+ by the given dependency. Further, version and source types are checked.
559
558
"""
560
- if not self .provides (dependency ) or not dependency .constraint .allows (
561
- self .version
562
- ):
559
+ if self .name != dependency .name :
560
+ return False
561
+
562
+ if not dependency .constraint .allows (self .version ):
563
563
return False
564
564
565
- return ignore_source_type or self .is_same_source_as (dependency )
565
+ if not ignore_source_type and not self .source_satisfies (dependency ):
566
+ return False
567
+
568
+ return True
569
+
570
+ def source_satisfies (self , dependency : Dependency ) -> bool :
571
+ """Determine whether this package's source satisfies the given dependency."""
572
+ if dependency .source_type is None :
573
+ if dependency .source_name is None :
574
+ # The dependency doesn't care about the source, so this package
575
+ # certainly satisfies it.
576
+ return True
577
+
578
+ # The dependency specifies a source_name but not a type: it wants either
579
+ # pypi or a legacy repository.
580
+ #
581
+ # - If this package has no source type then it's from pypi, so it
582
+ # matches if and only if that's what the dependency wants
583
+ # - Else this package is a match if and only if it is from the desired
584
+ # repository
585
+ if self .source_type is None :
586
+ return dependency .source_name .lower () == "pypi"
587
+
588
+ return (
589
+ self .source_type == "legacy"
590
+ and self .source_reference is not None
591
+ and self .source_reference .lower () == dependency .source_name .lower ()
592
+ )
593
+
594
+ # The dependency specifies a source: this package matches if and only if it is
595
+ # from that source.
596
+ return dependency .is_same_source_as (self )
566
597
567
598
def __eq__ (self , other : object ) -> bool :
568
599
if not isinstance (other , Package ):
0 commit comments