Remove "blacklist" and "whitelist" from module configuration (#37432)
The sections were deprecated in v0.19
This commit is contained in:

committed by
GitHub

parent
c3593e5b48
commit
0c5a5e2ce0
@@ -59,34 +59,6 @@
|
||||
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 @@ def excluded(self):
|
||||
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 @@ def specs_to_prereq(self):
|
||||
@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 = []
|
||||
|
@@ -187,57 +187,3 @@
|
||||
"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)
|
||||
|
@@ -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")
|
||||
|
@@ -13,7 +13,6 @@
|
||||
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 find_nothing(*args):
|
||||
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
|
||||
|
@@ -124,12 +124,10 @@ def test_autoload_all(self, modulefile_content, module_configuration):
|
||||
|
||||
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 @@ def test_help_message(self, modulefile_content, module_configuration):
|
||||
)
|
||||
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
|
||||
|
@@ -85,12 +85,10 @@ def test_prerequisites_all(self, modulefile_content, module_configuration):
|
||||
|
||||
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 @@ def test_help_message(self, modulefile_content, module_configuration):
|
||||
)
|
||||
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 @@ def test_extend_context(self, modulefile_content, module_configuration):
|
||||
|
||||
@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 @@ def test_exclude_implicits(self, module_configuration, database, config_name):
|
||||
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")
|
||||
|
Reference in New Issue
Block a user