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

Allow wildcard in rm_safe call #16105

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions conans/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def serialize(self):

def get_safe(self, name, default=None):
"""
Get the setting value avoiding
Get the setting value avoiding throwing if it does not exist or has been removed
:param name:
:param default:
:return:
Expand All @@ -232,7 +232,10 @@ def rm_safe(self, name):
except KeyError:
pass
else:
self._data.pop(name, None)
if name == "*":
self.clear()
else:
self._data.pop(name, None)

def copy(self):
""" deepcopy, recursive
Expand Down
11 changes: 11 additions & 0 deletions conans/test/unittests/model/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ def test_rm_safe():
assert "'settings.compiler.libcxx' doesn't exist for 'clang'" in str(e.value)


def test_rm_safe_wildcard():
settings = Settings.loads(default_settings_yml)
settings.compiler = "gcc"
settings.compiler.version = "4.8"
settings.compiler.libcxx = "libstdc++"
settings.rm_safe("compiler.*")
assert settings.compiler == "gcc"
assert settings.get_safe("compiler.version") is None
assert settings.get_safe("compiler.libcxx") is None


def test_settings_intel_cppstd_03():
settings = Settings.loads(default_settings_yml)
settings.compiler = "intel-cc"
Expand Down