From 35a84f02fa2f75bf7ddb64a8e2af3fc3d7e99460 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 28 Mar 2025 16:17:04 +0100 Subject: [PATCH] variant.py: reserved names is a set (#49762) --- lib/spack/spack/directives.py | 2 +- lib/spack/spack/spec.py | 9 ++++----- lib/spack/spack/variant.py | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 5e8453aed3c..a70dbdb7b30 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -654,7 +654,7 @@ def format_error(msg, pkg): msg += " @*r{{[{0}, variant '{1}']}}" 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): msg = "The name '%s' is reserved by Spack" % name diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index b8b4727ac8a..eb546abbc7d 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1701,7 +1701,7 @@ def _add_flag(self, name, value, propagate): Known flags currently include "arch" """ - if propagate and name in vt.reserved_names: + if propagate and name in vt.RESERVED_NAMES: raise UnsupportedPropagationError( 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 propagate_variants = [name for name, variant in spec.variants.items() if variant.propagate] - not_existing = set(spec.variants) - ( - set(pkg_variants) | set(vt.reserved_names) | set(propagate_variants) - ) + not_existing = set(spec.variants) + not_existing.difference_update(pkg_variants, vt.RESERVED_NAMES, propagate_variants) if not_existing: raise vt.UnknownVariantError( @@ -4659,7 +4658,7 @@ def substitute_abstract_variants(spec: Spec): if name == "dev_path": spec.variants.substitute(vt.SingleValuedVariant(name, v._original_value)) continue - elif name in vt.reserved_names: + elif name in vt.RESERVED_NAMES: continue variant_defs = spack.repo.PATH.get_pkg_class(spec.fullname).variant_definitions(name) diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py index 6092cfdcef2..991dc49c8e4 100644 --- a/lib/spack/spack/variant.py +++ b/lib/spack/spack/variant.py @@ -21,7 +21,7 @@ import spack.spec_parser #: These are variant names used by Spack internally; packages can't use them -reserved_names = [ +RESERVED_NAMES = { "arch", "architecture", "dev_path", @@ -31,7 +31,7 @@ "patches", "platform", "target", -] +} special_variant_values = [None, "none", "*"] @@ -832,7 +832,7 @@ def prevalidate_variant_value( only if the variant is a reserved variant. """ # 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 [] # raise if there is no definition at all