Skip to content

Commit

Permalink
Allow wildcard in rm_safe call (#16105)
Browse files Browse the repository at this point in the history
Allow wildcard in rm_safe call
  • Loading branch information
AbrilRBS authored Apr 19, 2024
1 parent 1b497cd commit 517e2b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 517e2b7

Please sign in to comment.