variant.py: reserved names is a set (#49762)

This commit is contained in:
Harmen Stoppels 2025-03-28 16:17:04 +01:00 committed by GitHub
parent f6123ee160
commit 35a84f02fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 9 deletions

View File

@ -654,7 +654,7 @@ def format_error(msg, pkg):
msg += " @*r{{[{0}, variant '{1}']}}" msg += " @*r{{[{0}, variant '{1}']}}"
return llnl.util.tty.color.colorize(msg.format(pkg.name, name)) return llnl.util.tty.color.colorize(msg.format(pkg.name, name))
if name in spack.variant.reserved_names: if name in spack.variant.RESERVED_NAMES:
def _raise_reserved_name(pkg): def _raise_reserved_name(pkg):
msg = "The name '%s' is reserved by Spack" % name msg = "The name '%s' is reserved by Spack" % name

View File

@ -1701,7 +1701,7 @@ def _add_flag(self, name, value, propagate):
Known flags currently include "arch" Known flags currently include "arch"
""" """
if propagate and name in vt.reserved_names: if propagate and name in vt.RESERVED_NAMES:
raise UnsupportedPropagationError( raise UnsupportedPropagationError(
f"Propagation with '==' is not supported for '{name}'." f"Propagation with '==' is not supported for '{name}'."
) )
@ -3014,9 +3014,8 @@ def ensure_valid_variants(spec):
# but are not necessarily recorded by the package's class # but are not necessarily recorded by the package's class
propagate_variants = [name for name, variant in spec.variants.items() if variant.propagate] propagate_variants = [name for name, variant in spec.variants.items() if variant.propagate]
not_existing = set(spec.variants) - ( not_existing = set(spec.variants)
set(pkg_variants) | set(vt.reserved_names) | set(propagate_variants) not_existing.difference_update(pkg_variants, vt.RESERVED_NAMES, propagate_variants)
)
if not_existing: if not_existing:
raise vt.UnknownVariantError( raise vt.UnknownVariantError(
@ -4659,7 +4658,7 @@ def substitute_abstract_variants(spec: Spec):
if name == "dev_path": if name == "dev_path":
spec.variants.substitute(vt.SingleValuedVariant(name, v._original_value)) spec.variants.substitute(vt.SingleValuedVariant(name, v._original_value))
continue continue
elif name in vt.reserved_names: elif name in vt.RESERVED_NAMES:
continue continue
variant_defs = spack.repo.PATH.get_pkg_class(spec.fullname).variant_definitions(name) variant_defs = spack.repo.PATH.get_pkg_class(spec.fullname).variant_definitions(name)

View File

@ -21,7 +21,7 @@
import spack.spec_parser import spack.spec_parser
#: These are variant names used by Spack internally; packages can't use them #: These are variant names used by Spack internally; packages can't use them
reserved_names = [ RESERVED_NAMES = {
"arch", "arch",
"architecture", "architecture",
"dev_path", "dev_path",
@ -31,7 +31,7 @@
"patches", "patches",
"platform", "platform",
"target", "target",
] }
special_variant_values = [None, "none", "*"] special_variant_values = [None, "none", "*"]
@ -832,7 +832,7 @@ def prevalidate_variant_value(
only if the variant is a reserved variant. only if the variant is a reserved variant.
""" """
# don't validate wildcards or variants with reserved names # don't validate wildcards or variants with reserved names
if variant.value == ("*",) or variant.name in reserved_names or variant.propagate: if variant.value == ("*",) or variant.name in RESERVED_NAMES or variant.propagate:
return [] return []
# raise if there is no definition at all # raise if there is no definition at all