From 8b51951cd01671b01711447d2e7e3718ff76ab4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Thu, 18 Apr 2024 16:22:49 +0200 Subject: [PATCH] Allow wildcard in rm_safe call --- conans/model/settings.py | 7 +++++-- conans/test/unittests/model/settings_test.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/conans/model/settings.py b/conans/model/settings.py index 8ebe924b4bf..347ab40a5fe 100644 --- a/conans/model/settings.py +++ b/conans/model/settings.py @@ -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: @@ -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 diff --git a/conans/test/unittests/model/settings_test.py b/conans/test/unittests/model/settings_test.py index 94d4a44673c..63960772d7e 100644 --- a/conans/test/unittests/model/settings_test.py +++ b/conans/test/unittests/model/settings_test.py @@ -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"