@@ -537,29 +537,43 @@ def aggregate_lock_specs(
537
537
[lock_spec .dependencies for lock_spec in lock_specs ]
538
538
):
539
539
key = (dep .manager , dep .name )
540
+ new_dep = dep .copy ()
540
541
if key in unique_deps :
541
542
prev_dep = unique_deps [key ]
542
543
543
544
# Override existing, but merge selectors
544
545
previous_selectors = prev_dep .selectors
545
546
previous_selectors |= dep .selectors
546
- dep .selectors = previous_selectors
547
+ new_dep .selectors = previous_selectors
547
548
548
- # If bold old and new are VersionedDependency, combine versions
549
+ # If bold old and new are VersionedDependency, combine version strings together
550
+ # If there are conflicting versions, they will be handled by the solver
549
551
if isinstance (prev_dep , VersionedDependency ) and isinstance (
550
552
dep , VersionedDependency
551
553
):
554
+ assert isinstance (new_dep , VersionedDependency )
555
+
556
+ # MatchSpecs are expressions in DNF form: `|` is OR and `,` is AND
552
557
prev_versions = [
553
- set (sec .split ("," )) for sec in prev_dep .version .split ("|" )
558
+ set (sec .split ("," ))
559
+ for sec in prev_dep .version .split ("|" )
560
+ if sec != ""
561
+ ]
562
+ new_versions = [
563
+ set (sec .split ("," )) for sec in dep .version .split ("|" ) if sec != ""
554
564
]
555
- new_versions = [set (sec .split ("," )) for sec in dep .version .split ("|" )]
565
+ # To AND two DNF expressions, we essentially perform the distributive law
566
+ # ORing every pair of terms in the individual expressions
567
+ # Ex: (AB | CD) (AC | BD) = ABAC | ABBD | CDAC | CDBC = ABC | ABD | ACD | BCD
556
568
cross_versions = [
557
569
prev | new for prev , new in product (prev_versions , new_versions )
558
570
]
559
- final_versions = set ("," .join (subset ) for subset in cross_versions )
560
- dep .version = "|" .join (final_versions )
571
+ final_versions = set (
572
+ "," .join (sorted (subset , reverse = True )) for subset in cross_versions
573
+ )
574
+ new_dep .version = "|" .join (sorted (final_versions , reverse = True ))
561
575
562
- unique_deps [key ] = dep
576
+ unique_deps [key ] = new_dep
563
577
564
578
dependencies = list (unique_deps .values ())
565
579
try :
0 commit comments