Skip to content

Commit

Permalink
Include record of previously checked config entries, to avoid overclo…
Browse files Browse the repository at this point in the history
…bbering by lower priority entries; include test for such overclobbering
  • Loading branch information
danpetry committed Oct 16, 2023
1 parent ed7f5e3 commit c379006
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,19 @@ def filter_combined_spec_to_used_keys(combined_spec, specs):

# TODO: act here?
combined_spec = explode_variants(combined_spec)
seen_keys=set() # seen_keys makes sure that a setting from a lower-priority spec doesn't clobber the same setting that has been redefined in a higher-priority spec.
# The specs are checked from high to low priority order.
for source, source_specs in reversed(specs.items()):
for k, vs in source_specs.items():
if k not in extend_keys:
if k not in extend_keys and k not in seen_keys:
# when filtering ends up killing off all variants, we just ignore that. Generally,
# this arises when a later variant config overrides, rather than selects a
# subspace of earlier configs
combined_spec = (
filter_by_key_value(combined_spec, k, vs, source_name=source)
or combined_spec
)
seen_keys.add(k)
return combined_spec


Expand Down
26 changes: 26 additions & 0 deletions tests/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
dict_of_lists_to_list_of_dicts,
get_package_variants,
validate_spec,
filter_combined_spec_to_used_keys,
)

from .utils import variants_dir
Expand Down Expand Up @@ -657,3 +658,28 @@ def test_variant_subkeys_retained():
m.final = False
outputs = m.get_output_metadata_set(permit_unsatisfiable_variants=False)
get_all_replacements(outputs[0][1].config.variant)

@pytest.mark.parametrize(
"internal_defaults, low_prio_config, high_prio_config, expected",
[
(
{'pkg_1': '1.0'},
{'pkg_1': '1.1'},
{'pkg_1': ['1.1', '1.2'],
'pkg_2': ['1.1', '1.2'],
'zip_keys': [['pkg_1', 'pkg_2']]},
[{'pkg_1': '1.1', 'pkg_2': '1.1', 'zip_keys': [['pkg_1', 'pkg_2']]},
{'pkg_1': '1.2', 'pkg_2': '1.2', 'zip_keys': [['pkg_1', 'pkg_2']]}]
)
]
)
def test_zip_key_filtering(internal_defaults, low_prio_config, high_prio_config, expected):
from collections import OrderedDict

combined_spec = low_prio_config.copy()
combined_spec.update(high_prio_config)
specs = OrderedDict([('internal_defaults',internal_defaults),
('low_prio_config',low_prio_config),
('high_prio_config',high_prio_config)])

assert filter_combined_spec_to_used_keys(combined_spec, specs=specs) == expected

0 comments on commit c379006

Please sign in to comment.