diff options
Diffstat (limited to 'lib/spack/spack/spec.py')
-rw-r--r-- | lib/spack/spack/spec.py | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 6238bb8c65..2cfc3c759a 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -56,7 +56,7 @@ import itertools import os import re import warnings -from typing import Tuple, Union +from typing import List, Tuple, Union import llnl.util.filesystem as fs import llnl.util.lang as lang @@ -5147,9 +5147,7 @@ class LazySpecCache(collections.defaultdict): return value -def save_dependency_specfiles( - root_spec_info, output_directory, dependencies=None, spec_format="json" -): +def save_dependency_specfiles(root: Spec, output_directory: str, dependencies: List[Spec]): """Given a root spec (represented as a yaml object), index it with a subset of its dependencies, and write each dependency to a separate yaml file in the output directory. By default, all dependencies will be written @@ -5158,26 +5156,15 @@ def save_dependency_specfiles( incoming spec is not json, that can be specified with the spec_format parameter. This can be used to convert from yaml specfiles to the json format.""" - if spec_format == "json": - root_spec = Spec.from_json(root_spec_info) - elif spec_format == "yaml": - root_spec = Spec.from_yaml(root_spec_info) - else: - raise SpecParseError("Unrecognized spec format {0}.".format(spec_format)) - dep_list = dependencies - if not dep_list: - dep_list = [dep.name for dep in root_spec.traverse()] + for spec in root.traverse(): + if not any(spec.satisfies(dep) for dep in dependencies): + continue - for dep_name in dep_list: - if dep_name not in root_spec: - msg = "Dependency {0} does not exist in root spec {1}".format(dep_name, root_spec.name) - raise SpecDependencyNotFoundError(msg) - dep_spec = root_spec[dep_name] - json_path = os.path.join(output_directory, "{0}.json".format(dep_name)) + json_path = os.path.join(output_directory, f"{spec.name}.json") with open(json_path, "w") as fd: - fd.write(dep_spec.to_json(hash=ht.dag_hash)) + fd.write(spec.to_json(hash=ht.dag_hash)) class SpecParseError(spack.error.SpecError): @@ -5398,11 +5385,6 @@ class ConflictsInSpecError(spack.error.SpecError, RuntimeError): super().__init__(message, long_message) -class SpecDependencyNotFoundError(spack.error.SpecError): - """Raised when a failure is encountered writing the dependencies of - a spec.""" - - class SpecDeprecatedError(spack.error.SpecError): """Raised when a spec concretizes to a deprecated spec or dependency.""" |