diff options
Diffstat (limited to 'lib/spack/spack/spec.py')
-rw-r--r-- | lib/spack/spack/spec.py | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 13bf66f506..85a638b602 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -54,10 +54,14 @@ import enum import io import itertools import os +import platform import re +import socket import warnings -from typing import Callable, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union +import llnl.path +import llnl.string import llnl.util.filesystem as fs import llnl.util.lang as lang import llnl.util.tty as tty @@ -82,11 +86,9 @@ import spack.util.crypto import spack.util.executable import spack.util.hash import spack.util.module_cmd as md -import spack.util.path as pth import spack.util.prefix import spack.util.spack_json as sjson import spack.util.spack_yaml as syaml -import spack.util.string import spack.variant as vt import spack.version as vn import spack.version.git_ref_lookup @@ -1390,7 +1392,7 @@ class Spec: @property def external_path(self): - return pth.path_to_os_path(self._external_path)[0] + return llnl.path.path_to_os_path(self._external_path)[0] @external_path.setter def external_path(self, ext_path): @@ -1799,7 +1801,7 @@ class Spec: @prefix.setter def prefix(self, value): - self._prefix = spack.util.prefix.Prefix(pth.convert_to_platform_path(value)) + self._prefix = spack.util.prefix.Prefix(llnl.path.convert_to_platform_path(value)) def spec_hash(self, hash): """Utility method for computing different types of Spec hashes. @@ -5148,6 +5150,43 @@ def save_dependency_specfiles(root: Spec, output_directory: str, dependencies: L fd.write(spec.to_json(hash=ht.dag_hash)) +def get_host_environment_metadata() -> Dict[str, str]: + """Get the host environment, reduce to a subset that we can store in + the install directory, and add the spack version. + """ + import spack.main + + environ = get_host_environment() + return { + "host_os": environ["os"], + "platform": environ["platform"], + "host_target": environ["target"], + "hostname": environ["hostname"], + "spack_version": spack.main.get_version(), + "kernel_version": platform.version(), + } + + +def get_host_environment() -> Dict[str, Any]: + """Return a dictionary (lookup) with host information (not including the + os.environ). + """ + host_platform = spack.platforms.host() + host_target = host_platform.target("default_target") + host_os = host_platform.operating_system("default_os") + arch_fmt = "platform={0} os={1} target={2}" + arch_spec = Spec(arch_fmt.format(host_platform, host_os, host_target)) + return { + "target": str(host_target), + "os": str(host_os), + "platform": str(host_platform), + "arch": arch_spec, + "architecture": arch_spec, + "arch_str": str(arch_spec), + "hostname": socket.gethostname(), + } + + class SpecParseError(spack.error.SpecError): """Wrapper for ParseError for when we're parsing specs.""" @@ -5208,7 +5247,7 @@ class InvalidDependencyError(spack.error.SpecError): def __init__(self, pkg, deps): self.invalid_deps = deps super().__init__( - "Package {0} does not depend on {1}".format(pkg, spack.util.string.comma_or(deps)) + "Package {0} does not depend on {1}".format(pkg, llnl.string.comma_or(deps)) ) |