From 4b02ecddf4e485a963af5126ae18c776ffe15480 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 28 Mar 2025 15:12:45 +0100 Subject: [PATCH] variant.py: use spack.error the normal way (#49763) This module references `spack.error.Something` in the same file, which happens to work but is incorrect. Use `spack.error` to prevent that in the future. --- lib/spack/spack/variant.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py index ebd0e0faa4a..6092cfdcef2 100644 --- a/lib/spack/spack/variant.py +++ b/lib/spack/spack/variant.py @@ -16,7 +16,7 @@ import llnl.util.lang as lang import llnl.util.tty.color -import spack.error as error +import spack.error import spack.spec import spack.spec_parser @@ -251,7 +251,7 @@ def convert(self, other): # We don't care if types are different as long as I can convert other to type(self) try: other = type(self)(other.name, other._original_value, propagate=other.propagate) - except (error.SpecError, ValueError): + except (spack.error.SpecError, ValueError): return False return method(self, other) @@ -626,7 +626,7 @@ def __init__(self, *sets): # 'none' is a special value and can appear only in a set of # a single element if any("none" in s and s != set(("none",)) for s in self.sets): - raise error.SpecError( + raise spack.error.SpecError( "The value 'none' represents the empty set," " and must appear alone in a set. Use the " "method 'allow_empty_set' to add it." @@ -634,7 +634,7 @@ def __init__(self, *sets): # Sets should not intersect with each other if any(s1 & s2 for s1, s2 in itertools.combinations(self.sets, 2)): - raise error.SpecError("sets in input must be disjoint") + raise spack.error.SpecError("sets in input must be disjoint") #: Attribute used to track values which correspond to #: features which can be enabled or disabled as understood by the @@ -704,7 +704,7 @@ def _disjoint_set_validator(pkg_name, variant_name, values): format_args = {"variant": variant_name, "package": pkg_name, "values": values} msg = self.error_fmt + " @*r{{[{package}, variant '{variant}']}}" msg = llnl.util.tty.color.colorize(msg.format(**format_args)) - raise error.SpecError(msg) + raise spack.error.SpecError(msg) return _disjoint_set_validator @@ -890,11 +890,11 @@ class ConditionalVariantValues(lang.TypedMutableSequence): """A list, just with a different type""" -class DuplicateVariantError(error.SpecError): +class DuplicateVariantError(spack.error.SpecError): """Raised when the same variant occurs in a spec twice.""" -class UnknownVariantError(error.SpecError): +class UnknownVariantError(spack.error.SpecError): """Raised when an unknown variant occurs in a spec.""" def __init__(self, msg: str, unknown_variants: List[str]): @@ -902,7 +902,7 @@ def __init__(self, msg: str, unknown_variants: List[str]): self.unknown_variants = unknown_variants -class InconsistentValidationError(error.SpecError): +class InconsistentValidationError(spack.error.SpecError): """Raised if the wrong validator is used to validate a variant.""" def __init__(self, vspec, variant): @@ -910,7 +910,7 @@ def __init__(self, vspec, variant): super().__init__(msg.format(vspec, variant)) -class MultipleValuesInExclusiveVariantError(error.SpecError, ValueError): +class MultipleValuesInExclusiveVariantError(spack.error.SpecError, ValueError): """Raised when multiple values are present in a variant that wants only one. """ @@ -922,15 +922,15 @@ def __init__(self, variant: AbstractVariant, pkg_name: Optional[str] = None): super().__init__(msg.format(variant, pkg_info)) -class InvalidVariantValueCombinationError(error.SpecError): +class InvalidVariantValueCombinationError(spack.error.SpecError): """Raised when a variant has values '*' or 'none' with other values.""" -class InvalidVariantValueError(error.SpecError): +class InvalidVariantValueError(spack.error.SpecError): """Raised when variants have invalid values.""" -class UnsatisfiableVariantSpecError(error.UnsatisfiableSpecError): +class UnsatisfiableVariantSpecError(spack.error.UnsatisfiableSpecError): """Raised when a spec variant conflicts with package constraints.""" def __init__(self, provided, required):