Skip to content

Commit 98b9806

Browse files
committed
DependencySpec: prepare the object to store an arbitrary number of attributes
1 parent d792424 commit 98b9806

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lib/spack/spack/spec.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class DependencySpec:
671671
virtuals: virtual packages provided from child to parent node.
672672
"""
673673

674-
__slots__ = "parent", "spec", "deptypes", "virtuals"
674+
__slots__ = "parent", "spec", "parameters"
675675

676676
def __init__(
677677
self,
@@ -683,28 +683,40 @@ def __init__(
683683
):
684684
self.parent = parent
685685
self.spec = spec
686-
self.deptypes = dp.canonical_deptype(deptypes)
687-
self.virtuals = tuple(sorted(set(virtuals)))
686+
self.parameters = {
687+
"deptypes": dp.canonical_deptype(deptypes),
688+
"virtuals": tuple(sorted(set(virtuals))),
689+
}
688690

689-
def _update_edge_property(self, property_name: str, value: Tuple[str, ...]) -> bool:
690-
current = getattr(self, property_name)
691+
@property
692+
def deptypes(self) -> Tuple[str, ...]:
693+
return self.parameters["deptypes"]
694+
695+
@property
696+
def virtuals(self) -> Tuple[str, ...]:
697+
return self.parameters["virtuals"]
698+
699+
def _update_edge_multivalued_property(
700+
self, property_name: str, value: Tuple[str, ...]
701+
) -> bool:
702+
current = self.parameters[property_name]
691703
update = set(current) | set(value)
692704
update = tuple(sorted(update))
693705
changed = current != update
694706

695707
if not changed:
696708
return False
697709

698-
setattr(self, property_name, update)
710+
self.parameters[property_name] = update
699711
return True
700712

701713
def update_deptypes(self, deptypes: Tuple[str, ...]) -> bool:
702714
"""Update the current dependency types"""
703-
return self._update_edge_property("deptypes", deptypes)
715+
return self._update_edge_multivalued_property("deptypes", deptypes)
704716

705717
def update_virtuals(self, virtuals: Tuple[str, ...]) -> bool:
706718
"""Update the list of provided virtuals"""
707-
return self._update_edge_property("virtuals", virtuals)
719+
return self._update_edge_multivalued_property("virtuals", virtuals)
708720

709721
def copy(self) -> "DependencySpec":
710722
"""Return a copy of this edge"""

0 commit comments

Comments
 (0)