Improve the error message for deprecated preferences (#41075)
Improves the warning for deprecated preferences, and adds a configuration audit to get files:lines details of the issues. Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>
This commit is contained in:
parent
d5ef4f8c83
commit
e1f98fd206
3 changed files with 53 additions and 7 deletions
|
@ -40,6 +40,7 @@ def _search_duplicate_compilers(error_cls):
|
||||||
import collections.abc
|
import collections.abc
|
||||||
import glob
|
import glob
|
||||||
import inspect
|
import inspect
|
||||||
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import pathlib
|
import pathlib
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -54,6 +55,7 @@ def _search_duplicate_compilers(error_cls):
|
||||||
import spack.repo
|
import spack.repo
|
||||||
import spack.spec
|
import spack.spec
|
||||||
import spack.util.crypto
|
import spack.util.crypto
|
||||||
|
import spack.util.spack_yaml as syaml
|
||||||
import spack.variant
|
import spack.variant
|
||||||
|
|
||||||
#: Map an audit tag to a list of callables implementing checks
|
#: Map an audit tag to a list of callables implementing checks
|
||||||
|
@ -250,6 +252,40 @@ def _search_duplicate_specs_in_externals(error_cls):
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
|
@config_packages
|
||||||
|
def _deprecated_preferences(error_cls):
|
||||||
|
"""Search package preferences deprecated in v0.21 (and slated for removal in v0.22)"""
|
||||||
|
# TODO (v0.22): remove this audit as the attributes will not be allowed in config
|
||||||
|
errors = []
|
||||||
|
packages_yaml = spack.config.CONFIG.get_config("packages")
|
||||||
|
|
||||||
|
def make_error(attribute_name, config_data, summary):
|
||||||
|
s = io.StringIO()
|
||||||
|
s.write("Occurring in the following file:\n")
|
||||||
|
dict_view = syaml.syaml_dict((k, v) for k, v in config_data.items() if k == attribute_name)
|
||||||
|
syaml.dump_config(dict_view, stream=s, blame=True)
|
||||||
|
return error_cls(summary=summary, details=[s.getvalue()])
|
||||||
|
|
||||||
|
if "all" in packages_yaml and "version" in packages_yaml["all"]:
|
||||||
|
summary = "Using the deprecated 'version' attribute under 'packages:all'"
|
||||||
|
errors.append(make_error("version", packages_yaml["all"], summary))
|
||||||
|
|
||||||
|
for package_name in packages_yaml:
|
||||||
|
if package_name == "all":
|
||||||
|
continue
|
||||||
|
|
||||||
|
package_conf = packages_yaml[package_name]
|
||||||
|
for attribute in ("compiler", "providers", "target"):
|
||||||
|
if attribute not in package_conf:
|
||||||
|
continue
|
||||||
|
summary = (
|
||||||
|
f"Using the deprecated '{attribute}' attribute " f"under 'packages:{package_name}'"
|
||||||
|
)
|
||||||
|
errors.append(make_error(attribute, package_conf, summary))
|
||||||
|
|
||||||
|
return errors
|
||||||
|
|
||||||
|
|
||||||
#: Sanity checks on package directives
|
#: Sanity checks on package directives
|
||||||
package_directives = AuditClass(
|
package_directives = AuditClass(
|
||||||
group="packages",
|
group="packages",
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
import warnings
|
||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
import llnl.util.tty.colify
|
import llnl.util.tty.colify
|
||||||
import llnl.util.tty.color as cl
|
import llnl.util.tty.color as cl
|
||||||
|
@ -52,8 +54,10 @@ def setup_parser(subparser):
|
||||||
|
|
||||||
|
|
||||||
def configs(parser, args):
|
def configs(parser, args):
|
||||||
reports = spack.audit.run_group(args.subcommand)
|
with warnings.catch_warnings():
|
||||||
_process_reports(reports)
|
warnings.simplefilter("ignore")
|
||||||
|
reports = spack.audit.run_group(args.subcommand)
|
||||||
|
_process_reports(reports)
|
||||||
|
|
||||||
|
|
||||||
def packages(parser, args):
|
def packages(parser, args):
|
||||||
|
|
|
@ -69,6 +69,8 @@
|
||||||
"patternProperties": {r"\w+": {}},
|
"patternProperties": {r"\w+": {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
REQUIREMENT_URL = "https://spack.readthedocs.io/en/latest/packages_yaml.html#package-requirements"
|
||||||
|
|
||||||
#: Properties for inclusion in other schemas
|
#: Properties for inclusion in other schemas
|
||||||
properties = {
|
properties = {
|
||||||
"packages": {
|
"packages": {
|
||||||
|
@ -117,7 +119,7 @@
|
||||||
"properties": ["version"],
|
"properties": ["version"],
|
||||||
"message": "setting version preferences in the 'all' section of packages.yaml "
|
"message": "setting version preferences in the 'all' section of packages.yaml "
|
||||||
"is deprecated and will be removed in v0.22\n\n\tThese preferences "
|
"is deprecated and will be removed in v0.22\n\n\tThese preferences "
|
||||||
"will be ignored by Spack. You can set them only in package specific sections "
|
"will be ignored by Spack. You can set them only in package-specific sections "
|
||||||
"of the same file.\n",
|
"of the same file.\n",
|
||||||
"error": False,
|
"error": False,
|
||||||
},
|
},
|
||||||
|
@ -162,10 +164,14 @@
|
||||||
},
|
},
|
||||||
"deprecatedProperties": {
|
"deprecatedProperties": {
|
||||||
"properties": ["target", "compiler", "providers"],
|
"properties": ["target", "compiler", "providers"],
|
||||||
"message": "setting compiler, target or provider preferences in a package "
|
"message": "setting 'compiler:', 'target:' or 'provider:' preferences in "
|
||||||
"specific section of packages.yaml is deprecated, and will be removed in "
|
"a package-specific section of packages.yaml is deprecated, and will be "
|
||||||
"v0.22.\n\n\tThese preferences will be ignored by Spack. You "
|
"removed in v0.22.\n\n\tThese preferences will be ignored by Spack, and "
|
||||||
"can set them only in the 'all' section of the same file.\n",
|
"can be set only in the 'all' section of the same file. "
|
||||||
|
"You can run:\n\n\t\t$ spack audit configs\n\n\tto get better diagnostics, "
|
||||||
|
"including files:lines where the deprecated attributes are used.\n\n"
|
||||||
|
"\tUse requirements to enforce conditions on specific packages: "
|
||||||
|
f"{REQUIREMENT_URL}\n",
|
||||||
"error": False,
|
"error": False,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue