show directive properly

This commit is contained in:
Harmen Stoppels 2025-02-10 10:17:22 +01:00
parent 908095e865
commit 7aaf51c36e

View File

@ -1199,19 +1199,18 @@ def _version_constraints_are_satisfiable_by_some_version_in_repo(pkgs, error_cls
def _when_conditions_are_satisfiable_by_some_version(pkgs, error_cls): def _when_conditions_are_satisfiable_by_some_version(pkgs, error_cls):
"""Report if versions in when conditions used in directives are not satisfiable""" """Report if versions in when conditions used in directives are not satisfiable"""
errors = [] errors = []
attrs = [ attrs = {
"conflicts", "conflicts": "conflicts",
"dependencies", "dependencies": "depends_on",
"languages", "licenses": "license",
"licenses", "patches": "patch",
"patches", "provided_together": "provides",
"provided_together", "provided": "provides",
"provided", "requirements": "requires",
"requirements", "resources": "resource",
"resources", "splice_specs": "can_splice",
"splice_specs", "variants": "variant",
"variants", }
]
host_architecture = spack.spec.ArchSpec.default_arch() host_architecture = spack.spec.ArchSpec.default_arch()
for pkg_name in pkgs: for pkg_name in pkgs:
pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name) pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name)
@ -1224,7 +1223,7 @@ def _when_conditions_are_satisfiable_by_some_version(pkgs, error_cls):
min(pkg_cls.versions), spack.version.StandardVersion.typemax() min(pkg_cls.versions), spack.version.StandardVersion.typemax()
) )
details = [] details = []
for attr in attrs: for attr, directive in attrs.items():
if attr == "patches": if attr == "patches":
# Patches should strictly apply to some known version # Patches should strictly apply to some known version
unsatisfiable = [ unsatisfiable = [
@ -1240,12 +1239,12 @@ def _when_conditions_are_satisfiable_by_some_version(pkgs, error_cls):
unsatisfiable = [ unsatisfiable = [
when for when in getattr(pkg_cls, attr) if not range.intersects(when.versions) when for when in getattr(pkg_cls, attr) if not range.intersects(when.versions)
] ]
details.extend(f'when="{x}"' for x in unsatisfiable) details.extend(f'{directive}(..., when="{x}")' for x in unsatisfiable)
if details: if details:
errors.append( errors.append(
error_cls( error_cls(
summary=f"{filename}: `{attr}` when conditions are not satisfiable by " summary=f"{filename}: when conditions are not satisfiable by "
f"any known version of {pkg_cls.name}", f"any known version of {pkg_cls.name}",
details=details, details=details,
) )