get_mark_from_yaml_data: move to spack.util.spack_yaml (#49409)
This commit is contained in:
parent
d352b71df0
commit
9f69d9b286
@ -65,6 +65,7 @@
|
|||||||
import spack.util.remote_file_cache as rfc_util
|
import spack.util.remote_file_cache as rfc_util
|
||||||
import spack.util.spack_yaml as syaml
|
import spack.util.spack_yaml as syaml
|
||||||
from spack.util.cpus import cpus_available
|
from spack.util.cpus import cpus_available
|
||||||
|
from spack.util.spack_yaml import get_mark_from_yaml_data
|
||||||
|
|
||||||
from .enums import ConfigScopePriority
|
from .enums import ConfigScopePriority
|
||||||
|
|
||||||
@ -1596,28 +1597,6 @@ def create_from(*scopes_or_paths: Union[ScopeWithOptionalPriority, str]) -> Conf
|
|||||||
return result
|
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(
|
def determine_number_of_jobs(
|
||||||
*,
|
*,
|
||||||
parallel: bool = False,
|
parallel: bool = False,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
import spack.error
|
import spack.error
|
||||||
import spack.package_base
|
import spack.package_base
|
||||||
import spack.spec
|
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):
|
class RequirementKind(enum.Enum):
|
||||||
|
@ -495,3 +495,25 @@ class SpackYAMLError(spack.error.SpackError):
|
|||||||
|
|
||||||
def __init__(self, msg, yaml_error):
|
def __init__(self, msg, yaml_error):
|
||||||
super().__init__(msg, str(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
|
||||||
|
Loading…
Reference in New Issue
Block a user