Skip to content

Commit

Permalink
Avoid clobbering variants from higher priority cbc.yaml (#5039)
Browse files Browse the repository at this point in the history
* Add record of previously checked config entries, to avoid clobbering by lower priority entries.
* Add test for clobbering.

---------

Co-authored-by: Ken Odegard <[email protected]>
Co-authored-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 558999b commit f7dd4ed
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,21 @@ def filter_combined_spec_to_used_keys(combined_spec, specs):

# TODO: act here?
combined_spec = explode_variants(combined_spec)
# 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.
seen_keys = set()
# 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
19 changes: 19 additions & 0 deletions news/5039-dont-clobber-multiple-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Avoid clobbering of variants in high priority cbc.yaml entries when they aren't present in lower priority cbc.yamls. (#5039)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
43 changes: 43 additions & 0 deletions tests/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from conda_build.variants import (
combine_specs,
dict_of_lists_to_list_of_dicts,
filter_combined_spec_to_used_keys,
get_package_variants,
validate_spec,
)
Expand Down Expand Up @@ -657,3 +658,45 @@ 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",
[
pytest.param(
{"pkg_1": "1.0"},
{"pkg_1": "1.1"},
{"pkg_1": ["1.1", "1.2"], "pkg_2": ["1.1"]},
[{"pkg_1": "1.1", "pkg_2": "1.1"}, {"pkg_1": "1.2", "pkg_2": "1.1"}],
id="basic",
),
pytest.param(
{"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"]]},
],
id="zip_keys",
),
],
)
def test_zip_key_filtering(
internal_defaults, low_prio_config, high_prio_config, expected
):
combined_spec = {
**low_prio_config,
**high_prio_config,
}
specs = {
"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 f7dd4ed

Please sign in to comment.