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