summaryrefslogtreecommitdiff
path: root/lib/spack/spack/spec.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/spec.py')
-rw-r--r--lib/spack/spack/spec.py43
1 files changed, 16 insertions, 27 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index d3ec7d7157..413cb22f5f 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -99,7 +99,7 @@ __all__ = [
"CompilerSpec",
"Spec",
"SpecParseError",
- "ArchitecturePropagationError",
+ "UnsupportedPropagationError",
"DuplicateDependencyError",
"DuplicateCompilerSpecError",
"UnsupportedCompilerError",
@@ -163,14 +163,14 @@ HASH_COLOR = "@K" #: color for highlighting package hashes
DEFAULT_FORMAT = (
"{name}{@versions}"
"{%compiler.name}{@compiler.versions}{compiler_flags}"
- "{variants}{ arch=architecture}{/abstract_hash}"
+ "{variants}{ namespace=namespace_if_anonymous}{ arch=architecture}{/abstract_hash}"
)
#: Display format, which eliminates extra `@=` in the output, for readability.
DISPLAY_FORMAT = (
"{name}{@version}"
"{%compiler.name}{@compiler.version}{compiler_flags}"
- "{variants}{ arch=architecture}{/abstract_hash}"
+ "{variants}{ namespace=namespace_if_anonymous}{ arch=architecture}{/abstract_hash}"
)
#: Regular expression to pull spec contents out of clearsigned signature
@@ -1640,19 +1640,9 @@ class Spec:
Known flags currently include "arch"
"""
- # If the == syntax is used to propagate the spec architecture
- # This is an error
- architecture_names = [
- "arch",
- "architecture",
- "platform",
- "os",
- "operating_system",
- "target",
- ]
- if propagate and name in architecture_names:
- raise ArchitecturePropagationError(
- "Unable to propagate the architecture failed." " Use a '=' instead."
+ if propagate and name in spack.directives.reserved_names:
+ raise UnsupportedPropagationError(
+ f"Propagation with '==' is not supported for '{name}'."
)
valid_flags = FlagMap.valid_compiler_flags()
@@ -1666,6 +1656,8 @@ class Spec:
self._set_architecture(os=value)
elif name == "target":
self._set_architecture(target=value)
+ elif name == "namespace":
+ self.namespace = value
elif name in valid_flags:
assert self.compiler_flags is not None
flags_and_propagation = spack.compiler.tokenize_flags(value, propagate)
@@ -1685,9 +1677,7 @@ class Spec:
"""Called by the parser to set the architecture."""
arch_attrs = ["platform", "os", "target"]
if self.architecture and self.architecture.concrete:
- raise DuplicateArchitectureError(
- "Spec for '%s' cannot have two architectures." % self.name
- )
+ raise DuplicateArchitectureError("Spec cannot have two architectures.")
if not self.architecture:
new_vals = tuple(kwargs.get(arg, None) for arg in arch_attrs)
@@ -1696,10 +1686,7 @@ class Spec:
new_attrvals = [(a, v) for a, v in kwargs.items() if a in arch_attrs]
for new_attr, new_value in new_attrvals:
if getattr(self.architecture, new_attr):
- raise DuplicateArchitectureError(
- "Spec for '%s' cannot have two '%s' specified "
- "for its architecture" % (self.name, new_attr)
- )
+ raise DuplicateArchitectureError(f"Cannot specify '{new_attr}' twice")
else:
setattr(self.architecture, new_attr, new_value)
@@ -4386,6 +4373,10 @@ class Spec:
yield deps
+ @property
+ def namespace_if_anonymous(self):
+ return self.namespace if not self.name else None
+
def format(self, format_string: str = DEFAULT_FORMAT, color: Optional[bool] = False) -> str:
r"""Prints out attributes of a spec according to a format string.
@@ -5403,10 +5394,8 @@ class SpecParseError(spack.error.SpecError):
)
-class ArchitecturePropagationError(spack.error.SpecError):
- """Raised when the double equal symbols are used to assign
- the spec's architecture.
- """
+class UnsupportedPropagationError(spack.error.SpecError):
+ """Raised when propagation (==) is used with reserved variant names."""
class DuplicateDependencyError(spack.error.SpecError):