diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2023-05-05 06:28:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 00:28:34 -0400 |
commit | 0c5a5e2ce0eec872bd526208dd8caf5d169e626e (patch) | |
tree | 6ede44bdcd446a684083bf8a9b9d4eb6a0bc7875 /lib | |
parent | c3593e5b486f3f824d5070151ed07c10fdeccaa3 (diff) | |
download | spack-0c5a5e2ce0eec872bd526208dd8caf5d169e626e.tar.gz spack-0c5a5e2ce0eec872bd526208dd8caf5d169e626e.tar.bz2 spack-0c5a5e2ce0eec872bd526208dd8caf5d169e626e.tar.xz spack-0c5a5e2ce0eec872bd526208dd8caf5d169e626e.zip |
Remove "blacklist" and "whitelist" from module configuration (#37432)
The sections were deprecated in v0.19
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/modules/common.py | 43 | ||||
-rw-r--r-- | lib/spack/spack/schema/modules.py | 54 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/module.py | 12 | ||||
-rw-r--r-- | lib/spack/spack/test/modules/common.py | 33 | ||||
-rw-r--r-- | lib/spack/spack/test/modules/lmod.py | 12 | ||||
-rw-r--r-- | lib/spack/spack/test/modules/tcl.py | 21 |
6 files changed, 21 insertions, 154 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py index 7dbe6d8988..930bce8a92 100644 --- a/lib/spack/spack/modules/common.py +++ b/lib/spack/spack/modules/common.py @@ -59,34 +59,6 @@ import spack.util.path import spack.util.spack_yaml as syaml -def get_deprecated(dictionary, name, old_name, default): - """Get a deprecated property from a ``dict``. - - Arguments: - dictionary (dict): dictionary to get a value from. - name (str): New name for the property. If present, supersedes ``old_name``. - old_name (str): Deprecated name for the property. If present, a warning - is printed. - default (object): value to return if neither name is found. - """ - value = default - - # always warn if old name is present - if old_name in dictionary: - value = dictionary.get(old_name, value) - main_msg = "`{}:` is deprecated in module config and will be removed in v0.20." - details = ( - "Use `{}:` instead. You can run `spack config update` to translate your " - "configuration files automatically." - ) - tty.warn(main_msg.format(old_name), details.format(name)) - - # name overrides old name if present - value = dictionary.get(name, value) - - return value - - #: config section for this file def configuration(module_set_name): config_path = "modules:%s" % module_set_name @@ -514,18 +486,15 @@ class BaseConfiguration(object): conf = self.module.configuration(self.name) # Compute the list of include rules that match - # DEPRECATED: remove 'whitelist' in v0.20 - include_rules = get_deprecated(conf, "include", "whitelist", []) + include_rules = conf.get("include", []) include_matches = [x for x in include_rules if spec.satisfies(x)] # Compute the list of exclude rules that match - # DEPRECATED: remove 'blacklist' in v0.20 - exclude_rules = get_deprecated(conf, "exclude", "blacklist", []) + exclude_rules = conf.get("exclude", []) exclude_matches = [x for x in exclude_rules if spec.satisfies(x)] # Should I exclude the module because it's implicit? - # DEPRECATED: remove 'blacklist_implicits' in v0.20 - exclude_implicits = get_deprecated(conf, "exclude_implicits", "blacklist_implicits", None) + exclude_implicits = conf.get("exclude_implicits", None) excluded_as_implicit = exclude_implicits and not self.explicit def debug_info(line_header, match_list): @@ -570,10 +539,8 @@ class BaseConfiguration(object): @property def exclude_env_vars(self): """List of variables that should be left unmodified.""" - filter = self.conf.get("filter", {}) - - # DEPRECATED: remove in v0.20 - return get_deprecated(filter, "exclude_env_vars", "environment_blacklist", {}) + filter_subsection = self.conf.get("filter", {}) + return filter_subsection.get("exclude_env_vars", {}) def _create_list_for(self, what): include = [] diff --git a/lib/spack/spack/schema/modules.py b/lib/spack/spack/schema/modules.py index 261065c8b3..1d285f851b 100644 --- a/lib/spack/spack/schema/modules.py +++ b/lib/spack/spack/schema/modules.py @@ -187,57 +187,3 @@ schema = { "additionalProperties": False, "properties": properties, } - - -# deprecated keys and their replacements -exclude_include_translations = { - "whitelist": "include", - "blacklist": "exclude", - "blacklist_implicits": "exclude_implicits", - "environment_blacklist": "exclude_env_vars", -} - - -def update_keys(data, key_translations): - """Change blacklist/whitelist to exclude/include. - - Arguments: - data (dict): data from a valid modules configuration. - key_translations (dict): A dictionary of keys to translate to - their respective values. - - Return: - (bool) whether anything was changed in data - """ - changed = False - - if isinstance(data, dict): - keys = list(data.keys()) - for key in keys: - value = data[key] - - translation = key_translations.get(key) - if translation: - data[translation] = data.pop(key) - changed = True - - changed |= update_keys(value, key_translations) - - elif isinstance(data, list): - for elt in data: - changed |= update_keys(elt, key_translations) - - return changed - - -def update(data): - """Update the data in place to remove deprecated properties. - - Args: - data (dict): dictionary to be updated - - Returns: - True if data was changed, False otherwise - """ - # translate blacklist/whitelist to exclude/include - return update_keys(data, exclude_include_translations) diff --git a/lib/spack/spack/test/cmd/module.py b/lib/spack/spack/test/cmd/module.py index d333325f4e..e60d3ab3c7 100644 --- a/lib/spack/spack/test/cmd/module.py +++ b/lib/spack/spack/test/cmd/module.py @@ -140,20 +140,16 @@ def test_find_recursive(): @pytest.mark.db -# DEPRECATED: remove blacklist in v0.20 -@pytest.mark.parametrize("config_name", ["exclude", "blacklist"]) -def test_find_recursive_excluded(database, module_configuration, config_name): - module_configuration(config_name) +def test_find_recursive_excluded(database, module_configuration): + module_configuration("exclude") module("lmod", "refresh", "-y", "--delete-tree") module("lmod", "find", "-r", "mpileaks ^mpich") @pytest.mark.db -# DEPRECATED: remove blacklist in v0.20 -@pytest.mark.parametrize("config_name", ["exclude", "blacklist"]) -def test_loads_recursive_excluded(database, module_configuration, config_name): - module_configuration(config_name) +def test_loads_recursive_excluded(database, module_configuration): + module_configuration("exclude") module("lmod", "refresh", "-y", "--delete-tree") output = module("lmod", "loads", "-r", "mpileaks ^mpich") diff --git a/lib/spack/spack/test/modules/common.py b/lib/spack/spack/test/modules/common.py index 0dc12d5bbe..77347c8d2b 100644 --- a/lib/spack/spack/test/modules/common.py +++ b/lib/spack/spack/test/modules/common.py @@ -13,7 +13,6 @@ import spack.modules.tcl import spack.package_base import spack.schema.modules import spack.spec -import spack.util.spack_yaml as syaml from spack.modules.common import UpstreamModuleIndex from spack.spec import Spec @@ -188,35 +187,3 @@ def test_load_installed_package_not_in_repo(install_mockery, mock_fetch, monkeyp assert module_path spack.package_base.PackageBase.uninstall_by_spec(spec) - - -# DEPRECATED: remove blacklist in v0.20 -@pytest.mark.parametrize( - "module_type, old_config,new_config", - [ - ("tcl", "blacklist.yaml", "exclude.yaml"), - ("tcl", "blacklist_implicits.yaml", "exclude_implicits.yaml"), - ("tcl", "blacklist_environment.yaml", "alter_environment.yaml"), - ("lmod", "blacklist.yaml", "exclude.yaml"), - ("lmod", "blacklist_environment.yaml", "alter_environment.yaml"), - ], -) -def test_exclude_include_update(module_type, old_config, new_config): - module_test_data_root = os.path.join(spack.paths.test_path, "data", "modules", module_type) - with open(os.path.join(module_test_data_root, old_config)) as f: - old_yaml = syaml.load(f) - with open(os.path.join(module_test_data_root, new_config)) as f: - new_yaml = syaml.load(f) - - # ensure file that needs updating is translated to the right thing. - assert spack.schema.modules.update_keys( - old_yaml, spack.schema.modules.exclude_include_translations - ) - assert new_yaml == old_yaml - - # ensure a file that doesn't need updates doesn't get updated - original_new_yaml = new_yaml.copy() - assert not spack.schema.modules.update_keys( - new_yaml, spack.schema.modules.exclude_include_translations - ) - original_new_yaml == new_yaml diff --git a/lib/spack/spack/test/modules/lmod.py b/lib/spack/spack/test/modules/lmod.py index 0b3d2bf597..26370d1a6e 100644 --- a/lib/spack/spack/test/modules/lmod.py +++ b/lib/spack/spack/test/modules/lmod.py @@ -124,12 +124,10 @@ class TestLmod(object): assert len([x for x in content if "depends_on(" in x]) == 5 - # DEPRECATED: remove blacklist in v0.20 - @pytest.mark.parametrize("config_name", ["alter_environment", "blacklist_environment"]) - def test_alter_environment(self, modulefile_content, module_configuration, config_name): + def test_alter_environment(self, modulefile_content, module_configuration): """Tests modifications to run-time environment.""" - module_configuration(config_name) + module_configuration("alter_environment") content = modulefile_content("mpileaks platform=test target=x86_64") assert len([x for x in content if x.startswith('prepend_path("CMAKE_PREFIX_PATH"')]) == 0 @@ -182,11 +180,9 @@ class TestLmod(object): ) assert help_msg in "".join(content) - @pytest.mark.parametrize("config_name", ["exclude", "blacklist"]) - def test_exclude(self, modulefile_content, module_configuration, config_name): + def test_exclude(self, modulefile_content, module_configuration): """Tests excluding the generation of selected modules.""" - - module_configuration(config_name) + module_configuration("exclude") content = modulefile_content(mpileaks_spec_string) assert len([x for x in content if "depends_on(" in x]) == 1 diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py index 4345d1f04f..57f7c2ba36 100644 --- a/lib/spack/spack/test/modules/tcl.py +++ b/lib/spack/spack/test/modules/tcl.py @@ -85,12 +85,10 @@ class TestTcl(object): assert len([x for x in content if "prereq" in x]) == 5 - # DEPRECATED: remove blacklist in v0.20 - @pytest.mark.parametrize("config_name", ["alter_environment", "blacklist_environment"]) - def test_alter_environment(self, modulefile_content, module_configuration, config_name): + def test_alter_environment(self, modulefile_content, module_configuration): """Tests modifications to run-time environment.""" - module_configuration(config_name) + module_configuration("alter_environment") content = modulefile_content("mpileaks platform=test target=x86_64") assert len([x for x in content if x.startswith("prepend-path CMAKE_PREFIX_PATH")]) == 0 @@ -151,11 +149,10 @@ class TestTcl(object): ) assert help_msg in "".join(content) - @pytest.mark.parametrize("config_name", ["exclude", "blacklist"]) - def test_exclude(self, modulefile_content, module_configuration, config_name): + def test_exclude(self, modulefile_content, module_configuration): """Tests excluding the generation of selected modules.""" - module_configuration(config_name) + module_configuration("exclude") content = modulefile_content("mpileaks ^zmpi") assert len([x for x in content if "module load " in x]) == 1 @@ -355,9 +352,8 @@ class TestTcl(object): @pytest.mark.regression("4400") @pytest.mark.db - @pytest.mark.parametrize("config_name", ["exclude_implicits", "blacklist_implicits"]) - def test_exclude_implicits(self, module_configuration, database, config_name): - module_configuration(config_name) + def test_exclude_implicits(self, module_configuration, database): + module_configuration("exclude_implicits") # mpileaks has been installed explicitly when setting up # the tests database @@ -374,9 +370,8 @@ class TestTcl(object): assert writer.conf.excluded @pytest.mark.regression("12105") - @pytest.mark.parametrize("config_name", ["exclude_implicits", "blacklist_implicits"]) - def test_exclude_implicits_with_arg(self, module_configuration, config_name): - module_configuration(config_name) + def test_exclude_implicits_with_arg(self, module_configuration): + module_configuration("exclude_implicits") # mpileaks is defined as explicit with explicit argument set on writer mpileaks_spec = spack.spec.Spec("mpileaks") |