File tree Expand file tree Collapse file tree 2 files changed +140
-3
lines changed Expand file tree Collapse file tree 2 files changed +140
-3
lines changed Original file line number Diff line number Diff line change @@ -2581,3 +2581,130 @@ def test_optional_dependencies_with_version_specifier(
25812581 )
25822582 assert resolved .keys () == {"adaptive" }
25832583 assert resolved ["adaptive" ][None ]["conda" ].pin == "=0.13.2"
2584+
2585+
2586+ @pytest .mark .parametrize ("toml_or_yaml" , ["toml" , "yaml" ])
2587+ def test_origin_in_spec (
2588+ tmp_path : Path ,
2589+ toml_or_yaml : Literal ["toml" , "yaml" ],
2590+ ) -> None :
2591+ d1 = tmp_path / "dir1"
2592+ d1 .mkdir ()
2593+ f1 = d1 / "requirements.yaml"
2594+ f1 .write_text ("dependencies:\n - numpy\n - conda: mumps" )
2595+
2596+ d2 = tmp_path / "dir2"
2597+ d2 .mkdir ()
2598+ f2 = d2 / "requirements.yaml"
2599+ f2 .write_text ("dependencies:\n - pip: pandas\n - numpy" )
2600+ f1 = maybe_as_toml (toml_or_yaml , f1 )
2601+ f2 = maybe_as_toml (toml_or_yaml , f2 )
2602+
2603+ requirements = parse_requirements (f1 , f2 , verbose = False )
2604+ assert requirements .requirements == {
2605+ "numpy" : [
2606+ Spec (
2607+ name = "numpy" ,
2608+ which = "conda" ,
2609+ pin = None ,
2610+ identifier = "17e5d607" ,
2611+ selector = None ,
2612+ origin = (f1 ,),
2613+ ),
2614+ Spec (
2615+ name = "numpy" ,
2616+ which = "pip" ,
2617+ pin = None ,
2618+ identifier = "17e5d607" ,
2619+ selector = None ,
2620+ origin = (f1 ,),
2621+ ),
2622+ Spec (
2623+ name = "numpy" ,
2624+ which = "conda" ,
2625+ pin = None ,
2626+ identifier = "9e467fa1" ,
2627+ selector = None ,
2628+ origin = (f2 ,),
2629+ ),
2630+ Spec (
2631+ name = "numpy" ,
2632+ which = "pip" ,
2633+ pin = None ,
2634+ identifier = "9e467fa1" ,
2635+ selector = None ,
2636+ origin = (f2 ,),
2637+ ),
2638+ ],
2639+ "mumps" : [
2640+ Spec (
2641+ name = "mumps" ,
2642+ which = "conda" ,
2643+ pin = None ,
2644+ identifier = "5eb93b8c" ,
2645+ selector = None ,
2646+ origin = (f1 ,),
2647+ ),
2648+ ],
2649+ "pandas" : [
2650+ Spec (
2651+ name = "pandas" ,
2652+ which = "pip" ,
2653+ pin = None ,
2654+ identifier = "08fd8713" ,
2655+ selector = None ,
2656+ origin = (f2 ,),
2657+ ),
2658+ ],
2659+ }
2660+
2661+ resolved = resolve_conflicts (
2662+ requirements .requirements ,
2663+ requirements .platforms ,
2664+ )
2665+ assert resolved == {
2666+ "numpy" : {
2667+ None : {
2668+ "conda" : Spec (
2669+ name = "numpy" ,
2670+ which = "conda" ,
2671+ pin = None ,
2672+ identifier = "17e5d607" ,
2673+ selector = None ,
2674+ origin = (f1 , f2 ),
2675+ ),
2676+ "pip" : Spec (
2677+ name = "numpy" ,
2678+ which = "pip" ,
2679+ pin = None ,
2680+ identifier = "17e5d607" ,
2681+ selector = None ,
2682+ origin = (f1 , f2 ),
2683+ ),
2684+ },
2685+ },
2686+ "mumps" : {
2687+ None : {
2688+ "conda" : Spec (
2689+ name = "mumps" ,
2690+ which = "conda" ,
2691+ pin = None ,
2692+ identifier = "5eb93b8c" ,
2693+ selector = None ,
2694+ origin = (f1 ,),
2695+ ),
2696+ },
2697+ },
2698+ "pandas" : {
2699+ None : {
2700+ "pip" : Spec (
2701+ name = "pandas" ,
2702+ which = "pip" ,
2703+ pin = None ,
2704+ identifier = "08fd8713" ,
2705+ selector = None ,
2706+ origin = (f2 ,),
2707+ ),
2708+ },
2709+ },
2710+ }
Original file line number Diff line number Diff line change @@ -82,22 +82,32 @@ def _maybe_new_spec_with_combined_pinnings(
8282 specs : list [Spec ],
8383) -> Spec :
8484 pinned_specs = [m for m in specs if m .pin is not None ]
85+ combined_origin = tuple (sorted ({p for s in specs for p in s .origin }))
8586 if len (pinned_specs ) == 1 :
86- return pinned_specs [0 ]
87+ if len (combined_origin ) == 1 :
88+ return pinned_specs [0 ]
89+ # If there is only one pinned spec, but the origins are different,
90+ # we need to create a new spec with the combined origin.
91+ return pinned_specs [0 ]._replace (origin = combined_origin )
92+
8793 if len (pinned_specs ) > 1 :
8894 first = pinned_specs [0 ]
8995 pins = [m .pin for m in pinned_specs ]
9096 pin = combine_version_pinnings (pins , name = first .name ) # type: ignore[arg-type]
91- combined_files = tuple ({f for spec in specs for f in (spec .origin or ())})
9297 return Spec (
9398 name = first .name ,
9499 which = first .which ,
95100 pin = pin ,
96101 identifier = first .identifier , # should I create a new one?
97- origin = combined_files ,
102+ origin = combined_origin ,
98103 )
99104
100105 # Flatten the list
106+ assert len (pinned_specs ) == 0
107+ if len (combined_origin ) > 1 :
108+ # If there are no pinned specs, but the origins are different,
109+ # we need to create a new spec with the combined origin.
110+ return specs [0 ]._replace (origin = combined_origin )
101111 return specs [0 ]
102112
103113
You can’t perform that action at this time.
0 commit comments