diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-01-29 16:31:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-29 16:31:50 +0100 |
commit | 890ec8d71c40a39a7018d4d7acd28d374697ce86 (patch) | |
tree | 860216a7bcd8952eb4901e89a65cd2c632a9e7cf /lib | |
parent | 62ed5ee318a41068c8e6673562f2a11055e3d1a5 (diff) | |
download | spack-890ec8d71c40a39a7018d4d7acd28d374697ce86.tar.gz spack-890ec8d71c40a39a7018d4d7acd28d374697ce86.tar.bz2 spack-890ec8d71c40a39a7018d4d7acd28d374697ce86.tar.xz spack-890ec8d71c40a39a7018d4d7acd28d374697ce86.zip |
traverse: w/o deptype (#42345)
Add the empty deptype `spack.deptypes.NONE`.
Test the case `traverse_nodes(deptype=spack.deptypes.NONE)` to not
traverse dependencies, only de-duplicate.
Use the construct in environment views that otherwise would branch on
whether deps are enabled or not.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/deptypes.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/environment/environment.py | 23 | ||||
-rw-r--r-- | lib/spack/spack/test/traverse.py | 13 |
3 files changed, 25 insertions, 14 deletions
diff --git a/lib/spack/spack/deptypes.py b/lib/spack/spack/deptypes.py index af196bd4ad..df965a87f1 100644 --- a/lib/spack/spack/deptypes.py +++ b/lib/spack/spack/deptypes.py @@ -36,6 +36,9 @@ ALL: DepFlag = BUILD | LINK | RUN | TEST #: Default dependency type if none is specified DEFAULT: DepFlag = BUILD | LINK +#: A flag with no dependency types set +NONE: DepFlag = 0 + #: An iterator of all flag components ALL_FLAGS: Tuple[DepFlag, DepFlag, DepFlag, DepFlag] = (BUILD, LINK, RUN, TEST) diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 2a6cc6e774..634c1925d3 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -21,7 +21,6 @@ from typing import Dict, Iterable, List, Optional, Set, Tuple, Union import llnl.util.filesystem as fs import llnl.util.tty as tty import llnl.util.tty.color as clr -from llnl.util.lang import dedupe from llnl.util.link_tree import ConflictingSpecsError from llnl.util.symlink import symlink @@ -663,27 +662,23 @@ class ViewDescriptor: return True - def specs_for_view(self, concretized_root_specs): + def specs_for_view(self, concrete_roots: List[Spec]) -> List[Spec]: """ From the list of concretized user specs in the environment, flatten the dags, and filter selected, installed specs, remove duplicates on dag hash. """ - # With deps, requires traversal - if self.link == "all" or self.link == "run": - deptype = ("run") if self.link == "run" else ("link", "run") - specs = list( - traverse.traverse_nodes( - concretized_root_specs, deptype=deptype, key=traverse.by_dag_hash - ) - ) + if self.link == "all": + deptype = dt.LINK | dt.RUN + elif self.link == "run": + deptype = dt.RUN else: - specs = list(dedupe(concretized_root_specs, key=traverse.by_dag_hash)) + deptype = dt.NONE + + specs = traverse.traverse_nodes(concrete_roots, deptype=deptype, key=traverse.by_dag_hash) # Filter selected, installed specs with spack.store.STORE.db.read_transaction(): - specs = [s for s in specs if s in self and s.installed] - - return specs + return [s for s in specs if s in self and s.installed] def regenerate(self, concretized_root_specs): specs = self.specs_for_view(concretized_root_specs) diff --git a/lib/spack/spack/test/traverse.py b/lib/spack/spack/test/traverse.py index 8e440f93fb..0876c65cc2 100644 --- a/lib/spack/spack/test/traverse.py +++ b/lib/spack/spack/test/traverse.py @@ -395,3 +395,16 @@ def test_traverse_edges_topo(abstract_specs_toposort): out_edge_indices = [i for (i, (parent, child)) in enumerate(edges) if node == parent] if in_edge_indices and out_edge_indices: assert max(in_edge_indices) < min(out_edge_indices) + + +def test_traverse_nodes_no_deps(abstract_specs_dtuse): + """Traversing nodes without deps should be the same as deduplicating the input specs. This may + not look useful, but can be used to avoid a branch on the call site in which it's otherwise + easy to forget to deduplicate input specs.""" + inputs = [ + abstract_specs_dtuse["dtuse"], + abstract_specs_dtuse["dtlink5"], + abstract_specs_dtuse["dtuse"], # <- duplicate + ] + outputs = [x for x in traverse.traverse_nodes(inputs, deptype=dt.NONE)] + assert outputs == [abstract_specs_dtuse["dtuse"], abstract_specs_dtuse["dtlink5"]] |