diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 28694121fba..4a578eb5521 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -65,6 +65,7 @@ import spack.util.remote_file_cache as rfc_util import spack.util.spack_yaml as syaml from spack.util.cpus import cpus_available +from spack.util.spack_yaml import get_mark_from_yaml_data from .enums import ConfigScopePriority @@ -1596,28 +1597,6 @@ def create_from(*scopes_or_paths: Union[ScopeWithOptionalPriority, str]) -> Conf return result -def get_mark_from_yaml_data(obj): - """Try to get ``spack.util.spack_yaml`` mark from YAML data. - - We try the object, and if that fails we try its first member (if it's a container). - - Returns: - mark if one is found, otherwise None. - """ - # mark of object itelf - mark = getattr(obj, "_start_mark", None) - if mark: - return mark - - # mark of first member if it is a container - if isinstance(obj, (list, dict)): - first_member = next(iter(obj), None) - if first_member: - mark = getattr(first_member, "_start_mark", None) - - return mark - - def determine_number_of_jobs( *, parallel: bool = False, diff --git a/lib/spack/spack/solver/requirements.py b/lib/spack/spack/solver/requirements.py index 6fa107e9fd0..95e383feaf9 100644 --- a/lib/spack/spack/solver/requirements.py +++ b/lib/spack/spack/solver/requirements.py @@ -10,7 +10,7 @@ import spack.error import spack.package_base import spack.spec -from spack.config import get_mark_from_yaml_data +from spack.util.spack_yaml import get_mark_from_yaml_data class RequirementKind(enum.Enum): diff --git a/lib/spack/spack/util/spack_yaml.py b/lib/spack/spack/util/spack_yaml.py index de68ddda3f7..0a1549e6d25 100644 --- a/lib/spack/spack/util/spack_yaml.py +++ b/lib/spack/spack/util/spack_yaml.py @@ -495,3 +495,25 @@ class SpackYAMLError(spack.error.SpackError): def __init__(self, msg, yaml_error): super().__init__(msg, str(yaml_error)) + + +def get_mark_from_yaml_data(obj): + """Try to get ``spack.util.spack_yaml`` mark from YAML data. + + We try the object, and if that fails we try its first member (if it's a container). + + Returns: + mark if one is found, otherwise None. + """ + # mark of object itelf + mark = getattr(obj, "_start_mark", None) + if mark: + return mark + + # mark of first member if it is a container + if isinstance(obj, (list, dict)): + first_member = next(iter(obj), None) + if first_member: + mark = getattr(first_member, "_start_mark", None) + + return mark