Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[settings] subsettings from fake settings #16642

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ def _compatible_infos(conanfile, compatibles):
compat_info = conanfile.original_info.clone()
settings = elem.get("settings")
if settings:
compat_info.settings.update_values(settings)
compat_info.settings.update_values(settings, raise_error=False)
options = elem.get("options")
if options:
compat_info.options.update(options_values=OrderedDict(options))
result.append(compat_info)
settings_target = elem.get("settings_target")
if settings_target and compat_info.settings_target:
compat_info.settings_target.update_values(settings_target)
compat_info.settings_target.update_values(settings_target, raise_error=False)
return result
17 changes: 9 additions & 8 deletions conans/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,24 @@ def values_list(self):
def items(self):
return self.values_list

def update_values(self, vals):
""" receives a list of tuples (compiler.version, value)
This is more an updated than a setter
def update_values(self, values, raise_error=True):
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
"""
Receives a list of tuples (compiler.version, value)
This is more an updater than a setter.
"""
self._frozen = False # Could be restored at the end, but not really necessary
assert isinstance(vals, (list, tuple)), vals
for (name, value) in vals:
assert isinstance(values, (list, tuple)), values
for (name, value) in values:
list_settings = name.split(".")
attr = self
try:
for setting in list_settings[:-1]:
attr = getattr(attr, setting)
except ConanException: # fails if receiving settings doesn't have it defined
pass
else:
value = str(value) if value is not None else None
setattr(attr, list_settings[-1], value)
except ConanException: # fails if receiving settings doesn't have it defined
if raise_error:
raise

def constrained(self, constraint_def):
""" allows to restrict a given Settings object with the input of another Settings object
Expand Down
22 changes: 22 additions & 0 deletions test/unittests/model/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,25 @@ def test_settings_intel_cppstd_03():
settings.compiler = "intel-cc"
# This doesn't crash, it used to crash due to "03" not quoted in setting.yml
settings.compiler.cppstd = "03"


def test_set_value_non_existing_values():
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
data = {
"compiler": {
"gcc": {
"version": ["4.8", "4.9"],
"arch": {"x86": {"speed": ["A", "B"]},
"x64": {"speed": ["C", "D"]}}}
},
"os": ["Windows", "Linux"]
}
settings = Settings(data)
with pytest.raises(ConanException) as cm:
settings.update_values([("foo", "A")])
assert "'settings.foo' doesn't exist for 'settings'" in str(cm.value)
with pytest.raises(ConanException) as cm:
settings.update_values([("foo.bar", "A")])
assert "'settings.foo' doesn't exist for 'settings'" in str(cm.value)
# it does not raise any error
settings.update_values([("foo", "A")], raise_error=False)
settings.update_values([("foo.bar", "A")], raise_error=False)