Compare commits

..

1 Commits

Author SHA1 Message Date
Harmen Stoppels
25c74506a3 cmake.py: include transitive run deps in CMAKE_PREFIX_PATH
- Run deps often need to be located during the build
- In cases like python-venv and python, where there's a direct build dep
  on both, but python-venv has a run dep on python, meaning we'd rather
  see python-venv in path before python topologically.
2024-11-28 18:27:15 +01:00
277 changed files with 2843 additions and 3956 deletions

View File

@@ -32,4 +32,3 @@ jobs:
uses: codecov/codecov-action@05f5a9cfad807516dbbef9929c4a42df3eb78766
with:
verbose: true
fail_ci_if_error: true

View File

@@ -3,5 +3,5 @@ clingo==5.7.1
flake8==7.1.1
isort==5.13.2
mypy==1.8.0
types-six==1.17.0.20241205
types-six==1.16.21.20241105
vermin==1.6.0

View File

@@ -76,8 +76,6 @@ packages:
buildable: false
cray-mvapich2:
buildable: false
egl:
buildable: false
fujitsu-mpi:
buildable: false
hpcx-mpi:

View File

@@ -6,7 +6,7 @@ python-levenshtein==0.26.1
docutils==0.21.2
pygments==2.18.0
urllib3==2.2.3
pytest==8.3.4
pytest==8.3.3
isort==5.13.2
black==24.10.0
flake8==7.1.1

View File

@@ -2773,6 +2773,22 @@ def prefixes(path):
return paths
@system_path_filter
def md5sum(file):
"""Compute the MD5 sum of a file.
Args:
file (str): file to be checksummed
Returns:
MD5 sum of the file's content
"""
md5 = hashlib.md5()
with open(file, "rb") as f:
md5.update(f.read())
return md5.digest()
@system_path_filter
def remove_directory_contents(dir):
"""Remove all contents of a directory."""

View File

@@ -693,19 +693,19 @@ def invalid_sha256_digest(fetcher):
return h, True
return None, False
error_msg = f"Package '{pkg_name}' does not use sha256 checksum"
error_msg = "Package '{}' does not use sha256 checksum".format(pkg_name)
details = []
for v, args in pkg.versions.items():
fetcher = spack.fetch_strategy.for_package_version(pkg, v)
digest, is_bad = invalid_sha256_digest(fetcher)
if is_bad:
details.append(f"{pkg_name}@{v} uses {digest}")
details.append("{}@{} uses {}".format(pkg_name, v, digest))
for _, resources in pkg.resources.items():
for resource in resources:
digest, is_bad = invalid_sha256_digest(resource.fetcher)
if is_bad:
details.append(f"Resource in '{pkg_name}' uses {digest}")
details.append("Resource in '{}' uses {}".format(pkg_name, digest))
if details:
errors.append(error_cls(error_msg, details))

View File

@@ -40,7 +40,7 @@
import spack.hash_types as ht
import spack.hooks
import spack.hooks.sbang
import spack.mirrors.mirror
import spack.mirror
import spack.oci.image
import spack.oci.oci
import spack.oci.opener
@@ -369,7 +369,7 @@ def update(self, with_cooldown=False):
on disk under ``_index_cache_root``)."""
self._init_local_index_cache()
configured_mirror_urls = [
m.fetch_url for m in spack.mirrors.mirror.MirrorCollection(binary=True).values()
m.fetch_url for m in spack.mirror.MirrorCollection(binary=True).values()
]
items_to_remove = []
spec_cache_clear_needed = False
@@ -1176,7 +1176,7 @@ def _url_upload_tarball_and_specfile(
class Uploader:
def __init__(self, mirror: spack.mirrors.mirror.Mirror, force: bool, update_index: bool):
def __init__(self, mirror: spack.mirror.Mirror, force: bool, update_index: bool):
self.mirror = mirror
self.force = force
self.update_index = update_index
@@ -1224,7 +1224,7 @@ def tag(self, tag: str, roots: List[spack.spec.Spec]):
class OCIUploader(Uploader):
def __init__(
self,
mirror: spack.mirrors.mirror.Mirror,
mirror: spack.mirror.Mirror,
force: bool,
update_index: bool,
base_image: Optional[str],
@@ -1273,7 +1273,7 @@ def tag(self, tag: str, roots: List[spack.spec.Spec]):
class URLUploader(Uploader):
def __init__(
self,
mirror: spack.mirrors.mirror.Mirror,
mirror: spack.mirror.Mirror,
force: bool,
update_index: bool,
signing_key: Optional[str],
@@ -1297,7 +1297,7 @@ def push(
def make_uploader(
mirror: spack.mirrors.mirror.Mirror,
mirror: spack.mirror.Mirror,
force: bool = False,
update_index: bool = False,
signing_key: Optional[str] = None,
@@ -1953,9 +1953,9 @@ def download_tarball(spec, unsigned: Optional[bool] = False, mirrors_for_spec=No
"signature_verified": "true-if-binary-pkg-was-already-verified"
}
"""
configured_mirrors: Iterable[spack.mirrors.mirror.Mirror] = (
spack.mirrors.mirror.MirrorCollection(binary=True).values()
)
configured_mirrors: Iterable[spack.mirror.Mirror] = spack.mirror.MirrorCollection(
binary=True
).values()
if not configured_mirrors:
tty.die("Please add a spack mirror to allow download of pre-compiled packages.")
@@ -1980,7 +1980,7 @@ def fetch_url_to_mirror(url):
for mirror in configured_mirrors:
if mirror.fetch_url == url:
return mirror
return spack.mirrors.mirror.Mirror(url)
return spack.mirror.Mirror(url)
mirrors = [fetch_url_to_mirror(url) for url in mirror_urls]
@@ -2650,7 +2650,7 @@ def try_direct_fetch(spec, mirrors=None):
specfile_is_signed = False
found_specs = []
binary_mirrors = spack.mirrors.mirror.MirrorCollection(mirrors=mirrors, binary=True).values()
binary_mirrors = spack.mirror.MirrorCollection(mirrors=mirrors, binary=True).values()
for mirror in binary_mirrors:
buildcache_fetch_url_json = url_util.join(
@@ -2711,7 +2711,7 @@ def get_mirrors_for_spec(spec=None, mirrors_to_check=None, index_only=False):
if spec is None:
return []
if not spack.mirrors.mirror.MirrorCollection(mirrors=mirrors_to_check, binary=True):
if not spack.mirror.MirrorCollection(mirrors=mirrors_to_check, binary=True):
tty.debug("No Spack mirrors are currently configured")
return {}
@@ -2750,7 +2750,7 @@ def clear_spec_cache():
def get_keys(install=False, trust=False, force=False, mirrors=None):
"""Get pgp public keys available on mirror with suffix .pub"""
mirror_collection = mirrors or spack.mirrors.mirror.MirrorCollection(binary=True)
mirror_collection = mirrors or spack.mirror.MirrorCollection(binary=True)
if not mirror_collection:
tty.die("Please add a spack mirror to allow " + "download of build caches.")
@@ -2805,7 +2805,7 @@ def get_keys(install=False, trust=False, force=False, mirrors=None):
def _url_push_keys(
*mirrors: Union[spack.mirrors.mirror.Mirror, str],
*mirrors: Union[spack.mirror.Mirror, str],
keys: List[str],
tmpdir: str,
update_index: bool = False,
@@ -2872,7 +2872,7 @@ def check_specs_against_mirrors(mirrors, specs, output_file=None):
"""
rebuilds = {}
for mirror in spack.mirrors.mirror.MirrorCollection(mirrors, binary=True).values():
for mirror in spack.mirror.MirrorCollection(mirrors, binary=True).values():
tty.debug("Checking for built specs at {0}".format(mirror.fetch_url))
rebuild_list = []
@@ -2916,7 +2916,7 @@ def _download_buildcache_entry(mirror_root, descriptions):
def download_buildcache_entry(file_descriptions, mirror_url=None):
if not mirror_url and not spack.mirrors.mirror.MirrorCollection(binary=True):
if not mirror_url and not spack.mirror.MirrorCollection(binary=True):
tty.die(
"Please provide or add a spack mirror to allow " + "download of buildcache entries."
)
@@ -2925,7 +2925,7 @@ def download_buildcache_entry(file_descriptions, mirror_url=None):
mirror_root = os.path.join(mirror_url, BUILD_CACHE_RELATIVE_PATH)
return _download_buildcache_entry(mirror_root, file_descriptions)
for mirror in spack.mirrors.mirror.MirrorCollection(binary=True).values():
for mirror in spack.mirror.MirrorCollection(binary=True).values():
mirror_root = os.path.join(mirror.fetch_url, BUILD_CACHE_RELATIVE_PATH)
if _download_buildcache_entry(mirror_root, file_descriptions):

View File

@@ -35,10 +35,9 @@
from llnl.util.lang import GroupedExceptionHandler
import spack.binary_distribution
import spack.concretize
import spack.config
import spack.detection
import spack.mirrors.mirror
import spack.mirror
import spack.platforms
import spack.spec
import spack.store
@@ -92,7 +91,7 @@ def __init__(self, conf: ConfigDictionary) -> None:
self.metadata_dir = spack.util.path.canonicalize_path(conf["metadata"])
# Promote (relative) paths to file urls
self.url = spack.mirrors.mirror.Mirror(conf["info"]["url"]).fetch_url
self.url = spack.mirror.Mirror(conf["info"]["url"]).fetch_url
@property
def mirror_scope(self) -> spack.config.InternalConfigScope:
@@ -272,10 +271,10 @@ def try_import(self, module: str, abstract_spec_str: str) -> bool:
bootstrapper = ClingoBootstrapConcretizer(configuration=spack.config.CONFIG)
concrete_spec = bootstrapper.concretize()
else:
abstract_spec = spack.spec.Spec(
concrete_spec = spack.spec.Spec(
abstract_spec_str + " ^" + spec_for_current_python()
)
concrete_spec = spack.concretize.concretized(abstract_spec)
concrete_spec.concretize()
msg = "[BOOTSTRAP MODULE {0}] Try installing '{1}' from sources"
tty.debug(msg.format(module, abstract_spec_str))
@@ -301,7 +300,7 @@ def try_search_path(self, executables: Tuple[str], abstract_spec_str: str) -> bo
# might reduce compilation time by a fair amount
_add_externals_if_missing()
concrete_spec = spack.concretize.concretized(spack.spec.Spec(abstract_spec_str))
concrete_spec = spack.spec.Spec(abstract_spec_str).concretized()
msg = "[BOOTSTRAP] Try installing '{0}' from sources"
tty.debug(msg.format(abstract_spec_str))
with spack.config.override(self.mirror_scope):

View File

@@ -1426,20 +1426,27 @@ def make_stack(tb, stack=None):
# We found obj, the Package implementation we care about.
# Point out the location in the install method where we failed.
filename = inspect.getfile(frame.f_code)
lines = [f"{filename}:{frame.f_lineno}, in {frame.f_code.co_name}:"]
lineno = frame.f_lineno
if os.path.basename(filename) == "package.py":
# subtract 1 because we inject a magic import at the top of package files.
# TODO: get rid of the magic import.
lineno -= 1
lines = ["{0}:{1:d}, in {2}:".format(filename, lineno, frame.f_code.co_name)]
# Build a message showing context in the install method.
sourcelines, start = inspect.getsourcelines(frame)
# Calculate lineno of the error relative to the start of the function.
fun_lineno = frame.f_lineno - start
fun_lineno = lineno - start
start_ctx = max(0, fun_lineno - context)
sourcelines = sourcelines[start_ctx : fun_lineno + context + 1]
for i, line in enumerate(sourcelines):
is_error = start_ctx + i == fun_lineno
mark = ">> " if is_error else " "
# Add start to get lineno relative to start of file, not function.
marked = f" {'>> ' if is_error else ' '}{start + start_ctx + i:-6d}{line.rstrip()}"
marked = " {0}{1:-6d}{2}".format(mark, start + start_ctx + i, line.rstrip())
if is_error:
marked = colorize("@R{%s}" % cescape(marked))
lines.append(marked)

View File

@@ -170,7 +170,7 @@ def get_cmake_prefix_path(pkg: spack.package_base.PackageBase) -> List[str]:
edges = traverse.traverse_topo_edges_generator(
traverse.with_artificial_edges([pkg.spec]),
visitor=traverse.MixedDepthVisitor(
direct=dt.BUILD | dt.TEST, transitive=dt.LINK, key=traverse.by_dag_hash
direct=dt.BUILD | dt.TEST, transitive=dt.LINK | dt.RUN, key=traverse.by_dag_hash
),
key=traverse.by_dag_hash,
root=False,

View File

@@ -37,8 +37,7 @@
import spack.config as cfg
import spack.error
import spack.main
import spack.mirrors.mirror
import spack.mirrors.utils
import spack.mirror
import spack.paths
import spack.repo
import spack.spec
@@ -205,7 +204,7 @@ def _print_staging_summary(spec_labels, stages, rebuild_decisions):
if not stages:
return
mirrors = spack.mirrors.mirror.MirrorCollection(binary=True)
mirrors = spack.mirror.MirrorCollection(binary=True)
tty.msg("Checked the following mirrors for binaries:")
for m in mirrors.values():
tty.msg(f" {m.fetch_url}")
@@ -798,7 +797,7 @@ def ensure_expected_target_path(path):
path = path.replace("\\", "/")
return path
pipeline_mirrors = spack.mirrors.mirror.MirrorCollection(binary=True)
pipeline_mirrors = spack.mirror.MirrorCollection(binary=True)
buildcache_destination = None
if "buildcache-destination" not in pipeline_mirrors:
raise SpackCIError("spack ci generate requires a mirror named 'buildcache-destination'")
@@ -1324,7 +1323,7 @@ def push_to_build_cache(spec: spack.spec.Spec, mirror_url: str, sign_binaries: b
"""
tty.debug(f"Pushing to build cache ({'signed' if sign_binaries else 'unsigned'})")
signing_key = bindist.select_signing_key() if sign_binaries else None
mirror = spack.mirrors.mirror.Mirror.from_url(mirror_url)
mirror = spack.mirror.Mirror.from_url(mirror_url)
try:
with bindist.make_uploader(mirror, signing_key=signing_key) as uploader:
uploader.push_or_raise([spec])
@@ -1344,7 +1343,7 @@ def remove_other_mirrors(mirrors_to_keep, scope=None):
mirrors_to_remove.append(name)
for mirror_name in mirrors_to_remove:
spack.mirrors.utils.remove(mirror_name, scope)
spack.mirror.remove(mirror_name, scope)
def copy_files_to_artifacts(src, artifacts_dir):

View File

@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import argparse
import difflib
import importlib
import os
import re
@@ -126,8 +125,6 @@ def get_module(cmd_name):
tty.debug("Imported {0} from built-in commands".format(pname))
except ImportError:
module = spack.extensions.get_module(cmd_name)
if not module:
raise CommandNotFoundError(cmd_name)
attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op
attr_setdefault(module, DESCRIPTION, "")
@@ -199,7 +196,7 @@ def _concretize_spec_pairs(to_concretize, tests=False):
# Special case for concretizing a single spec
if len(to_concretize) == 1:
abstract, concrete = to_concretize[0]
return [concrete or spack.concretize.concretized(abstract)]
return [concrete or abstract.concretized()]
# Special case if every spec is either concrete or has an abstract hash
if all(
@@ -251,9 +248,9 @@ def matching_spec_from_env(spec):
"""
env = ev.active_environment()
if env:
return env.matching_spec(spec) or spack.concretize.concretized(spec)
return env.matching_spec(spec) or spec.concretized()
else:
return spack.concretize.concretized(spec)
return spec.concretized()
def matching_specs_from_env(specs):
@@ -694,24 +691,3 @@ def find_environment(args):
def first_line(docstring):
"""Return the first line of the docstring."""
return docstring.split("\n")[0]
class CommandNotFoundError(spack.error.SpackError):
"""Exception class thrown when a requested command is not recognized as
such.
"""
def __init__(self, cmd_name):
msg = (
f"{cmd_name} is not a recognized Spack command or extension command; "
"check with `spack commands`."
)
long_msg = None
similar = difflib.get_close_matches(cmd_name, all_commands())
if 1 <= len(similar) <= 5:
long_msg = "\nDid you mean one of the following commands?\n "
long_msg += "\n ".join(similar)
super().__init__(msg, long_msg)

View File

@@ -15,9 +15,8 @@
import spack.bootstrap
import spack.bootstrap.config
import spack.bootstrap.core
import spack.concretize
import spack.config
import spack.mirrors.utils
import spack.mirror
import spack.spec
import spack.stage
import spack.util.path
@@ -399,9 +398,9 @@ def _mirror(args):
llnl.util.tty.msg(msg.format(spec_str, mirror_dir))
# Suppress tty from the call below for terser messages
llnl.util.tty.set_msg_enabled(False)
spec = spack.concretize.concretized(spack.spec.Spec(spec_str))
spec = spack.spec.Spec(spec_str).concretized()
for node in spec.traverse():
spack.mirrors.utils.create(mirror_dir, [node])
spack.mirror.create(mirror_dir, [node])
llnl.util.tty.set_msg_enabled(True)
if args.binary_packages:

View File

@@ -17,12 +17,11 @@
import spack.binary_distribution as bindist
import spack.cmd
import spack.concretize
import spack.config
import spack.deptypes as dt
import spack.environment as ev
import spack.error
import spack.mirrors.mirror
import spack.mirror
import spack.oci.oci
import spack.spec
import spack.stage
@@ -393,7 +392,7 @@ def push_fn(args):
roots = spack.cmd.require_active_env(cmd_name="buildcache push").concrete_roots()
mirror = args.mirror
assert isinstance(mirror, spack.mirrors.mirror.Mirror)
assert isinstance(mirror, spack.mirror.Mirror)
push_url = mirror.push_url
@@ -556,7 +555,8 @@ def check_fn(args: argparse.Namespace):
tty.msg("No specs provided, exiting.")
return
specs = [spack.concretize.concretized(s) for s in specs]
for spec in specs:
spec.concretize()
# Next see if there are any configured binary mirrors
configured_mirrors = spack.config.get("mirrors", scope=args.scope)
@@ -624,7 +624,7 @@ def save_specfile_fn(args):
root = specs[0]
if not root.concrete:
root = spack.concretize.concretized(root)
root.concretize()
save_dependency_specfiles(
root, args.specfile_dir, dependencies=spack.cmd.parse_specs(args.specs)
@@ -750,7 +750,7 @@ def manifest_copy(manifest_file_list, dest_mirror=None):
copy_buildcache_file(copy_file["src"], dest)
def update_index(mirror: spack.mirrors.mirror.Mirror, update_keys=False):
def update_index(mirror: spack.mirror.Mirror, update_keys=False):
# Special case OCI images for now.
try:
image_ref = spack.oci.oci.image_from_mirror(mirror)

View File

@@ -20,7 +20,7 @@
import spack.config as cfg
import spack.environment as ev
import spack.hash_types as ht
import spack.mirrors.mirror
import spack.mirror
import spack.util.gpg as gpg_util
import spack.util.timer as timer
import spack.util.url as url_util
@@ -240,7 +240,7 @@ def ci_reindex(args):
ci_mirrors = yaml_root["mirrors"]
mirror_urls = [url for url in ci_mirrors.values()]
remote_mirror_url = mirror_urls[0]
mirror = spack.mirrors.mirror.Mirror(remote_mirror_url)
mirror = spack.mirror.Mirror(remote_mirror_url)
buildcache.update_index(mirror, update_keys=True)
@@ -328,7 +328,7 @@ def ci_rebuild(args):
full_rebuild = True if rebuild_everything and rebuild_everything.lower() == "true" else False
pipeline_mirrors = spack.mirrors.mirror.MirrorCollection(binary=True)
pipeline_mirrors = spack.mirror.MirrorCollection(binary=True)
buildcache_destination = None
if "buildcache-destination" not in pipeline_mirrors:
tty.die("spack ci rebuild requires a mirror named 'buildcache-destination")

View File

@@ -14,8 +14,7 @@
import spack.config
import spack.deptypes as dt
import spack.environment as ev
import spack.mirrors.mirror
import spack.mirrors.utils
import spack.mirror
import spack.reporters
import spack.spec
import spack.store
@@ -690,31 +689,31 @@ def mirror_name_or_url(m):
# If there's a \ or / in the name, it's interpreted as a path or url.
if "/" in m or "\\" in m or m in (".", ".."):
return spack.mirrors.mirror.Mirror(m)
return spack.mirror.Mirror(m)
# Otherwise, the named mirror is required to exist.
try:
return spack.mirrors.utils.require_mirror_name(m)
return spack.mirror.require_mirror_name(m)
except ValueError as e:
raise argparse.ArgumentTypeError(f"{e}. Did you mean {os.path.join('.', m)}?") from e
def mirror_url(url):
try:
return spack.mirrors.mirror.Mirror.from_url(url)
return spack.mirror.Mirror.from_url(url)
except ValueError as e:
raise argparse.ArgumentTypeError(str(e)) from e
def mirror_directory(path):
try:
return spack.mirrors.mirror.Mirror.from_local_path(path)
return spack.mirror.Mirror.from_local_path(path)
except ValueError as e:
raise argparse.ArgumentTypeError(str(e)) from e
def mirror_name(name):
try:
return spack.mirrors.utils.require_mirror_name(name)
return spack.mirror.require_mirror_name(name)
except ValueError as e:
raise argparse.ArgumentTypeError(str(e)) from e

View File

@@ -19,7 +19,6 @@
from llnl.util.symlink import symlink
import spack.cmd
import spack.concretize
import spack.environment as ev
import spack.installer
import spack.store
@@ -105,7 +104,7 @@ def deprecate(parser, args):
)
if args.install:
deprecator = spack.concretize.concretized(specs[1])
deprecator = specs[1].concretized()
else:
deprecator = spack.cmd.disambiguate_spec(specs[1], env, local=True)

View File

@@ -11,7 +11,6 @@
import spack.build_environment
import spack.cmd
import spack.cmd.common.arguments
import spack.concretize
import spack.config
import spack.repo
from spack.cmd.common import arguments
@@ -116,7 +115,7 @@ def dev_build(self, args):
# Forces the build to run out of the source directory.
spec.constrain("dev_path=%s" % source_path)
spec = spack.concretize.concretized(spec)
spec.concretize()
if spec.installed:
tty.error("Already installed in %s" % spec.prefix)

View File

@@ -8,7 +8,7 @@
import tempfile
import spack.binary_distribution
import spack.mirrors.mirror
import spack.mirror
import spack.paths
import spack.stage
import spack.util.gpg
@@ -217,11 +217,11 @@ def gpg_publish(args):
mirror = None
if args.directory:
url = spack.util.url.path_to_file_url(args.directory)
mirror = spack.mirrors.mirror.Mirror(url, url)
mirror = spack.mirror.Mirror(url, url)
elif args.mirror_name:
mirror = spack.mirrors.mirror.MirrorCollection(binary=True).lookup(args.mirror_name)
mirror = spack.mirror.MirrorCollection(binary=True).lookup(args.mirror_name)
elif args.mirror_url:
mirror = spack.mirrors.mirror.Mirror(args.mirror_url, args.mirror_url)
mirror = spack.mirror.Mirror(args.mirror_url, args.mirror_url)
with tempfile.TemporaryDirectory(dir=spack.stage.get_stage_root()) as tmpdir:
spack.binary_distribution._url_push_keys(

View File

@@ -14,7 +14,6 @@
from llnl.util import lang, tty
import spack.cmd
import spack.concretize
import spack.config
import spack.environment as ev
import spack.paths
@@ -452,7 +451,7 @@ def concrete_specs_from_file(args):
else:
s = spack.spec.Spec.from_json(f)
concretized = spack.concretize.concretized(s)
concretized = s.concretized()
if concretized.dag_hash() != s.dag_hash():
msg = 'skipped invalid file "{0}". '
msg += "The file does not contain a concrete spec."

View File

@@ -8,7 +8,6 @@
from llnl.path import convert_to_posix_path
import spack.concretize
import spack.paths
import spack.util.executable
from spack.spec import Spec
@@ -67,7 +66,8 @@ def make_installer(parser, args):
"""
if sys.platform == "win32":
output_dir = args.output_dir
cmake_spec = spack.concretize.concretized(Spec("cmake"))
cmake_spec = Spec("cmake")
cmake_spec.concretize()
cmake_path = os.path.join(cmake_spec.prefix, "bin", "cmake.exe")
cpack_path = os.path.join(cmake_spec.prefix, "bin", "cpack.exe")
spack_source = args.spack_source

View File

@@ -14,8 +14,7 @@
import spack.concretize
import spack.config
import spack.environment as ev
import spack.mirrors.mirror
import spack.mirrors.utils
import spack.mirror
import spack.repo
import spack.spec
import spack.util.web as web_util
@@ -366,15 +365,15 @@ def mirror_add(args):
connection["autopush"] = args.autopush
if args.signed is not None:
connection["signed"] = args.signed
mirror = spack.mirrors.mirror.Mirror(connection, name=args.name)
mirror = spack.mirror.Mirror(connection, name=args.name)
else:
mirror = spack.mirrors.mirror.Mirror(args.url, name=args.name)
spack.mirrors.utils.add(mirror, args.scope)
mirror = spack.mirror.Mirror(args.url, name=args.name)
spack.mirror.add(mirror, args.scope)
def mirror_remove(args):
"""remove a mirror by name"""
spack.mirrors.utils.remove(args.name, args.scope)
spack.mirror.remove(args.name, args.scope)
def _configure_mirror(args):
@@ -383,7 +382,7 @@ def _configure_mirror(args):
if args.name not in mirrors:
tty.die(f"No mirror found with name {args.name}.")
entry = spack.mirrors.mirror.Mirror(mirrors[args.name], args.name)
entry = spack.mirror.Mirror(mirrors[args.name], args.name)
direction = "fetch" if args.fetch else "push" if args.push else None
changes = {}
if args.url:
@@ -450,7 +449,7 @@ def mirror_set_url(args):
def mirror_list(args):
"""print out available mirrors to the console"""
mirrors = spack.mirrors.mirror.MirrorCollection(scope=args.scope)
mirrors = spack.mirror.MirrorCollection(scope=args.scope)
if not mirrors:
tty.msg("No mirrors configured.")
return
@@ -490,10 +489,10 @@ def concrete_specs_from_user(args):
def extend_with_additional_versions(specs, num_versions):
if num_versions == "all":
mirror_specs = spack.mirrors.utils.get_all_versions(specs)
mirror_specs = spack.mirror.get_all_versions(specs)
else:
mirror_specs = spack.mirrors.utils.get_matching_versions(specs, num_versions=num_versions)
mirror_specs = [spack.concretize.concretized(x) for x in mirror_specs]
mirror_specs = spack.mirror.get_matching_versions(specs, num_versions=num_versions)
mirror_specs = [x.concretized() for x in mirror_specs]
return mirror_specs
@@ -571,7 +570,7 @@ def concrete_specs_from_environment():
def all_specs_with_all_versions():
specs = [spack.spec.Spec(n) for n in spack.repo.all_package_names()]
mirror_specs = spack.mirrors.utils.get_all_versions(specs)
mirror_specs = spack.mirror.get_all_versions(specs)
mirror_specs.sort(key=lambda s: (s.name, s.version))
return mirror_specs
@@ -660,21 +659,19 @@ def _specs_and_action(args):
def create_mirror_for_all_specs(mirror_specs, path, skip_unstable_versions):
mirror_cache, mirror_stats = spack.mirrors.utils.mirror_cache_and_stats(
mirror_cache, mirror_stats = spack.mirror.mirror_cache_and_stats(
path, skip_unstable_versions=skip_unstable_versions
)
for candidate in mirror_specs:
pkg_cls = spack.repo.PATH.get_pkg_class(candidate.name)
pkg_obj = pkg_cls(spack.spec.Spec(candidate))
mirror_stats.next_spec(pkg_obj.spec)
spack.mirrors.utils.create_mirror_from_package_object(pkg_obj, mirror_cache, mirror_stats)
spack.mirror.create_mirror_from_package_object(pkg_obj, mirror_cache, mirror_stats)
process_mirror_stats(*mirror_stats.stats())
def create_mirror_for_individual_specs(mirror_specs, path, skip_unstable_versions):
present, mirrored, error = spack.mirrors.utils.create(
path, mirror_specs, skip_unstable_versions
)
present, mirrored, error = spack.mirror.create(path, mirror_specs, skip_unstable_versions)
tty.msg("Summary for mirror in {}".format(path))
process_mirror_stats(present, mirrored, error)
@@ -684,7 +681,7 @@ def mirror_destroy(args):
mirror_url = None
if args.mirror_name:
result = spack.mirrors.mirror.MirrorCollection().lookup(args.mirror_name)
result = spack.mirror.MirrorCollection().lookup(args.mirror_name)
mirror_url = result.push_url
elif args.mirror_url:
mirror_url = args.mirror_url

View File

@@ -323,6 +323,8 @@ def process_files(file_list, is_args):
rewrite_and_print_output(output, args, pat, replacement)
packages_isort_args = (
"--rm",
"spack",
"--rm",
"spack.pkgkit",
"--rm",

View File

@@ -51,10 +51,11 @@ def concretize_specs_together(
tests: list of package names for which to consider tests dependencies. If True, all nodes
will have test dependencies. If False, test dependencies will be disregarded.
"""
from spack.solver.asp import Solver
import spack.solver.asp
allow_deprecated = spack.config.get("config:deprecated", False)
result = Solver().solve(abstract_specs, tests=tests, allow_deprecated=allow_deprecated)
solver = spack.solver.asp.Solver()
result = solver.solve(abstract_specs, tests=tests, allow_deprecated=allow_deprecated)
return [s.copy() for s in result.specs]
@@ -89,7 +90,7 @@ def concretize_together_when_possible(
tests: list of package names for which to consider tests dependencies. If True, all nodes
will have test dependencies. If False, test dependencies will be disregarded.
"""
from spack.solver.asp import Solver
import spack.solver.asp
to_concretize = [concrete if concrete else abstract for abstract, concrete in spec_list]
old_concrete_to_abstract = {
@@ -97,8 +98,9 @@ def concretize_together_when_possible(
}
result_by_user_spec = {}
solver = spack.solver.asp.Solver()
allow_deprecated = spack.config.get("config:deprecated", False)
for result in Solver().solve_in_rounds(
for result in solver.solve_in_rounds(
to_concretize, tests=tests, allow_deprecated=allow_deprecated
):
result_by_user_spec.update(result.specs_by_input)
@@ -122,7 +124,7 @@ def concretize_separately(
tests: list of package names for which to consider tests dependencies. If True, all nodes
will have test dependencies. If False, test dependencies will be disregarded.
"""
from spack.bootstrap import ensure_bootstrap_configuration, ensure_clingo_importable_or_raise
import spack.bootstrap
to_concretize = [abstract for abstract, concrete in spec_list if not concrete]
args = [
@@ -132,8 +134,8 @@ def concretize_separately(
]
ret = [(i, abstract) for i, abstract in enumerate(to_concretize) if abstract.concrete]
# Ensure we don't try to bootstrap clingo in parallel
with ensure_bootstrap_configuration():
ensure_clingo_importable_or_raise()
with spack.bootstrap.ensure_bootstrap_configuration():
spack.bootstrap.ensure_clingo_importable_or_raise()
# Ensure all the indexes have been built or updated, since
# otherwise the processes in the pool may timeout on waiting
@@ -188,50 +190,10 @@ def _concretize_task(packed_arguments: Tuple[int, str, TestsType]) -> Tuple[int,
index, spec_str, tests = packed_arguments
with tty.SuppressOutput(msg_enabled=False):
start = time.time()
spec = concretized(Spec(spec_str), tests=tests)
spec = Spec(spec_str).concretized(tests=tests)
return index, spec, time.time() - start
def concretized(spec: Spec, tests: Union[bool, Iterable[str]] = False) -> Spec:
"""Return a concretized copy of the given spec.
Args:
tests: if False disregard 'test' dependencies, if a list of names activate them for
the packages in the list, if True activate 'test' dependencies for all packages.
"""
from spack.solver.asp import Solver, SpecBuilder
spec.replace_hash()
for node in spec.traverse():
if not node.name:
raise spack.error.SpecError(
f"Spec {node} has no name; cannot concretize an anonymous spec"
)
if spec._concrete:
return spec.copy()
allow_deprecated = spack.config.get("config:deprecated", False)
result = Solver().solve([spec], tests=tests, allow_deprecated=allow_deprecated)
# take the best answer
opt, i, answer = min(result.answers)
name = spec.name
# TODO: Consolidate this code with similar code in solve.py
if spec.virtual:
providers = [s.name for s in answer.values() if s.package.provides(name)]
name = providers[0]
node = SpecBuilder.make_node(pkg=name)
assert (
node in answer
), f"cannot find {name} in the list of specs {','.join([n.pkg for n in answer.keys()])}"
concretized = answer[node]
return concretized
class UnavailableCompilerVersionError(spack.error.SpackError):
"""Raised when there is no available compiler that satisfies a
compiler spec."""

View File

@@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
"""Data structures that represent Spack's dependency relationships."""
from typing import Dict, List, Type
from typing import Dict, List
import spack.deptypes as dt
import spack.spec
@@ -38,7 +38,7 @@ class Dependency:
def __init__(
self,
pkg: Type["spack.package_base.PackageBase"],
pkg: "spack.package_base.PackageBase",
spec: "spack.spec.Spec",
depflag: dt.DepFlag = dt.DEFAULT,
):

View File

@@ -21,7 +21,6 @@ class OpenMpi(Package):
* ``conflicts``
* ``depends_on``
* ``extends``
* ``license``
* ``patch``
* ``provides``
* ``resource``
@@ -35,12 +34,11 @@ class OpenMpi(Package):
import collections.abc
import os.path
import re
from typing import Any, Callable, List, Optional, Tuple, Type, Union
from typing import Any, Callable, List, Optional, Tuple, Union
import llnl.util.tty.color
import spack.deptypes as dt
import spack.fetch_strategy
import spack.package_base
import spack.patch
import spack.spec
@@ -48,6 +46,7 @@ class OpenMpi(Package):
import spack.variant
from spack.dependency import Dependency
from spack.directives_meta import DirectiveError, DirectiveMeta
from spack.fetch_strategy import from_kwargs
from spack.resource import Resource
from spack.version import (
GitVersion,
@@ -82,8 +81,8 @@ class OpenMpi(Package):
SpecType = str
DepType = Union[Tuple[str, ...], str]
WhenType = Optional[Union[spack.spec.Spec, str, bool]]
Patcher = Callable[[Union[Type[spack.package_base.PackageBase], Dependency]], None]
PatchesType = Union[Patcher, str, List[Union[Patcher, str]]]
Patcher = Callable[[Union[spack.package_base.PackageBase, Dependency]], None]
PatchesType = Optional[Union[Patcher, str, List[Union[Patcher, str]]]]
SUPPORTED_LANGUAGES = ("fortran", "cxx", "c")
@@ -219,7 +218,7 @@ def version(
return lambda pkg: _execute_version(pkg, ver, **kwargs)
def _execute_version(pkg: Type[spack.package_base.PackageBase], ver: Union[str, int], **kwargs):
def _execute_version(pkg, ver, **kwargs):
if (
(any(s in kwargs for s in spack.util.crypto.hashes) or "checksum" in kwargs)
and hasattr(pkg, "has_code")
@@ -250,12 +249,12 @@ def _execute_version(pkg: Type[spack.package_base.PackageBase], ver: Union[str,
def _depends_on(
pkg: Type[spack.package_base.PackageBase],
pkg: spack.package_base.PackageBase,
spec: spack.spec.Spec,
*,
when: WhenType = None,
type: DepType = dt.DEFAULT_TYPES,
patches: Optional[PatchesType] = None,
patches: PatchesType = None,
):
when_spec = _make_when_spec(when)
if not when_spec:
@@ -330,7 +329,7 @@ def conflicts(conflict_spec: SpecType, when: WhenType = None, msg: Optional[str]
msg (str): optional user defined message
"""
def _execute_conflicts(pkg: Type[spack.package_base.PackageBase]):
def _execute_conflicts(pkg: spack.package_base.PackageBase):
# If when is not specified the conflict always holds
when_spec = _make_when_spec(when)
if not when_spec:
@@ -349,7 +348,7 @@ def depends_on(
spec: SpecType,
when: WhenType = None,
type: DepType = dt.DEFAULT_TYPES,
patches: Optional[PatchesType] = None,
patches: PatchesType = None,
):
"""Creates a dict of deps with specs defining when they apply.
@@ -371,16 +370,14 @@ def depends_on(
assert type == "build", "languages must be of 'build' type"
return _language(lang_spec_str=spec, when=when)
def _execute_depends_on(pkg: Type[spack.package_base.PackageBase]):
def _execute_depends_on(pkg: spack.package_base.PackageBase):
_depends_on(pkg, dep_spec, when=when, type=type, patches=patches)
return _execute_depends_on
@directive("disable_redistribute")
def redistribute(
source: Optional[bool] = None, binary: Optional[bool] = None, when: WhenType = None
):
def redistribute(source=None, binary=None, when: WhenType = None):
"""Can be used inside a Package definition to declare that
the package source and/or compiled binaries should not be
redistributed.
@@ -395,10 +392,7 @@ def redistribute(
def _execute_redistribute(
pkg: Type[spack.package_base.PackageBase],
source: Optional[bool],
binary: Optional[bool],
when: WhenType,
pkg: spack.package_base.PackageBase, source=None, binary=None, when: WhenType = None
):
if source is None and binary is None:
return
@@ -474,7 +468,9 @@ def provides(*specs: SpecType, when: WhenType = None):
when: condition when this provides clause needs to be considered
"""
def _execute_provides(pkg: Type[spack.package_base.PackageBase]):
def _execute_provides(pkg: spack.package_base.PackageBase):
import spack.parser # Avoid circular dependency
when_spec = _make_when_spec(when)
if not when_spec:
return
@@ -520,7 +516,7 @@ def can_splice(
variants will be skipped by '*'.
"""
def _execute_can_splice(pkg: Type[spack.package_base.PackageBase]):
def _execute_can_splice(pkg: spack.package_base.PackageBase):
when_spec = _make_when_spec(when)
if isinstance(match_variants, str) and match_variants != "*":
raise ValueError(
@@ -561,10 +557,10 @@ def patch(
compressed URL patches)
"""
def _execute_patch(
pkg_or_dep: Union[Type[spack.package_base.PackageBase], Dependency]
) -> None:
pkg = pkg_or_dep.pkg if isinstance(pkg_or_dep, Dependency) else pkg_or_dep
def _execute_patch(pkg_or_dep: Union[spack.package_base.PackageBase, Dependency]):
pkg = pkg_or_dep
if isinstance(pkg, Dependency):
pkg = pkg.pkg
if hasattr(pkg, "has_code") and not pkg.has_code:
raise UnsupportedPackageDirective(
@@ -738,55 +734,58 @@ def _execute_variant(pkg):
@directive("resources")
def resource(
*,
name: Optional[str] = None,
destination: str = "",
placement: Optional[str] = None,
when: WhenType = None,
# additional kwargs are as for `version()`
**kwargs,
):
"""Define an external resource to be fetched and staged when building the package.
Based on the keywords present in the dictionary the appropriate FetchStrategy will
be used for the resource. Resources are fetched and staged in their own folder
inside spack stage area, and then moved into the stage area of the package that
needs them.
def resource(**kwargs):
"""Define an external resource to be fetched and staged when building the
package. Based on the keywords present in the dictionary the appropriate
FetchStrategy will be used for the resource. Resources are fetched and
staged in their own folder inside spack stage area, and then moved into
the stage area of the package that needs them.
Keyword Arguments:
name: name for the resource
when: condition defining when the resource is needed
destination: path, relative to the package stage area, to which resource should be moved
placement: optionally rename the expanded resource inside the destination directory
List of recognized keywords:
* 'when' : (optional) represents the condition upon which the resource is
needed
* 'destination' : (optional) path where to move the resource. This path
must be relative to the main package stage area.
* 'placement' : (optional) gives the possibility to fine tune how the
resource is moved into the main package stage area.
"""
def _execute_resource(pkg):
when = kwargs.get("when")
when_spec = _make_when_spec(when)
if not when_spec:
return
destination = kwargs.get("destination", "")
placement = kwargs.get("placement", None)
# Check if the path is relative
if os.path.isabs(destination):
msg = "The destination keyword of a resource directive can't be an absolute path.\n"
msg += f"\tdestination : '{destination}\n'"
raise RuntimeError(msg)
message = (
"The destination keyword of a resource directive " "can't be an absolute path.\n"
)
message += "\tdestination : '{dest}\n'".format(dest=destination)
raise RuntimeError(message)
# Check if the path falls within the main package stage area
test_path = "stage_folder_root"
# Normalized absolute path
normalized_destination = os.path.normpath(os.path.join(test_path, destination))
normalized_destination = os.path.normpath(
os.path.join(test_path, destination)
) # Normalized absolute path
if test_path not in normalized_destination:
msg = "Destination of a resource must be within the package stage directory.\n"
msg += f"\tdestination : '{destination}'\n"
raise RuntimeError(msg)
message = (
"The destination folder of a resource must fall "
"within the main package stage directory.\n"
)
message += "\tdestination : '{dest}'\n".format(dest=destination)
raise RuntimeError(message)
resources = pkg.resources.setdefault(when_spec, [])
resources.append(
Resource(name, spack.fetch_strategy.from_kwargs(**kwargs), destination, placement)
)
name = kwargs.get("name")
fetcher = from_kwargs(**kwargs)
resources.append(Resource(name, fetcher, destination, placement))
return _execute_resource
@@ -818,9 +817,7 @@ def _execute_maintainer(pkg):
return _execute_maintainer
def _execute_license(
pkg: Type[spack.package_base.PackageBase], license_identifier: str, when: WhenType
):
def _execute_license(pkg, license_identifier: str, when):
# If when is not specified the license always holds
when_spec = _make_when_spec(when)
if not when_spec:
@@ -884,7 +881,7 @@ def requires(*requirement_specs: str, policy="one_of", when=None, msg=None):
msg: optional user defined message
"""
def _execute_requires(pkg: Type[spack.package_base.PackageBase]):
def _execute_requires(pkg: spack.package_base.PackageBase):
if policy not in ("one_of", "any_of"):
err_msg = (
f"the 'policy' argument of the 'requires' directive in {pkg.name} is set "
@@ -909,7 +906,7 @@ def _execute_requires(pkg: Type[spack.package_base.PackageBase]):
def _language(lang_spec_str: str, *, when: Optional[Union[str, bool]] = None):
"""Temporary implementation of language virtuals, until compilers are proper dependencies."""
def _execute_languages(pkg: Type[spack.package_base.PackageBase]):
def _execute_languages(pkg: spack.package_base.PackageBase):
when_spec = _make_when_spec(when)
if not when_spec:
return

View File

@@ -5,7 +5,7 @@
import collections.abc
import functools
from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Type, Union
from typing import List, Set
import llnl.util.lang
@@ -25,13 +25,11 @@ class DirectiveMeta(type):
# Set of all known directives
_directive_dict_names: Set[str] = set()
_directives_to_be_executed: List[Callable] = []
_when_constraints_from_context: List[spack.spec.Spec] = []
_directives_to_be_executed: List[str] = []
_when_constraints_from_context: List[str] = []
_default_args: List[dict] = []
def __new__(
cls: Type["DirectiveMeta"], name: str, bases: tuple, attr_dict: dict
) -> "DirectiveMeta":
def __new__(cls, name, bases, attr_dict):
# Initialize the attribute containing the list of directives
# to be executed. Here we go reversed because we want to execute
# commands:
@@ -62,7 +60,7 @@ def __new__(
return super(DirectiveMeta, cls).__new__(cls, name, bases, attr_dict)
def __init__(cls: "DirectiveMeta", name: str, bases: tuple, attr_dict: dict):
def __init__(cls, name, bases, attr_dict):
# The instance is being initialized: if it is a package we must ensure
# that the directives are called to set it up.
@@ -83,27 +81,27 @@ def __init__(cls: "DirectiveMeta", name: str, bases: tuple, attr_dict: dict):
super(DirectiveMeta, cls).__init__(name, bases, attr_dict)
@staticmethod
def push_to_context(when_spec: spack.spec.Spec) -> None:
def push_to_context(when_spec):
"""Add a spec to the context constraints."""
DirectiveMeta._when_constraints_from_context.append(when_spec)
@staticmethod
def pop_from_context() -> spack.spec.Spec:
def pop_from_context():
"""Pop the last constraint from the context"""
return DirectiveMeta._when_constraints_from_context.pop()
@staticmethod
def push_default_args(default_args: Dict[str, Any]) -> None:
def push_default_args(default_args):
"""Push default arguments"""
DirectiveMeta._default_args.append(default_args)
@staticmethod
def pop_default_args() -> dict:
def pop_default_args():
"""Pop default arguments"""
return DirectiveMeta._default_args.pop()
@staticmethod
def directive(dicts: Optional[Union[Sequence[str], str]] = None) -> Callable:
def directive(dicts=None):
"""Decorator for Spack directives.
Spack directives allow you to modify a package while it is being
@@ -158,7 +156,7 @@ class Foo(Package):
DirectiveMeta._directive_dict_names |= set(dicts)
# This decorator just returns the directive functions
def _decorator(decorated_function: Callable) -> Callable:
def _decorator(decorated_function):
directive_names.append(decorated_function.__name__)
@functools.wraps(decorated_function)

View File

@@ -192,10 +192,3 @@ def __reduce__(self):
def _make_stop_phase(msg, long_msg):
return StopPhase(msg, long_msg)
class MirrorError(SpackError):
"""Superclass of all mirror-creation related errors."""
def __init__(self, msg, long_msg=None):
super().__init__(msg, long_msg)

View File

@@ -5,6 +5,7 @@
"""Service functions and classes to implement the hooks
for Spack's command extensions.
"""
import difflib
import glob
import importlib
import os
@@ -16,6 +17,7 @@
import llnl.util.lang
import spack.cmd
import spack.config
import spack.error
import spack.util.path
@@ -23,6 +25,9 @@
_extension_regexp = re.compile(r"spack-(\w[-\w]*)$")
# TODO: For consistency we should use spack.cmd.python_name(), but
# currently this would create a circular relationship between
# spack.cmd and spack.extensions.
def _python_name(cmd_name):
return cmd_name.replace("-", "_")
@@ -206,7 +211,8 @@ def get_module(cmd_name):
module = load_command_extension(cmd_name, folder)
if module:
return module
return None
else:
raise CommandNotFoundError(cmd_name)
def get_template_dirs():
@@ -218,6 +224,27 @@ def get_template_dirs():
return extensions
class CommandNotFoundError(spack.error.SpackError):
"""Exception class thrown when a requested command is not recognized as
such.
"""
def __init__(self, cmd_name):
msg = (
"{0} is not a recognized Spack command or extension command;"
" check with `spack commands`.".format(cmd_name)
)
long_msg = None
similar = difflib.get_close_matches(cmd_name, spack.cmd.all_commands())
if 1 <= len(similar) <= 5:
long_msg = "\nDid you mean one of the following commands?\n "
long_msg += "\n ".join(similar)
super().__init__(msg, long_msg)
class ExtensionNamingError(spack.error.SpackError):
"""Exception class thrown when a configured extension does not follow
the expected naming convention.

View File

@@ -6,7 +6,7 @@
import llnl.util.tty as tty
import spack.binary_distribution as bindist
import spack.mirrors.mirror
import spack.mirror
def post_install(spec, explicit):
@@ -22,7 +22,7 @@ def post_install(spec, explicit):
return
# Push the package to all autopush mirrors
for mirror in spack.mirrors.mirror.MirrorCollection(binary=True, autopush=True).values():
for mirror in spack.mirror.MirrorCollection(binary=True, autopush=True).values():
signing_key = bindist.select_signing_key() if mirror.signed else None
with bindist.make_uploader(mirror=mirror, force=True, signing_key=signing_key) as uploader:
uploader.push_or_raise([spec])

View File

@@ -56,7 +56,7 @@
import spack.deptypes as dt
import spack.error
import spack.hooks
import spack.mirrors.mirror
import spack.mirror
import spack.package_base
import spack.package_prefs as prefs
import spack.repo
@@ -491,7 +491,7 @@ def _try_install_from_binary_cache(
timer: timer to keep track of binary install phases.
"""
# Early exit if no binary mirrors are configured.
if not spack.mirrors.mirror.MirrorCollection(binary=True):
if not spack.mirror.MirrorCollection(binary=True):
return False
tty.debug(f"Searching for binary cache of {package_id(pkg.spec)}")

View File

@@ -2,20 +2,42 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
"""
This file contains code for creating spack mirror directories. A
mirror is an organized hierarchy containing specially named archive
files. This enabled spack to know where to find files in a mirror if
the main server for a particular package is down. Or, if the computer
where spack is run is not connected to the internet, it allows spack
to download packages directly from a mirror (e.g., on an intranet).
"""
import collections
import collections.abc
import operator
import os
import os.path
import sys
import traceback
import urllib.parse
from typing import Any, Dict, Optional, Tuple, Union
import llnl.url
import llnl.util.symlink
import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp
import spack.caches
import spack.config
import spack.error
import spack.fetch_strategy
import spack.mirror
import spack.oci.image
import spack.repo
import spack.spec
import spack.util.path
import spack.util.spack_json as sjson
import spack.util.spack_yaml as syaml
import spack.util.url as url_util
from spack.error import MirrorError
import spack.version
#: What schemes do we support
supported_url_schemes = ("file", "http", "https", "sftp", "ftp", "s3", "gs", "oci")
@@ -468,3 +490,380 @@ def __iter__(self):
def __len__(self):
return len(self._mirrors)
def _determine_extension(fetcher):
if isinstance(fetcher, spack.fetch_strategy.URLFetchStrategy):
if fetcher.expand_archive:
# If we fetch with a URLFetchStrategy, use URL's archive type
ext = llnl.url.determine_url_file_extension(fetcher.url)
if ext:
# Remove any leading dots
ext = ext.lstrip(".")
else:
msg = """\
Unable to parse extension from {0}.
If this URL is for a tarball but does not include the file extension
in the name, you can explicitly declare it with the following syntax:
version('1.2.3', 'hash', extension='tar.gz')
If this URL is for a download like a .jar or .whl that does not need
to be expanded, or an uncompressed installation script, you can tell
Spack not to expand it with the following syntax:
version('1.2.3', 'hash', expand=False)
"""
raise MirrorError(msg.format(fetcher.url))
else:
# If the archive shouldn't be expanded, don't check extension.
ext = None
else:
# Otherwise we'll make a .tar.gz ourselves
ext = "tar.gz"
return ext
class MirrorLayout:
"""A ``MirrorLayout`` object describes the relative path of a mirror entry."""
def __init__(self, path: str) -> None:
self.path = path
def __iter__(self):
"""Yield all paths including aliases where the resource can be found."""
yield self.path
def make_alias(self, root: str) -> None:
"""Make the entry ``root / self.path`` available under a human readable alias"""
pass
class DefaultLayout(MirrorLayout):
def __init__(self, alias_path: str, digest_path: Optional[str] = None) -> None:
# When we have a digest, it is used as the primary storage location. If not, then we use
# the human-readable alias. In case of mirrors of a VCS checkout, we currently do not have
# a digest, that's why an alias is required and a digest optional.
super().__init__(path=digest_path or alias_path)
self.alias = alias_path
self.digest_path = digest_path
def make_alias(self, root: str) -> None:
"""Symlink a human readible path in our mirror to the actual storage location."""
# We already use the human-readable path as the main storage location.
if not self.digest_path:
return
alias, digest = os.path.join(root, self.alias), os.path.join(root, self.digest_path)
alias_dir = os.path.dirname(alias)
relative_dst = os.path.relpath(digest, start=alias_dir)
mkdirp(alias_dir)
tmp = f"{alias}.tmp"
llnl.util.symlink.symlink(relative_dst, tmp)
try:
os.rename(tmp, alias)
except OSError:
# Clean up the temporary if possible
try:
os.unlink(tmp)
except OSError:
pass
raise
def __iter__(self):
if self.digest_path:
yield self.digest_path
yield self.alias
class OCILayout(MirrorLayout):
"""Follow the OCI Image Layout Specification to archive blobs where paths are of the form
``blobs/<algorithm>/<digest>``"""
def __init__(self, digest: spack.oci.image.Digest) -> None:
super().__init__(os.path.join("blobs", digest.algorithm, digest.digest))
def default_mirror_layout(
fetcher: "spack.fetch_strategy.FetchStrategy",
per_package_ref: str,
spec: Optional["spack.spec.Spec"] = None,
) -> MirrorLayout:
"""Returns a ``MirrorReference`` object which keeps track of the relative
storage path of the resource associated with the specified ``fetcher``."""
ext = None
if spec:
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
versions = pkg_cls.versions.get(spec.version, {})
ext = versions.get("extension", None)
# If the spec does not explicitly specify an extension (the default case),
# then try to determine it automatically. An extension can only be
# specified for the primary source of the package (e.g. the source code
# identified in the 'version' declaration). Resources/patches don't have
# an option to specify an extension, so it must be inferred for those.
ext = ext or _determine_extension(fetcher)
if ext:
per_package_ref += ".%s" % ext
global_ref = fetcher.mirror_id()
if global_ref:
global_ref = os.path.join("_source-cache", global_ref)
if global_ref and ext:
global_ref += ".%s" % ext
return DefaultLayout(per_package_ref, global_ref)
def get_all_versions(specs):
"""Given a set of initial specs, return a new set of specs that includes
each version of each package in the original set.
Note that if any spec in the original set specifies properties other than
version, this information will be omitted in the new set; for example; the
new set of specs will not include variant settings.
"""
version_specs = []
for spec in specs:
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
# Skip any package that has no known versions.
if not pkg_cls.versions:
tty.msg("No safe (checksummed) versions for package %s" % pkg_cls.name)
continue
for version in pkg_cls.versions:
version_spec = spack.spec.Spec(pkg_cls.name)
version_spec.versions = spack.version.VersionList([version])
version_specs.append(version_spec)
return version_specs
def get_matching_versions(specs, num_versions=1):
"""Get a spec for EACH known version matching any spec in the list.
For concrete specs, this retrieves the concrete version and, if more
than one version per spec is requested, retrieves the latest versions
of the package.
"""
matching = []
for spec in specs:
pkg = spec.package
# Skip any package that has no known versions.
if not pkg.versions:
tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
continue
pkg_versions = num_versions
version_order = list(reversed(sorted(pkg.versions)))
matching_spec = []
if spec.concrete:
matching_spec.append(spec)
pkg_versions -= 1
if spec.version in version_order:
version_order.remove(spec.version)
for v in version_order:
# Generate no more than num_versions versions for each spec.
if pkg_versions < 1:
break
# Generate only versions that satisfy the spec.
if spec.concrete or v.intersects(spec.versions):
s = spack.spec.Spec(pkg.name)
s.versions = spack.version.VersionList([v])
s.variants = spec.variants.copy()
# This is needed to avoid hanging references during the
# concretization phase
s.variants.spec = s
matching_spec.append(s)
pkg_versions -= 1
if not matching_spec:
tty.warn("No known version matches spec: %s" % spec)
matching.extend(matching_spec)
return matching
def create(path, specs, skip_unstable_versions=False):
"""Create a directory to be used as a spack mirror, and fill it with
package archives.
Arguments:
path: Path to create a mirror directory hierarchy in.
specs: Any package versions matching these specs will be added \
to the mirror.
skip_unstable_versions: if true, this skips adding resources when
they do not have a stable archive checksum (as determined by
``fetch_strategy.stable_target``)
Return Value:
Returns a tuple of lists: (present, mirrored, error)
* present: Package specs that were already present.
* mirrored: Package specs that were successfully mirrored.
* error: Package specs that failed to mirror due to some error.
"""
# automatically spec-ify anything in the specs array.
specs = [s if isinstance(s, spack.spec.Spec) else spack.spec.Spec(s) for s in specs]
mirror_cache, mirror_stats = mirror_cache_and_stats(path, skip_unstable_versions)
for spec in specs:
mirror_stats.next_spec(spec)
create_mirror_from_package_object(spec.package, mirror_cache, mirror_stats)
return mirror_stats.stats()
def mirror_cache_and_stats(path, skip_unstable_versions=False):
"""Return both a mirror cache and a mirror stats, starting from the path
where a mirror ought to be created.
Args:
path (str): path to create a mirror directory hierarchy in.
skip_unstable_versions: if true, this skips adding resources when
they do not have a stable archive checksum (as determined by
``fetch_strategy.stable_target``)
"""
# Get the absolute path of the root before we start jumping around.
if not os.path.isdir(path):
try:
mkdirp(path)
except OSError as e:
raise MirrorError("Cannot create directory '%s':" % path, str(e))
mirror_cache = spack.caches.MirrorCache(path, skip_unstable_versions=skip_unstable_versions)
mirror_stats = MirrorStats()
return mirror_cache, mirror_stats
def add(mirror: Mirror, scope=None):
"""Add a named mirror in the given scope"""
mirrors = spack.config.get("mirrors", scope=scope)
if not mirrors:
mirrors = syaml.syaml_dict()
if mirror.name in mirrors:
tty.die("Mirror with name {} already exists.".format(mirror.name))
items = [(n, u) for n, u in mirrors.items()]
items.insert(0, (mirror.name, mirror.to_dict()))
mirrors = syaml.syaml_dict(items)
spack.config.set("mirrors", mirrors, scope=scope)
def remove(name, scope):
"""Remove the named mirror in the given scope"""
mirrors = spack.config.get("mirrors", scope=scope)
if not mirrors:
mirrors = syaml.syaml_dict()
if name not in mirrors:
tty.die("No mirror with name %s" % name)
mirrors.pop(name)
spack.config.set("mirrors", mirrors, scope=scope)
tty.msg("Removed mirror %s." % name)
class MirrorStats:
def __init__(self):
self.present = {}
self.new = {}
self.errors = set()
self.current_spec = None
self.added_resources = set()
self.existing_resources = set()
def next_spec(self, spec):
self._tally_current_spec()
self.current_spec = spec
def _tally_current_spec(self):
if self.current_spec:
if self.added_resources:
self.new[self.current_spec] = len(self.added_resources)
if self.existing_resources:
self.present[self.current_spec] = len(self.existing_resources)
self.added_resources = set()
self.existing_resources = set()
self.current_spec = None
def stats(self):
self._tally_current_spec()
return list(self.present), list(self.new), list(self.errors)
def already_existed(self, resource):
# If an error occurred after caching a subset of a spec's
# resources, a secondary attempt may consider them already added
if resource not in self.added_resources:
self.existing_resources.add(resource)
def added(self, resource):
self.added_resources.add(resource)
def error(self):
self.errors.add(self.current_spec)
def create_mirror_from_package_object(pkg_obj, mirror_cache, mirror_stats):
"""Add a single package object to a mirror.
The package object is only required to have an associated spec
with a concrete version.
Args:
pkg_obj (spack.package_base.PackageBase): package object with to be added.
mirror_cache (spack.caches.MirrorCache): mirror where to add the spec.
mirror_stats (spack.mirror.MirrorStats): statistics on the current mirror
Return:
True if the spec was added successfully, False otherwise
"""
tty.msg("Adding package {} to mirror".format(pkg_obj.spec.format("{name}{@version}")))
num_retries = 3
while num_retries > 0:
try:
# Includes patches and resources
with pkg_obj.stage as pkg_stage:
pkg_stage.cache_mirror(mirror_cache, mirror_stats)
exception = None
break
except Exception as e:
exc_tuple = sys.exc_info()
exception = e
num_retries -= 1
if exception:
if spack.config.get("config:debug"):
traceback.print_exception(file=sys.stderr, *exc_tuple)
else:
tty.warn(
"Error while fetching %s" % pkg_obj.spec.cformat("{name}{@version}"),
getattr(exception, "message", exception),
)
mirror_stats.error()
return False
return True
def require_mirror_name(mirror_name):
"""Find a mirror by name and raise if it does not exist"""
mirror = MirrorCollection().get(mirror_name)
if not mirror:
raise ValueError(f'no mirror named "{mirror_name}"')
return mirror
class MirrorError(spack.error.SpackError):
"""Superclass of all mirror-creation related errors."""
def __init__(self, msg, long_msg=None):
super().__init__(msg, long_msg)

View File

@@ -1,4 +0,0 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

View File

@@ -1,146 +0,0 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import os.path
from typing import Optional
import llnl.url
import llnl.util.symlink
from llnl.util.filesystem import mkdirp
import spack.fetch_strategy
import spack.oci.image
import spack.repo
import spack.spec
from spack.error import MirrorError
class MirrorLayout:
"""A ``MirrorLayout`` object describes the relative path of a mirror entry."""
def __init__(self, path: str) -> None:
self.path = path
def __iter__(self):
"""Yield all paths including aliases where the resource can be found."""
yield self.path
def make_alias(self, root: str) -> None:
"""Make the entry ``root / self.path`` available under a human readable alias"""
pass
class DefaultLayout(MirrorLayout):
def __init__(self, alias_path: str, digest_path: Optional[str] = None) -> None:
# When we have a digest, it is used as the primary storage location. If not, then we use
# the human-readable alias. In case of mirrors of a VCS checkout, we currently do not have
# a digest, that's why an alias is required and a digest optional.
super().__init__(path=digest_path or alias_path)
self.alias = alias_path
self.digest_path = digest_path
def make_alias(self, root: str) -> None:
"""Symlink a human readible path in our mirror to the actual storage location."""
# We already use the human-readable path as the main storage location.
if not self.digest_path:
return
alias, digest = os.path.join(root, self.alias), os.path.join(root, self.digest_path)
alias_dir = os.path.dirname(alias)
relative_dst = os.path.relpath(digest, start=alias_dir)
mkdirp(alias_dir)
tmp = f"{alias}.tmp"
llnl.util.symlink.symlink(relative_dst, tmp)
try:
os.rename(tmp, alias)
except OSError:
# Clean up the temporary if possible
try:
os.unlink(tmp)
except OSError:
pass
raise
def __iter__(self):
if self.digest_path:
yield self.digest_path
yield self.alias
class OCILayout(MirrorLayout):
"""Follow the OCI Image Layout Specification to archive blobs where paths are of the form
``blobs/<algorithm>/<digest>``"""
def __init__(self, digest: spack.oci.image.Digest) -> None:
super().__init__(os.path.join("blobs", digest.algorithm, digest.digest))
def _determine_extension(fetcher):
if isinstance(fetcher, spack.fetch_strategy.URLFetchStrategy):
if fetcher.expand_archive:
# If we fetch with a URLFetchStrategy, use URL's archive type
ext = llnl.url.determine_url_file_extension(fetcher.url)
if ext:
# Remove any leading dots
ext = ext.lstrip(".")
else:
msg = """\
Unable to parse extension from {0}.
If this URL is for a tarball but does not include the file extension
in the name, you can explicitly declare it with the following syntax:
version('1.2.3', 'hash', extension='tar.gz')
If this URL is for a download like a .jar or .whl that does not need
to be expanded, or an uncompressed installation script, you can tell
Spack not to expand it with the following syntax:
version('1.2.3', 'hash', expand=False)
"""
raise MirrorError(msg.format(fetcher.url))
else:
# If the archive shouldn't be expanded, don't check extension.
ext = None
else:
# Otherwise we'll make a .tar.gz ourselves
ext = "tar.gz"
return ext
def default_mirror_layout(
fetcher: "spack.fetch_strategy.FetchStrategy",
per_package_ref: str,
spec: Optional["spack.spec.Spec"] = None,
) -> MirrorLayout:
"""Returns a ``MirrorReference`` object which keeps track of the relative
storage path of the resource associated with the specified ``fetcher``."""
ext = None
if spec:
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
versions = pkg_cls.versions.get(spec.version, {})
ext = versions.get("extension", None)
# If the spec does not explicitly specify an extension (the default case),
# then try to determine it automatically. An extension can only be
# specified for the primary source of the package (e.g. the source code
# identified in the 'version' declaration). Resources/patches don't have
# an option to specify an extension, so it must be inferred for those.
ext = ext or _determine_extension(fetcher)
if ext:
per_package_ref += ".%s" % ext
global_ref = fetcher.mirror_id()
if global_ref:
global_ref = os.path.join("_source-cache", global_ref)
if global_ref and ext:
global_ref += ".%s" % ext
return DefaultLayout(per_package_ref, global_ref)

View File

@@ -1,258 +0,0 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import os.path
import traceback
import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp
import spack.caches
import spack.config
import spack.error
import spack.repo
import spack.spec
import spack.util.spack_yaml as syaml
import spack.version
from spack.error import MirrorError
from spack.mirrors.mirror import Mirror, MirrorCollection
def get_all_versions(specs):
"""Given a set of initial specs, return a new set of specs that includes
each version of each package in the original set.
Note that if any spec in the original set specifies properties other than
version, this information will be omitted in the new set; for example; the
new set of specs will not include variant settings.
"""
version_specs = []
for spec in specs:
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
# Skip any package that has no known versions.
if not pkg_cls.versions:
tty.msg("No safe (checksummed) versions for package %s" % pkg_cls.name)
continue
for version in pkg_cls.versions:
version_spec = spack.spec.Spec(pkg_cls.name)
version_spec.versions = spack.version.VersionList([version])
version_specs.append(version_spec)
return version_specs
def get_matching_versions(specs, num_versions=1):
"""Get a spec for EACH known version matching any spec in the list.
For concrete specs, this retrieves the concrete version and, if more
than one version per spec is requested, retrieves the latest versions
of the package.
"""
matching = []
for spec in specs:
pkg = spec.package
# Skip any package that has no known versions.
if not pkg.versions:
tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
continue
pkg_versions = num_versions
version_order = list(reversed(sorted(pkg.versions)))
matching_spec = []
if spec.concrete:
matching_spec.append(spec)
pkg_versions -= 1
if spec.version in version_order:
version_order.remove(spec.version)
for v in version_order:
# Generate no more than num_versions versions for each spec.
if pkg_versions < 1:
break
# Generate only versions that satisfy the spec.
if spec.concrete or v.intersects(spec.versions):
s = spack.spec.Spec(pkg.name)
s.versions = spack.version.VersionList([v])
s.variants = spec.variants.copy()
# This is needed to avoid hanging references during the
# concretization phase
s.variants.spec = s
matching_spec.append(s)
pkg_versions -= 1
if not matching_spec:
tty.warn("No known version matches spec: %s" % spec)
matching.extend(matching_spec)
return matching
def create(path, specs, skip_unstable_versions=False):
"""Create a directory to be used as a spack mirror, and fill it with
package archives.
Arguments:
path: Path to create a mirror directory hierarchy in.
specs: Any package versions matching these specs will be added \
to the mirror.
skip_unstable_versions: if true, this skips adding resources when
they do not have a stable archive checksum (as determined by
``fetch_strategy.stable_target``)
Return Value:
Returns a tuple of lists: (present, mirrored, error)
* present: Package specs that were already present.
* mirrored: Package specs that were successfully mirrored.
* error: Package specs that failed to mirror due to some error.
"""
# automatically spec-ify anything in the specs array.
specs = [s if isinstance(s, spack.spec.Spec) else spack.spec.Spec(s) for s in specs]
mirror_cache, mirror_stats = mirror_cache_and_stats(path, skip_unstable_versions)
for spec in specs:
mirror_stats.next_spec(spec)
create_mirror_from_package_object(spec.package, mirror_cache, mirror_stats)
return mirror_stats.stats()
def mirror_cache_and_stats(path, skip_unstable_versions=False):
"""Return both a mirror cache and a mirror stats, starting from the path
where a mirror ought to be created.
Args:
path (str): path to create a mirror directory hierarchy in.
skip_unstable_versions: if true, this skips adding resources when
they do not have a stable archive checksum (as determined by
``fetch_strategy.stable_target``)
"""
# Get the absolute path of the root before we start jumping around.
if not os.path.isdir(path):
try:
mkdirp(path)
except OSError as e:
raise MirrorError("Cannot create directory '%s':" % path, str(e))
mirror_cache = spack.caches.MirrorCache(path, skip_unstable_versions=skip_unstable_versions)
mirror_stats = MirrorStats()
return mirror_cache, mirror_stats
def add(mirror: Mirror, scope=None):
"""Add a named mirror in the given scope"""
mirrors = spack.config.get("mirrors", scope=scope)
if not mirrors:
mirrors = syaml.syaml_dict()
if mirror.name in mirrors:
tty.die("Mirror with name {} already exists.".format(mirror.name))
items = [(n, u) for n, u in mirrors.items()]
items.insert(0, (mirror.name, mirror.to_dict()))
mirrors = syaml.syaml_dict(items)
spack.config.set("mirrors", mirrors, scope=scope)
def remove(name, scope):
"""Remove the named mirror in the given scope"""
mirrors = spack.config.get("mirrors", scope=scope)
if not mirrors:
mirrors = syaml.syaml_dict()
if name not in mirrors:
tty.die("No mirror with name %s" % name)
mirrors.pop(name)
spack.config.set("mirrors", mirrors, scope=scope)
tty.msg("Removed mirror %s." % name)
class MirrorStats:
def __init__(self):
self.present = {}
self.new = {}
self.errors = set()
self.current_spec = None
self.added_resources = set()
self.existing_resources = set()
def next_spec(self, spec):
self._tally_current_spec()
self.current_spec = spec
def _tally_current_spec(self):
if self.current_spec:
if self.added_resources:
self.new[self.current_spec] = len(self.added_resources)
if self.existing_resources:
self.present[self.current_spec] = len(self.existing_resources)
self.added_resources = set()
self.existing_resources = set()
self.current_spec = None
def stats(self):
self._tally_current_spec()
return list(self.present), list(self.new), list(self.errors)
def already_existed(self, resource):
# If an error occurred after caching a subset of a spec's
# resources, a secondary attempt may consider them already added
if resource not in self.added_resources:
self.existing_resources.add(resource)
def added(self, resource):
self.added_resources.add(resource)
def error(self):
self.errors.add(self.current_spec)
def create_mirror_from_package_object(
pkg_obj, mirror_cache: "spack.caches.MirrorCache", mirror_stats: MirrorStats
) -> bool:
"""Add a single package object to a mirror.
The package object is only required to have an associated spec
with a concrete version.
Args:
pkg_obj (spack.package_base.PackageBase): package object with to be added.
mirror_cache: mirror where to add the spec.
mirror_stats: statistics on the current mirror
Return:
True if the spec was added successfully, False otherwise
"""
tty.msg("Adding package {} to mirror".format(pkg_obj.spec.format("{name}{@version}")))
max_retries = 3
for num_retries in range(max_retries):
try:
# Includes patches and resources
with pkg_obj.stage as pkg_stage:
pkg_stage.cache_mirror(mirror_cache, mirror_stats)
break
except Exception as e:
if num_retries + 1 == max_retries:
if spack.config.get("config:debug"):
traceback.print_exc()
else:
tty.warn(
"Error while fetching %s" % pkg_obj.spec.format("{name}{@version}"), str(e)
)
mirror_stats.error()
return False
return True
def require_mirror_name(mirror_name):
"""Find a mirror by name and raise if it does not exist"""
mirror = MirrorCollection().get(mirror_name)
if not mirror:
raise ValueError(f'no mirror named "{mirror_name}"')
return mirror

View File

@@ -16,8 +16,7 @@
import llnl.util.tty as tty
import spack.fetch_strategy
import spack.mirrors.layout
import spack.mirrors.mirror
import spack.mirror
import spack.oci.opener
import spack.stage
import spack.util.url
@@ -214,7 +213,7 @@ def upload_manifest(
return digest, size
def image_from_mirror(mirror: spack.mirrors.mirror.Mirror) -> ImageReference:
def image_from_mirror(mirror: spack.mirror.Mirror) -> ImageReference:
"""Given an OCI based mirror, extract the URL and image name from it"""
url = mirror.push_url
if not url.startswith("oci://"):
@@ -386,8 +385,5 @@ def make_stage(
# is the `oci-layout` and `index.json` files, which are
# required by the spec.
return spack.stage.Stage(
fetch_strategy,
mirror_paths=spack.mirrors.layout.OCILayout(digest),
name=digest.digest,
keep=keep,
fetch_strategy, mirror_paths=spack.mirror.OCILayout(digest), name=digest.digest, keep=keep
)

View File

@@ -20,7 +20,7 @@
import llnl.util.lang
import spack.config
import spack.mirrors.mirror
import spack.mirror
import spack.parser
import spack.util.web
@@ -367,11 +367,11 @@ def http_error_401(self, req: Request, fp, code, msg, headers):
def credentials_from_mirrors(
domain: str, *, mirrors: Optional[Iterable[spack.mirrors.mirror.Mirror]] = None
domain: str, *, mirrors: Optional[Iterable[spack.mirror.Mirror]] = None
) -> Optional[UsernamePassword]:
"""Filter out OCI registry credentials from a list of mirrors."""
mirrors = mirrors or spack.mirrors.mirror.MirrorCollection().values()
mirrors = mirrors or spack.mirror.MirrorCollection().values()
for mirror in mirrors:
# Prefer push credentials over fetch. Unlikely that those are different

View File

@@ -40,8 +40,7 @@
import spack.error
import spack.fetch_strategy as fs
import spack.hooks
import spack.mirrors.layout
import spack.mirrors.mirror
import spack.mirror
import spack.multimethod
import spack.patch
import spack.phase_callbacks
@@ -55,7 +54,6 @@
import spack.variant
from spack.error import InstallError, NoURLError, PackageError
from spack.filesystem_view import YamlFilesystemView
from spack.resource import Resource
from spack.solver.version_order import concretization_version_order
from spack.stage import DevelopStage, ResourceStage, Stage, StageComposite, compute_stage_name
from spack.util.package_hash import package_hash
@@ -587,7 +585,6 @@ class PackageBase(WindowsRPath, PackageViewMixin, metaclass=PackageMeta):
# Declare versions dictionary as placeholder for values.
# This allows analysis tools to correctly interpret the class attributes.
versions: dict
resources: Dict[spack.spec.Spec, List[Resource]]
dependencies: Dict[spack.spec.Spec, Dict[str, spack.dependency.Dependency]]
conflicts: Dict[spack.spec.Spec, List[Tuple[spack.spec.Spec, Optional[str]]]]
requirements: Dict[
@@ -598,7 +595,6 @@ class PackageBase(WindowsRPath, PackageViewMixin, metaclass=PackageMeta):
patches: Dict[spack.spec.Spec, List[spack.patch.Patch]]
variants: Dict[spack.spec.Spec, Dict[str, spack.variant.Variant]]
languages: Dict[spack.spec.Spec, Set[str]]
licenses: Dict[spack.spec.Spec, str]
splice_specs: Dict[spack.spec.Spec, Tuple[spack.spec.Spec, Union[None, str, List[str]]]]
#: Store whether a given Spec source/binary should not be redistributed.
@@ -1188,10 +1184,10 @@ def _make_resource_stage(self, root_stage, resource):
root=root_stage,
resource=resource,
name=self._resource_stage(resource),
mirror_paths=spack.mirrors.layout.default_mirror_layout(
mirror_paths=spack.mirror.default_mirror_layout(
resource.fetcher, os.path.join(self.name, pretty_resource_name)
),
mirrors=spack.mirrors.mirror.MirrorCollection(source=True).values(),
mirrors=spack.mirror.MirrorCollection(source=True).values(),
path=self.path,
)
@@ -1203,7 +1199,7 @@ def _make_root_stage(self, fetcher):
# Construct a mirror path (TODO: get this out of package.py)
format_string = "{name}-{version}"
pretty_name = self.spec.format_path(format_string)
mirror_paths = spack.mirrors.layout.default_mirror_layout(
mirror_paths = spack.mirror.default_mirror_layout(
fetcher, os.path.join(self.name, pretty_name), self.spec
)
# Construct a path where the stage should build..
@@ -1212,7 +1208,7 @@ def _make_root_stage(self, fetcher):
stage = Stage(
fetcher,
mirror_paths=mirror_paths,
mirrors=spack.mirrors.mirror.MirrorCollection(source=True).values(),
mirrors=spack.mirror.MirrorCollection(source=True).values(),
name=stage_name,
path=self.path,
search_fn=self._download_search,

View File

@@ -16,8 +16,7 @@
import spack
import spack.error
import spack.fetch_strategy
import spack.mirrors.layout
import spack.mirrors.mirror
import spack.mirror
import spack.repo
import spack.stage
import spack.util.spack_json as sjson
@@ -330,12 +329,12 @@ def stage(self) -> "spack.stage.Stage":
name = "{0}-{1}".format(os.path.basename(self.url), fetch_digest[:7])
per_package_ref = os.path.join(self.owner.split(".")[-1], name)
mirror_ref = spack.mirrors.layout.default_mirror_layout(fetcher, per_package_ref)
mirror_ref = spack.mirror.default_mirror_layout(fetcher, per_package_ref)
self._stage = spack.stage.Stage(
fetcher,
name=f"{spack.stage.stage_prefix}patch-{fetch_digest}",
mirror_paths=mirror_ref,
mirrors=spack.mirrors.mirror.MirrorCollection(source=True).values(),
mirrors=spack.mirror.MirrorCollection(source=True).values(),
)
return self._stage

View File

@@ -41,7 +41,6 @@
import spack.provider_index
import spack.spec
import spack.tag
import spack.tengine
import spack.util.file_cache
import spack.util.git
import spack.util.naming as nm
@@ -82,6 +81,43 @@ def namespace_from_fullname(fullname):
return namespace
class _PrependFileLoader(importlib.machinery.SourceFileLoader):
def __init__(self, fullname, path, prepend=None):
super(_PrependFileLoader, self).__init__(fullname, path)
self.prepend = prepend
def path_stats(self, path):
stats = super(_PrependFileLoader, self).path_stats(path)
if self.prepend:
stats["size"] += len(self.prepend) + 1
return stats
def get_data(self, path):
data = super(_PrependFileLoader, self).get_data(path)
if path != self.path or self.prepend is None:
return data
else:
return self.prepend.encode() + b"\n" + data
class RepoLoader(_PrependFileLoader):
"""Loads a Python module associated with a package in specific repository"""
#: Code in ``_package_prepend`` is prepended to imported packages.
#:
#: Spack packages are expected to call `from spack.package import *`
#: themselves, but we are allowing a deprecation period before breaking
#: external repos that don't do this yet.
_package_prepend = "from spack.package import *"
def __init__(self, fullname, repo, package_name):
self.repo = repo
self.package_name = package_name
self.package_py = repo.filename_for_package_name(package_name)
self.fullname = fullname
super().__init__(self.fullname, self.package_py, prepend=self._package_prepend)
class SpackNamespaceLoader:
def create_module(self, spec):
return SpackNamespace(spec.name)
@@ -151,8 +187,7 @@ def compute_loader(self, fullname):
# With 2 nested conditionals we can call "repo.real_name" only once
package_name = repo.real_name(module_name)
if package_name:
module_path = repo.filename_for_package_name(package_name)
return importlib.machinery.SourceFileLoader(fullname, module_path)
return RepoLoader(fullname, repo, package_name)
# We are importing a full namespace like 'spack.pkg.builtin'
if fullname == repo.full_namespace:
@@ -1486,6 +1521,8 @@ def add_package(self, name, dependencies=None):
Both "dep_type" and "condition" can default to ``None`` in which case
``spack.dependency.default_deptype`` and ``spack.spec.Spec()`` are used.
"""
import spack.tengine # avoid circular import
dependencies = dependencies or []
context = {"cls_name": nm.mod_to_class(name), "dependencies": dependencies}
template = spack.tengine.make_environment().get_template("mock-repository/package.pyt")

View File

@@ -12,10 +12,7 @@
class Resource:
"""Represents any resource to be fetched by a package.
This includes the main tarball or source archive, as well as extra archives defined
by the resource() directive.
"""Represents an optional resource to be fetched by a package.
Aggregates a name, a fetcher, a destination and a placement.
"""

View File

@@ -106,8 +106,8 @@
{
"names": ["install_missing_compilers"],
"message": "The config:install_missing_compilers option has been deprecated in "
"Spack v0.23, and is currently ignored. It will be removed from config after "
"Spack v1.0.",
"Spack v0.23, and is currently ignored. It will be removed from config in "
"Spack v0.25.",
"error": False,
},
],

View File

@@ -48,6 +48,8 @@
import spack.version as vn
import spack.version.git_ref_lookup
from spack import traverse
from spack.config import get_mark_from_yaml_data
from spack.error import SpecSyntaxError
from .core import (
AspFunction,
@@ -63,12 +65,11 @@
parse_term,
)
from .counter import FullDuplicatesCounter, MinimalDuplicatesCounter, NoDuplicatesCounter
from .requirements import RequirementKind, RequirementParser, RequirementRule
from .version_order import concretization_version_order
GitOrStandardVersion = Union[spack.version.GitVersion, spack.version.StandardVersion]
TransformFunction = Callable[[spack.spec.Spec, List[AspFunction]], List[AspFunction]]
TransformFunction = Callable[["spack.spec.Spec", List[AspFunction]], List[AspFunction]]
#: Enable the addition of a runtime node
WITH_RUNTIME = sys.platform != "win32"
@@ -128,8 +129,8 @@ def __str__(self):
@contextmanager
def named_spec(
spec: Optional[spack.spec.Spec], name: Optional[str]
) -> Iterator[Optional[spack.spec.Spec]]:
spec: Optional["spack.spec.Spec"], name: Optional[str]
) -> Iterator[Optional["spack.spec.Spec"]]:
"""Context manager to temporarily set the name of a spec"""
if spec is None or name is None:
yield spec
@@ -143,6 +144,17 @@ def named_spec(
spec.name = old_name
class RequirementKind(enum.Enum):
"""Purpose / provenance of a requirement"""
#: Default requirement expressed under the 'all' attribute of packages.yaml
DEFAULT = enum.auto()
#: Requirement expressed on a virtual package
VIRTUAL = enum.auto()
#: Requirement expressed on a specific package
PACKAGE = enum.auto()
class DeclaredVersion(NamedTuple):
"""Data class to contain information on declared versions used in the solve"""
@@ -745,14 +757,25 @@ def on_model(model):
raise UnsatisfiableSpecError(msg)
class RequirementRule(NamedTuple):
"""Data class to collect information on a requirement"""
pkg_name: str
policy: str
requirements: List["spack.spec.Spec"]
condition: "spack.spec.Spec"
kind: RequirementKind
message: Optional[str]
class KnownCompiler(NamedTuple):
"""Data class to collect information on compilers"""
spec: spack.spec.Spec
spec: "spack.spec.Spec"
os: str
target: str
available: bool
compiler_obj: Optional[spack.compiler.Compiler]
compiler_obj: Optional["spack.compiler.Compiler"]
def _key(self):
return self.spec, self.os, self.target
@@ -1123,7 +1146,6 @@ class SpackSolverSetup:
def __init__(self, tests: bool = False):
# these are all initialized in setup()
self.gen: "ProblemInstanceBuilder" = ProblemInstanceBuilder()
self.requirement_parser = RequirementParser(spack.config.CONFIG)
self.possible_virtuals: Set[str] = set()
self.assumptions: List[Tuple["clingo.Symbol", bool]] = [] # type: ignore[name-defined]
@@ -1310,7 +1332,8 @@ def compiler_facts(self):
self.gen.newline()
def package_requirement_rules(self, pkg):
self.emit_facts_from_requirement_rules(self.requirement_parser.rules(pkg))
parser = RequirementParser(spack.config.CONFIG)
self.emit_facts_from_requirement_rules(parser.rules(pkg))
def pkg_rules(self, pkg, tests):
pkg = self.pkg_class(pkg)
@@ -1387,7 +1410,7 @@ def effect_rules(self):
def define_variant(
self,
pkg: Type[spack.package_base.PackageBase],
pkg: "Type[spack.package_base.PackageBase]",
name: str,
when: spack.spec.Spec,
variant_def: vt.Variant,
@@ -1491,7 +1514,7 @@ def define_auto_variant(self, name: str, multi: bool):
)
)
def variant_rules(self, pkg: Type[spack.package_base.PackageBase]):
def variant_rules(self, pkg: "Type[spack.package_base.PackageBase]"):
for name in pkg.variant_names():
self.gen.h3(f"Variant {name} in package {pkg.name}")
for when, variant_def in pkg.variant_definitions(name):
@@ -1682,8 +1705,8 @@ def dependency_holds(input_spec, requirements):
def _gen_match_variant_splice_constraints(
self,
pkg,
cond_spec: spack.spec.Spec,
splice_spec: spack.spec.Spec,
cond_spec: "spack.spec.Spec",
splice_spec: "spack.spec.Spec",
hash_asp_var: "AspVar",
splice_node,
match_variants: List[str],
@@ -1788,8 +1811,9 @@ def provider_defaults(self):
def provider_requirements(self):
self.gen.h2("Requirements on virtual providers")
parser = RequirementParser(spack.config.CONFIG)
for virtual_str in sorted(self.possible_virtuals):
rules = self.requirement_parser.rules_from_virtual(virtual_str)
rules = parser.rules_from_virtual(virtual_str)
if rules:
self.emit_facts_from_requirement_rules(rules)
self.trigger_rules()
@@ -2978,7 +3002,7 @@ def _specs_from_requires(self, pkg_name, section):
for s in spec_group[key]:
yield _spec_with_default_name(s, pkg_name)
def pkg_class(self, pkg_name: str) -> typing.Type[spack.package_base.PackageBase]:
def pkg_class(self, pkg_name: str) -> typing.Type["spack.package_base.PackageBase"]:
request = pkg_name
if pkg_name in self.explicitly_required_namespaces:
namespace = self.explicitly_required_namespaces[pkg_name]
@@ -3064,6 +3088,202 @@ def value(self) -> str:
return "".join(self.asp_problem)
def parse_spec_from_yaml_string(string: str) -> "spack.spec.Spec":
"""Parse a spec from YAML and add file/line info to errors, if it's available.
Parse a ``Spec`` from the supplied string, but also intercept any syntax errors and
add file/line information for debugging using file/line annotations from the string.
Arguments:
string: a string representing a ``Spec`` from config YAML.
"""
try:
return spack.spec.Spec(string)
except SpecSyntaxError as e:
mark = get_mark_from_yaml_data(string)
if mark:
msg = f"{mark.name}:{mark.line + 1}: {str(e)}"
raise SpecSyntaxError(msg) from e
raise e
class RequirementParser:
"""Parses requirements from package.py files and configuration, and returns rules."""
def __init__(self, configuration):
self.config = configuration
def rules(self, pkg: "spack.package_base.PackageBase") -> List[RequirementRule]:
result = []
result.extend(self.rules_from_package_py(pkg))
result.extend(self.rules_from_require(pkg))
result.extend(self.rules_from_prefer(pkg))
result.extend(self.rules_from_conflict(pkg))
return result
def rules_from_package_py(self, pkg) -> List[RequirementRule]:
rules = []
for when_spec, requirement_list in pkg.requirements.items():
for requirements, policy, message in requirement_list:
rules.append(
RequirementRule(
pkg_name=pkg.name,
policy=policy,
requirements=requirements,
kind=RequirementKind.PACKAGE,
condition=when_spec,
message=message,
)
)
return rules
def rules_from_virtual(self, virtual_str: str) -> List[RequirementRule]:
requirements = self.config.get("packages", {}).get(virtual_str, {}).get("require", [])
return self._rules_from_requirements(
virtual_str, requirements, kind=RequirementKind.VIRTUAL
)
def rules_from_require(self, pkg: "spack.package_base.PackageBase") -> List[RequirementRule]:
kind, requirements = self._raw_yaml_data(pkg, section="require")
return self._rules_from_requirements(pkg.name, requirements, kind=kind)
def rules_from_prefer(self, pkg: "spack.package_base.PackageBase") -> List[RequirementRule]:
result = []
kind, preferences = self._raw_yaml_data(pkg, section="prefer")
for item in preferences:
spec, condition, message = self._parse_prefer_conflict_item(item)
result.append(
# A strong preference is defined as:
#
# require:
# - any_of: [spec_str, "@:"]
RequirementRule(
pkg_name=pkg.name,
policy="any_of",
requirements=[spec, spack.spec.Spec("@:")],
kind=kind,
message=message,
condition=condition,
)
)
return result
def rules_from_conflict(self, pkg: "spack.package_base.PackageBase") -> List[RequirementRule]:
result = []
kind, conflicts = self._raw_yaml_data(pkg, section="conflict")
for item in conflicts:
spec, condition, message = self._parse_prefer_conflict_item(item)
result.append(
# A conflict is defined as:
#
# require:
# - one_of: [spec_str, "@:"]
RequirementRule(
pkg_name=pkg.name,
policy="one_of",
requirements=[spec, spack.spec.Spec("@:")],
kind=kind,
message=message,
condition=condition,
)
)
return result
def _parse_prefer_conflict_item(self, item):
# The item is either a string or an object with at least a "spec" attribute
if isinstance(item, str):
spec = parse_spec_from_yaml_string(item)
condition = spack.spec.Spec()
message = None
else:
spec = parse_spec_from_yaml_string(item["spec"])
condition = spack.spec.Spec(item.get("when"))
message = item.get("message")
return spec, condition, message
def _raw_yaml_data(self, pkg: "spack.package_base.PackageBase", *, section: str):
config = self.config.get("packages")
data = config.get(pkg.name, {}).get(section, [])
kind = RequirementKind.PACKAGE
if not data:
data = config.get("all", {}).get(section, [])
kind = RequirementKind.DEFAULT
return kind, data
def _rules_from_requirements(
self, pkg_name: str, requirements, *, kind: RequirementKind
) -> List[RequirementRule]:
"""Manipulate requirements from packages.yaml, and return a list of tuples
with a uniform structure (name, policy, requirements).
"""
if isinstance(requirements, str):
requirements = [requirements]
rules = []
for requirement in requirements:
# A string is equivalent to a one_of group with a single element
if isinstance(requirement, str):
requirement = {"one_of": [requirement]}
for policy in ("spec", "one_of", "any_of"):
if policy not in requirement:
continue
constraints = requirement[policy]
# "spec" is for specifying a single spec
if policy == "spec":
constraints = [constraints]
policy = "one_of"
# validate specs from YAML first, and fail with line numbers if parsing fails.
constraints = [
parse_spec_from_yaml_string(constraint) for constraint in constraints
]
when_str = requirement.get("when")
when = parse_spec_from_yaml_string(when_str) if when_str else spack.spec.Spec()
constraints = [
x
for x in constraints
if not self.reject_requirement_constraint(pkg_name, constraint=x, kind=kind)
]
if not constraints:
continue
rules.append(
RequirementRule(
pkg_name=pkg_name,
policy=policy,
requirements=constraints,
kind=kind,
message=requirement.get("message"),
condition=when,
)
)
return rules
def reject_requirement_constraint(
self, pkg_name: str, *, constraint: spack.spec.Spec, kind: RequirementKind
) -> bool:
"""Returns True if a requirement constraint should be rejected"""
if kind == RequirementKind.DEFAULT:
# Requirements under all: are applied only if they are satisfiable considering only
# package rules, so e.g. variants must exist etc. Otherwise, they are rejected.
try:
s = spack.spec.Spec(pkg_name)
s.constrain(constraint)
s.validate_or_raise()
except spack.error.SpackError as e:
tty.debug(
f"[SETUP] Rejecting the default '{constraint}' requirement "
f"on '{pkg_name}': {str(e)}",
level=2,
)
return True
return False
class CompilerParser:
"""Parses configuration files, and builds a list of possible compilers for the solve."""
@@ -3097,7 +3317,7 @@ def __init__(self, configuration) -> None:
self.compilers.add(candidate)
def with_input_specs(self, input_specs: List[spack.spec.Spec]) -> "CompilerParser":
def with_input_specs(self, input_specs: List["spack.spec.Spec"]) -> "CompilerParser":
"""Accounts for input specs when building the list of possible compilers.
Args:
@@ -3137,7 +3357,7 @@ def with_input_specs(self, input_specs: List[spack.spec.Spec]) -> "CompilerParse
return self
def add_compiler_from_concrete_spec(self, spec: spack.spec.Spec) -> None:
def add_compiler_from_concrete_spec(self, spec: "spack.spec.Spec") -> None:
"""Account for compilers that are coming from concrete specs, through reuse.
Args:

View File

@@ -1003,8 +1003,6 @@ variant_default_not_used(node(ID, Package), Variant, Value)
node_has_variant(node(ID, Package), Variant, _),
not attr("variant_value", node(ID, Package), Variant, Value),
not propagate(node(ID, Package), variant_value(Variant, _, _)),
% variant set explicitly don't count for this metric
not attr("variant_set", node(ID, Package), Variant, _),
attr("node", node(ID, Package)).
% The variant is set in an external spec

View File

@@ -1,232 +0,0 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import enum
from typing import List, NamedTuple, Optional, Sequence
from llnl.util import tty
import spack.config
import spack.error
import spack.package_base
import spack.spec
from spack.config import get_mark_from_yaml_data
class RequirementKind(enum.Enum):
"""Purpose / provenance of a requirement"""
#: Default requirement expressed under the 'all' attribute of packages.yaml
DEFAULT = enum.auto()
#: Requirement expressed on a virtual package
VIRTUAL = enum.auto()
#: Requirement expressed on a specific package
PACKAGE = enum.auto()
class RequirementRule(NamedTuple):
"""Data class to collect information on a requirement"""
pkg_name: str
policy: str
requirements: Sequence[spack.spec.Spec]
condition: spack.spec.Spec
kind: RequirementKind
message: Optional[str]
class RequirementParser:
"""Parses requirements from package.py files and configuration, and returns rules."""
def __init__(self, configuration: spack.config.Configuration):
self.config = configuration
def rules(self, pkg: spack.package_base.PackageBase) -> List[RequirementRule]:
result = []
result.extend(self.rules_from_package_py(pkg))
result.extend(self.rules_from_require(pkg))
result.extend(self.rules_from_prefer(pkg))
result.extend(self.rules_from_conflict(pkg))
return result
def rules_from_package_py(self, pkg: spack.package_base.PackageBase) -> List[RequirementRule]:
rules = []
for when_spec, requirement_list in pkg.requirements.items():
for requirements, policy, message in requirement_list:
rules.append(
RequirementRule(
pkg_name=pkg.name,
policy=policy,
requirements=requirements,
kind=RequirementKind.PACKAGE,
condition=when_spec,
message=message,
)
)
return rules
def rules_from_virtual(self, virtual_str: str) -> List[RequirementRule]:
requirements = self.config.get("packages", {}).get(virtual_str, {}).get("require", [])
return self._rules_from_requirements(
virtual_str, requirements, kind=RequirementKind.VIRTUAL
)
def rules_from_require(self, pkg: spack.package_base.PackageBase) -> List[RequirementRule]:
kind, requirements = self._raw_yaml_data(pkg, section="require")
return self._rules_from_requirements(pkg.name, requirements, kind=kind)
def rules_from_prefer(self, pkg: spack.package_base.PackageBase) -> List[RequirementRule]:
result = []
kind, preferences = self._raw_yaml_data(pkg, section="prefer")
for item in preferences:
spec, condition, message = self._parse_prefer_conflict_item(item)
result.append(
# A strong preference is defined as:
#
# require:
# - any_of: [spec_str, "@:"]
RequirementRule(
pkg_name=pkg.name,
policy="any_of",
requirements=[spec, spack.spec.Spec("@:")],
kind=kind,
message=message,
condition=condition,
)
)
return result
def rules_from_conflict(self, pkg: spack.package_base.PackageBase) -> List[RequirementRule]:
result = []
kind, conflicts = self._raw_yaml_data(pkg, section="conflict")
for item in conflicts:
spec, condition, message = self._parse_prefer_conflict_item(item)
result.append(
# A conflict is defined as:
#
# require:
# - one_of: [spec_str, "@:"]
RequirementRule(
pkg_name=pkg.name,
policy="one_of",
requirements=[spec, spack.spec.Spec("@:")],
kind=kind,
message=message,
condition=condition,
)
)
return result
def _parse_prefer_conflict_item(self, item):
# The item is either a string or an object with at least a "spec" attribute
if isinstance(item, str):
spec = parse_spec_from_yaml_string(item)
condition = spack.spec.Spec()
message = None
else:
spec = parse_spec_from_yaml_string(item["spec"])
condition = spack.spec.Spec(item.get("when"))
message = item.get("message")
return spec, condition, message
def _raw_yaml_data(self, pkg: spack.package_base.PackageBase, *, section: str):
config = self.config.get("packages")
data = config.get(pkg.name, {}).get(section, [])
kind = RequirementKind.PACKAGE
if not data:
data = config.get("all", {}).get(section, [])
kind = RequirementKind.DEFAULT
return kind, data
def _rules_from_requirements(
self, pkg_name: str, requirements, *, kind: RequirementKind
) -> List[RequirementRule]:
"""Manipulate requirements from packages.yaml, and return a list of tuples
with a uniform structure (name, policy, requirements).
"""
if isinstance(requirements, str):
requirements = [requirements]
rules = []
for requirement in requirements:
# A string is equivalent to a one_of group with a single element
if isinstance(requirement, str):
requirement = {"one_of": [requirement]}
for policy in ("spec", "one_of", "any_of"):
if policy not in requirement:
continue
constraints = requirement[policy]
# "spec" is for specifying a single spec
if policy == "spec":
constraints = [constraints]
policy = "one_of"
# validate specs from YAML first, and fail with line numbers if parsing fails.
constraints = [
parse_spec_from_yaml_string(constraint) for constraint in constraints
]
when_str = requirement.get("when")
when = parse_spec_from_yaml_string(when_str) if when_str else spack.spec.Spec()
constraints = [
x
for x in constraints
if not self.reject_requirement_constraint(pkg_name, constraint=x, kind=kind)
]
if not constraints:
continue
rules.append(
RequirementRule(
pkg_name=pkg_name,
policy=policy,
requirements=constraints,
kind=kind,
message=requirement.get("message"),
condition=when,
)
)
return rules
def reject_requirement_constraint(
self, pkg_name: str, *, constraint: spack.spec.Spec, kind: RequirementKind
) -> bool:
"""Returns True if a requirement constraint should be rejected"""
if kind == RequirementKind.DEFAULT:
# Requirements under all: are applied only if they are satisfiable considering only
# package rules, so e.g. variants must exist etc. Otherwise, they are rejected.
try:
s = spack.spec.Spec(pkg_name)
s.constrain(constraint)
s.validate_or_raise()
except spack.error.SpackError as e:
tty.debug(
f"[SETUP] Rejecting the default '{constraint}' requirement "
f"on '{pkg_name}': {str(e)}",
level=2,
)
return True
return False
def parse_spec_from_yaml_string(string: str) -> spack.spec.Spec:
"""Parse a spec from YAML and add file/line info to errors, if it's available.
Parse a ``Spec`` from the supplied string, but also intercept any syntax errors and
add file/line information for debugging using file/line annotations from the string.
Arguments:
string: a string representing a ``Spec`` from config YAML.
"""
try:
return spack.spec.Spec(string)
except spack.error.SpecSyntaxError as e:
mark = get_mark_from_yaml_data(string)
if mark:
msg = f"{mark.name}:{mark.line + 1}: {str(e)}"
raise spack.error.SpecSyntaxError(msg) from e
raise e

View File

@@ -73,6 +73,7 @@
import spack
import spack.compiler
import spack.compilers
import spack.config
import spack.deptypes as dt
import spack.error
import spack.hash_types as ht
@@ -81,6 +82,7 @@
import spack.platforms
import spack.provider_index
import spack.repo
import spack.solver
import spack.store
import spack.traverse as traverse
import spack.util.executable
@@ -2828,6 +2830,46 @@ def ensure_no_deprecated(root):
msg += " For each package listed, choose another spec\n"
raise SpecDeprecatedError(msg)
def concretize(self, tests: Union[bool, Iterable[str]] = False) -> None:
"""Concretize the current spec.
Args:
tests: if False disregard 'test' dependencies, if a list of names activate them for
the packages in the list, if True activate 'test' dependencies for all packages.
"""
import spack.solver.asp
self.replace_hash()
for node in self.traverse():
if not node.name:
raise spack.error.SpecError(
f"Spec {node} has no name; cannot concretize an anonymous spec"
)
if self._concrete:
return
allow_deprecated = spack.config.get("config:deprecated", False)
solver = spack.solver.asp.Solver()
result = solver.solve([self], tests=tests, allow_deprecated=allow_deprecated)
# take the best answer
opt, i, answer = min(result.answers)
name = self.name
# TODO: Consolidate this code with similar code in solve.py
if self.virtual:
providers = [spec.name for spec in answer.values() if spec.package.provides(name)]
name = providers[0]
node = spack.solver.asp.SpecBuilder.make_node(pkg=name)
assert (
node in answer
), f"cannot find {name} in the list of specs {','.join([n.pkg for n in answer.keys()])}"
concretized = answer[node]
self._dup(concretized)
def _mark_root_concrete(self, value=True):
"""Mark just this spec (not dependencies) concrete."""
if (not value) and self.concrete and self.installed:
@@ -2916,6 +2958,21 @@ def _finalize_concretization(self):
for spec in self.traverse():
spec._cached_hash(ht.dag_hash)
def concretized(self, tests: Union[bool, Iterable[str]] = False) -> "spack.spec.Spec":
"""This is a non-destructive version of concretize().
First clones, then returns a concrete version of this package
without modifying this package.
Args:
tests (bool or list): if False disregard 'test' dependencies,
if a list of names activate them for the packages in the list,
if True activate 'test' dependencies for all packages.
"""
clone = self.copy()
clone.concretize(tests=tests)
return clone
def index(self, deptype="all"):
"""Return a dictionary that points to all the dependencies in this
spec.

View File

@@ -34,8 +34,7 @@
import spack.caches
import spack.config
import spack.error
import spack.mirrors.layout
import spack.mirrors.utils
import spack.mirror
import spack.resource
import spack.spec
import spack.util.crypto
@@ -354,8 +353,8 @@ def __init__(
url_or_fetch_strategy,
*,
name=None,
mirror_paths: Optional["spack.mirrors.layout.MirrorLayout"] = None,
mirrors: Optional[Iterable["spack.mirrors.mirror.Mirror"]] = None,
mirror_paths: Optional["spack.mirror.MirrorLayout"] = None,
mirrors: Optional[Iterable["spack.mirror.Mirror"]] = None,
keep=False,
path=None,
lock=True,
@@ -489,7 +488,7 @@ def _generate_fetchers(self, mirror_only=False) -> Generator["fs.FetchStrategy",
# Insert fetchers in the order that the URLs are provided.
fetchers[:0] = (
fs.from_url_scheme(
url_util.join(mirror.fetch_url, *self.mirror_layout.path.split(os.sep)),
url_util.join(mirror.fetch_url, self.mirror_layout.path),
checksum=digest,
expand=expand,
extension=extension,
@@ -602,7 +601,7 @@ def cache_local(self):
spack.caches.FETCH_CACHE.store(self.fetcher, self.mirror_layout.path)
def cache_mirror(
self, mirror: "spack.caches.MirrorCache", stats: "spack.mirrors.utils.MirrorStats"
self, mirror: "spack.caches.MirrorCache", stats: "spack.mirror.MirrorStats"
) -> None:
"""Perform a fetch if the resource is not already cached

View File

@@ -8,7 +8,6 @@
import pytest
import spack.concretize
import spack.config
import spack.deptypes as dt
import spack.solver.asp
@@ -23,7 +22,7 @@ def __init__(self, specs: List[str]) -> None:
self.concr_specs = []
def __enter__(self):
self.concr_specs = [spack.concretize.concretized(Spec(s)) for s in self.req_specs]
self.concr_specs = [Spec(s).concretized() for s in self.req_specs]
for s in self.concr_specs:
PackageInstaller([s.package], fake=True, explicit=True).install()
@@ -64,13 +63,13 @@ def _has_build_dependency(spec: Spec, name: str):
def test_simple_reuse(splicing_setup):
with CacheManager(["splice-z@1.0.0+compat"]):
spack.config.set("packages", _make_specs_non_buildable(["splice-z"]))
assert spack.concretize.concretized(Spec("splice-z")).satisfies(Spec("splice-z"))
assert Spec("splice-z").concretized().satisfies(Spec("splice-z"))
def test_simple_dep_reuse(splicing_setup):
with CacheManager(["splice-z@1.0.0+compat"]):
spack.config.set("packages", _make_specs_non_buildable(["splice-z"]))
assert spack.concretize.concretized(Spec("splice-h@1")).satisfies(Spec("splice-h@1"))
assert Spec("splice-h@1").concretized().satisfies(Spec("splice-h@1"))
def test_splice_installed_hash(splicing_setup):
@@ -83,9 +82,9 @@ def test_splice_installed_hash(splicing_setup):
spack.config.set("packages", packages_config)
goal_spec = Spec("splice-t@1 ^splice-h@1.0.2+compat ^splice-z@1.0.0")
with pytest.raises(Exception):
spack.concretize.concretized(goal_spec)
goal_spec.concretized()
_enable_splicing()
assert spack.concretize.concretized(goal_spec).satisfies(goal_spec)
assert goal_spec.concretized().satisfies(goal_spec)
def test_splice_build_splice_node(splicing_setup):
@@ -93,9 +92,9 @@ def test_splice_build_splice_node(splicing_setup):
spack.config.set("packages", _make_specs_non_buildable(["splice-t"]))
goal_spec = Spec("splice-t@1 ^splice-h@1.0.2+compat ^splice-z@1.0.0+compat")
with pytest.raises(Exception):
spack.concretize.concretized(goal_spec)
goal_spec.concretized()
_enable_splicing()
assert spack.concretize.concretized(goal_spec).satisfies(goal_spec)
assert goal_spec.concretized().satisfies(goal_spec)
def test_double_splice(splicing_setup):
@@ -109,9 +108,9 @@ def test_double_splice(splicing_setup):
spack.config.set("packages", freeze_builds_config)
goal_spec = Spec("splice-t@1 ^splice-h@1.0.2+compat ^splice-z@1.0.2+compat")
with pytest.raises(Exception):
spack.concretize.concretized(goal_spec)
goal_spec.concretized()
_enable_splicing()
assert spack.concretize.concretized(goal_spec).satisfies(goal_spec)
assert goal_spec.concretized().satisfies(goal_spec)
# The next two tests are mirrors of one another
@@ -128,10 +127,10 @@ def test_virtual_multi_splices_in(splicing_setup):
spack.config.set("packages", _make_specs_non_buildable(["depends-on-virtual-with-abi"]))
for gs in goal_specs:
with pytest.raises(Exception):
spack.concretize.concretized(Spec(gs))
Spec(gs).concretized()
_enable_splicing()
for gs in goal_specs:
assert spack.concretize.concretized(Spec(gs)).satisfies(gs)
assert Spec(gs).concretized().satisfies(gs)
def test_virtual_multi_can_be_spliced(splicing_setup):
@@ -145,12 +144,12 @@ def test_virtual_multi_can_be_spliced(splicing_setup):
]
with CacheManager(cache):
spack.config.set("packages", _make_specs_non_buildable(["depends-on-virtual-with-abi"]))
for gs in goal_specs:
with pytest.raises(Exception):
spack.concretize.concretized(Spec(gs))
with pytest.raises(Exception):
for gs in goal_specs:
Spec(gs).concretized()
_enable_splicing()
for gs in goal_specs:
assert spack.concretize.concretized(Spec(gs)).satisfies(gs)
assert Spec(gs).concretized().satisfies(gs)
def test_manyvariant_star_matching_variant_splice(splicing_setup):
@@ -168,10 +167,10 @@ def test_manyvariant_star_matching_variant_splice(splicing_setup):
spack.config.set("packages", freeze_build_config)
for goal in goal_specs:
with pytest.raises(Exception):
spack.concretize.concretized(goal)
goal.concretized()
_enable_splicing()
for goal in goal_specs:
assert spack.concretize.concretized(goal).satisfies(goal)
assert goal.concretized().satisfies(goal)
def test_manyvariant_limited_matching(splicing_setup):
@@ -190,10 +189,10 @@ def test_manyvariant_limited_matching(splicing_setup):
spack.config.set("packages", freeze_build_config)
for s in goal_specs:
with pytest.raises(Exception):
spack.concretize.concretized(s)
s.concretized()
_enable_splicing()
for s in goal_specs:
assert spack.concretize.concretized(s).satisfies(s)
assert s.concretized().satisfies(s)
def test_external_splice_same_name(splicing_setup):
@@ -212,7 +211,7 @@ def test_external_splice_same_name(splicing_setup):
spack.config.set("packages", packages_yaml)
_enable_splicing()
for s in goal_specs:
assert spack.concretize.concretized(s).satisfies(s)
assert s.concretized().satisfies(s)
def test_spliced_build_deps_only_in_build_spec(splicing_setup):
@@ -221,7 +220,7 @@ def test_spliced_build_deps_only_in_build_spec(splicing_setup):
with CacheManager(cache):
_enable_splicing()
concr_goal = spack.concretize.concretized(goal_spec)
concr_goal = goal_spec.concretized()
build_spec = concr_goal._build_spec
# Spec has been spliced
assert build_spec is not None
@@ -239,7 +238,7 @@ def test_spliced_transitive_dependency(splicing_setup):
with CacheManager(cache):
spack.config.set("packages", _make_specs_non_buildable(["splice-depends-on-t"]))
_enable_splicing()
concr_goal = spack.concretize.concretized(goal_spec)
concr_goal = goal_spec.concretized()
# Spec has been spliced
assert concr_goal._build_spec is not None
assert concr_goal["splice-t"]._build_spec is not None

View File

@@ -134,5 +134,5 @@ def test_concretize_target_ranges(root_target_range, dep_target_range, result, m
f"pkg-a %gcc@10 foobar=bar target={root_target_range} ^pkg-b target={dep_target_range}"
)
with spack.concretize.disable_compiler_existence_check():
spec = spack.concretize.concretized(spec)
spec.concretize()
assert spec.target == spec["pkg-b"].target == result

View File

@@ -28,12 +28,11 @@
import spack.binary_distribution as bindist
import spack.caches
import spack.compilers
import spack.concretize
import spack.config
import spack.fetch_strategy
import spack.hooks.sbang as sbang
import spack.main
import spack.mirrors.mirror
import spack.mirror
import spack.paths
import spack.spec
import spack.stage
@@ -214,9 +213,8 @@ def test_default_rpaths_create_install_default_layout(temporary_mirror_dir):
Test the creation and installation of buildcaches with default rpaths
into the default directory layout scheme.
"""
gspec = spack.concretize.concretized(Spec("garply"))
cspec = spack.concretize.concretized(Spec("corge"))
sy_spec = spack.concretize.concretized(Spec("symly"))
gspec, cspec = Spec("garply").concretized(), Spec("corge").concretized()
sy_spec = Spec("symly").concretized()
# Install 'corge' without using a cache
install_cmd("--no-cache", cspec.name)
@@ -263,9 +261,9 @@ def test_default_rpaths_install_nondefault_layout(temporary_mirror_dir):
Test the creation and installation of buildcaches with default rpaths
into the non-default directory layout scheme.
"""
cspec = spack.concretize.concretized(Spec("corge"))
cspec = Spec("corge").concretized()
# This guy tests for symlink relocation
sy_spec = spack.concretize.concretized(Spec("symly"))
sy_spec = Spec("symly").concretized()
# Install some packages with dependent packages
# test install in non-default install path scheme
@@ -286,8 +284,7 @@ def test_relative_rpaths_install_default_layout(temporary_mirror_dir):
Test the creation and installation of buildcaches with relative
rpaths into the default directory layout scheme.
"""
gspec = spack.concretize.concretized(Spec("garply"))
cspec = spack.concretize.concretized(Spec("corge"))
gspec, cspec = Spec("garply").concretized(), Spec("corge").concretized()
# Install buildcache created with relativized rpaths
buildcache_cmd("install", "-uf", cspec.name)
@@ -316,7 +313,7 @@ def test_relative_rpaths_install_nondefault(temporary_mirror_dir):
Test the installation of buildcaches with relativized rpaths
into the non-default directory layout scheme.
"""
cspec = spack.concretize.concretized(Spec("corge"))
cspec = Spec("corge").concretized()
# Test install in non-default install path scheme and relative path
buildcache_cmd("install", "-uf", cspec.name)
@@ -327,8 +324,8 @@ def test_push_and_fetch_keys(mock_gnupghome, tmp_path):
mirror = os.path.join(testpath, "mirror")
mirrors = {"test-mirror": url_util.path_to_file_url(mirror)}
mirrors = spack.mirrors.mirror.MirrorCollection(mirrors)
mirror = spack.mirrors.mirror.Mirror(url_util.path_to_file_url(mirror))
mirrors = spack.mirror.MirrorCollection(mirrors)
mirror = spack.mirror.Mirror(url_util.path_to_file_url(mirror))
gpg_dir1 = os.path.join(testpath, "gpg1")
gpg_dir2 = os.path.join(testpath, "gpg2")
@@ -369,8 +366,7 @@ def test_built_spec_cache(temporary_mirror_dir):
that cache from a buildcache index."""
buildcache_cmd("list", "-a", "-l")
gspec = spack.concretize.concretized(Spec("garply"))
cspec = spack.concretize.concretized(Spec("corge"))
gspec, cspec = Spec("garply").concretized(), Spec("corge").concretized()
for s in [gspec, cspec]:
results = bindist.get_mirrors_for_spec(s)
@@ -393,7 +389,7 @@ def test_spec_needs_rebuild(monkeypatch, tmpdir):
mirror_dir = tmpdir.join("mirror_dir")
mirror_url = url_util.path_to_file_url(mirror_dir.strpath)
s = spack.concretize.concretized(Spec("libdwarf"))
s = Spec("libdwarf").concretized()
# Install a package
install_cmd(s.name)
@@ -422,7 +418,7 @@ def test_generate_index_missing(monkeypatch, tmpdir, mutable_config):
mirror_url = url_util.path_to_file_url(mirror_dir.strpath)
spack.config.set("mirrors", {"test": mirror_url})
s = spack.concretize.concretized(Spec("libdwarf"))
s = Spec("libdwarf").concretized()
# Install a package
install_cmd("--no-cache", s.name)
@@ -512,7 +508,7 @@ def test_update_sbang(tmpdir, temporary_mirror):
"""
spec_str = "old-sbang"
# Concretize a package with some old-fashioned sbang lines.
old_spec = spack.concretize.concretized(Spec(spec_str))
old_spec = Spec(spec_str).concretized()
old_spec_hash_str = "/{0}".format(old_spec.dag_hash())
# Need a fake mirror with *function* scope.
@@ -533,7 +529,7 @@ def test_update_sbang(tmpdir, temporary_mirror):
# Switch the store to the new install tree locations
newtree_dir = tmpdir.join("newtree")
with spack.store.use_store(str(newtree_dir)):
new_spec = spack.concretize.concretized(Spec("old-sbang"))
new_spec = Spec("old-sbang").concretized()
assert new_spec.dag_hash() == old_spec.dag_hash()
# Install package from buildcache

View File

@@ -9,8 +9,7 @@
import pytest
import spack.binary_distribution as bd
import spack.concretize
import spack.mirrors.mirror
import spack.mirror
import spack.spec
from spack.installer import PackageInstaller
@@ -18,13 +17,13 @@
def test_build_tarball_overwrite(install_mockery, mock_fetch, monkeypatch, tmp_path):
spec = spack.concretize.concretized(spack.spec.Spec("trivial-install-test-package"))
spec = spack.spec.Spec("trivial-install-test-package").concretized()
PackageInstaller([spec.package], fake=True).install()
specs = [spec]
# populate cache, everything is new
mirror = spack.mirrors.mirror.Mirror.from_local_path(str(tmp_path))
mirror = spack.mirror.Mirror.from_local_path(str(tmp_path))
with bd.make_uploader(mirror) as uploader:
skipped = uploader.push_or_raise(specs)
assert not skipped

View File

@@ -17,7 +17,6 @@
import spack.build_environment
import spack.compiler
import spack.compilers
import spack.concretize
import spack.config
import spack.deptypes as dt
import spack.package_base
@@ -165,7 +164,8 @@ def test_static_to_shared_library(build_environment):
@pytest.mark.regression("8345")
@pytest.mark.usefixtures("config", "mock_packages")
def test_cc_not_changed_by_modules(monkeypatch, working_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake"))
s = spack.spec.Spec("cmake")
s.concretize()
pkg = s.package
def _set_wrong_cc(x):
@@ -185,7 +185,7 @@ def test_setup_dependent_package_inherited_modules(
working_env, mock_packages, install_mockery, mock_fetch
):
# This will raise on regression
s = spack.concretize.concretized(spack.spec.Spec("cmake-client-inheritor"))
s = spack.spec.Spec("cmake-client-inheritor").concretized()
PackageInstaller([s.package]).install()
@@ -278,7 +278,7 @@ def platform_pathsep(pathlist):
return convert_to_platform_path(pathlist)
# Monkeypatch a pkg.compiler.environment with the required modifications
pkg = spack.concretize.concretized(spack.spec.Spec("cmake")).package
pkg = spack.spec.Spec("cmake").concretized().package
monkeypatch.setattr(pkg.compiler, "environment", modifications)
# Trigger the modifications
spack.build_environment.setup_package(pkg, False)
@@ -302,7 +302,7 @@ def custom_env(pkg, env):
env.prepend_path("PATH", test_path)
env.append_flags("ENV_CUSTOM_CC_FLAGS", "--custom-env-flag1")
pkg = spack.concretize.concretized(spack.spec.Spec("cmake")).package
pkg = spack.spec.Spec("cmake").concretized().package
monkeypatch.setattr(pkg.compiler, "setup_custom_environment", custom_env)
spack.build_environment.setup_package(pkg, False)
@@ -323,7 +323,7 @@ def test_external_config_env(mock_packages, mutable_config, working_env):
}
spack.config.set("packages:cmake", cmake_config)
cmake_client = spack.concretize.concretized(spack.spec.Spec("cmake-client"))
cmake_client = spack.spec.Spec("cmake-client").concretized()
spack.build_environment.setup_package(cmake_client.package, False)
assert os.environ["TEST_ENV_VAR_SET"] == "yes it's set"
@@ -331,7 +331,8 @@ def test_external_config_env(mock_packages, mutable_config, working_env):
@pytest.mark.regression("9107")
def test_spack_paths_before_module_paths(config, mock_packages, monkeypatch, working_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake"))
s = spack.spec.Spec("cmake")
s.concretize()
pkg = s.package
module_path = os.path.join("path", "to", "module")
@@ -352,7 +353,8 @@ def _set_wrong_cc(x):
def test_package_inheritance_module_setup(config, mock_packages, working_env):
s = spack.concretize.concretized(spack.spec.Spec("multimodule-inheritance"))
s = spack.spec.Spec("multimodule-inheritance")
s.concretize()
pkg = s.package
spack.build_environment.setup_package(pkg, False)
@@ -386,7 +388,8 @@ def test_wrapper_variables(
not in cuda_include_dirs
)
root = spack.concretize.concretized(spack.spec.Spec("dt-diamond"))
root = spack.spec.Spec("dt-diamond")
root.concretize()
for s in root.traverse():
s.prefix = "/{0}-prefix/".format(s.name)
@@ -451,7 +454,7 @@ def test_external_prefixes_last(mutable_config, mock_packages, working_env, monk
"""
)
spack.config.set("packages", cfg_data)
top = spack.concretize.concretized(spack.spec.Spec("dt-diamond"))
top = spack.spec.Spec("dt-diamond").concretized()
def _trust_me_its_a_dir(path):
return True
@@ -498,7 +501,8 @@ def test_parallel_false_is_not_propagating(default_mock_concretization):
)
def test_setting_dtags_based_on_config(config_setting, expected_flag, config, mock_packages):
# Pick a random package to be able to set compiler's variables
s = spack.concretize.concretized(spack.spec.Spec("cmake"))
s = spack.spec.Spec("cmake")
s.concretize()
pkg = s.package
env = EnvironmentModifications()
@@ -530,7 +534,7 @@ def setup_dependent_package(module, dependent_spec):
assert dependent_module.ninja is not None
dependent_spec.package.test_attr = True
externaltool = spack.concretize.concretized(spack.spec.Spec("externaltest"))
externaltool = spack.spec.Spec("externaltest").concretized()
monkeypatch.setattr(
externaltool["externaltool"].package, "setup_dependent_package", setup_dependent_package
)
@@ -725,7 +729,7 @@ def test_build_system_globals_only_set_on_root_during_build(default_mock_concret
But obviously it can lead to very hard to find bugs... We should get rid of those globals and
define them instead as a property on the package instance.
"""
root = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
root = spack.spec.Spec("mpileaks").concretized()
build_variables = ("std_cmake_args", "std_meson_args", "std_pip_args")
# See todo above, we clear out any properties that may have been set by the previous test.

View File

@@ -16,7 +16,6 @@
import spack.build_systems.autotools
import spack.build_systems.cmake
import spack.builder
import spack.concretize
import spack.environment
import spack.error
import spack.paths
@@ -146,7 +145,7 @@ def test_none_is_allowed(self, default_mock_concretization):
def test_libtool_archive_files_are_deleted_by_default(self, mutable_database):
# Install a package that creates a mock libtool archive
s = spack.concretize.concretized(Spec("libtool-deletion"))
s = Spec("libtool-deletion").concretized()
PackageInstaller([s.package], explicit=True).install()
# Assert the libtool archive is not there and we have
@@ -161,7 +160,7 @@ def test_libtool_archive_files_might_be_installed_on_demand(
):
# Install a package that creates a mock libtool archive,
# patch its package to preserve the installation
s = spack.concretize.concretized(Spec("libtool-deletion"))
s = Spec("libtool-deletion").concretized()
monkeypatch.setattr(
type(spack.builder.create(s.package)), "install_libtool_archives", True
)
@@ -175,9 +174,7 @@ def test_autotools_gnuconfig_replacement(self, mutable_database):
Tests whether only broken config.sub and config.guess are replaced with
files from working alternatives from the gnuconfig package.
"""
s = spack.concretize.concretized(
Spec("autotools-config-replacement +patch_config_files +gnuconfig")
)
s = Spec("autotools-config-replacement +patch_config_files +gnuconfig").concretized()
PackageInstaller([s.package]).install()
with open(os.path.join(s.prefix.broken, "config.sub")) as f:
@@ -196,9 +193,7 @@ def test_autotools_gnuconfig_replacement_disabled(self, mutable_database):
"""
Tests whether disabling patch_config_files
"""
s = spack.concretize.concretized(
Spec("autotools-config-replacement ~patch_config_files +gnuconfig")
)
s = Spec("autotools-config-replacement ~patch_config_files +gnuconfig").concretized()
PackageInstaller([s.package]).install()
with open(os.path.join(s.prefix.broken, "config.sub")) as f:
@@ -223,9 +218,8 @@ def test_autotools_gnuconfig_replacement_no_gnuconfig(self, mutable_database, mo
enabled, but gnuconfig is not listed as a direct build dependency.
"""
monkeypatch.setattr(spack.platforms.test.Test, "default", "x86_64")
s = spack.concretize.concretized(
Spec("autotools-config-replacement +patch_config_files ~gnuconfig")
)
s = Spec("autotools-config-replacement +patch_config_files ~gnuconfig")
s.concretize()
msg = "Cannot patch config files: missing dependencies: gnuconfig"
with pytest.raises(ChildError, match=msg):
@@ -305,7 +299,7 @@ def test_define(self, default_mock_concretization):
assert define("SINGLE", "red") == "-DSINGLE:STRING=red"
def test_define_from_variant(self):
s = spack.concretize.concretized(Spec("cmake-client multi=up,right ~truthy single=red"))
s = Spec("cmake-client multi=up,right ~truthy single=red").concretized()
arg = s.package.define_from_variant("MULTI")
assert arg == "-DMULTI:STRING=right;up"

View File

@@ -9,7 +9,6 @@
from llnl.util.filesystem import touch
import spack.builder
import spack.concretize
import spack.paths
import spack.repo
import spack.spec
@@ -80,7 +79,7 @@ def builder_test_repository():
@pytest.mark.disable_clean_stage_check
def test_callbacks_and_installation_procedure(spec_str, expected_values, working_env):
"""Test the correct execution of callbacks and installation procedures for packages."""
s = spack.concretize.concretized(spack.spec.Spec(spec_str))
s = spack.spec.Spec(spec_str).concretized()
builder = spack.builder.create(s.package)
for phase_fn in builder:
phase_fn.execute()
@@ -103,7 +102,7 @@ def test_callbacks_and_installation_procedure(spec_str, expected_values, working
],
)
def test_old_style_compatibility_with_super(spec_str, method_name, expected):
s = spack.concretize.concretized(spack.spec.Spec(spec_str))
s = spack.spec.Spec(spec_str).concretized()
builder = spack.builder.create(s.package)
value = getattr(builder, method_name)()
assert value == expected
@@ -114,7 +113,7 @@ def test_old_style_compatibility_with_super(spec_str, method_name, expected):
@pytest.mark.usefixtures("builder_test_repository", "config", "working_env")
@pytest.mark.disable_clean_stage_check
def test_build_time_tests_are_executed_from_default_builder():
s = spack.concretize.concretized(spack.spec.Spec("old-style-autotools"))
s = spack.spec.Spec("old-style-autotools").concretized()
builder = spack.builder.create(s.package)
builder.pkg.run_tests = True
for phase_fn in builder:
@@ -128,7 +127,7 @@ def test_build_time_tests_are_executed_from_default_builder():
@pytest.mark.usefixtures("builder_test_repository", "config", "working_env")
def test_monkey_patching_wrapped_pkg():
"""Confirm 'run_tests' is accessible through wrappers."""
s = spack.concretize.concretized(spack.spec.Spec("old-style-autotools"))
s = spack.spec.Spec("old-style-autotools").concretized()
builder = spack.builder.create(s.package)
assert s.package.run_tests is False
assert builder.pkg.run_tests is False
@@ -143,7 +142,7 @@ def test_monkey_patching_wrapped_pkg():
@pytest.mark.usefixtures("builder_test_repository", "config", "working_env")
def test_monkey_patching_test_log_file():
"""Confirm 'test_log_file' is accessible through wrappers."""
s = spack.concretize.concretized(spack.spec.Spec("old-style-autotools"))
s = spack.spec.Spec("old-style-autotools").concretized()
builder = spack.builder.create(s.package)
s.package.tester.test_log_file = "/some/file"
@@ -156,7 +155,7 @@ def test_monkey_patching_test_log_file():
@pytest.mark.not_on_windows("Does not run on windows")
def test_install_time_test_callback(tmpdir, config, mock_packages, mock_stage):
"""Confirm able to run stand-alone test as a post-install callback."""
s = spack.concretize.concretized(spack.spec.Spec("py-test-callback"))
s = spack.spec.Spec("py-test-callback").concretized()
builder = spack.builder.create(s.package)
builder.pkg.run_tests = True
s.package.tester.test_log_file = tmpdir.join("install_test.log")
@@ -176,7 +175,7 @@ def test_mixins_with_builders(working_env):
"""Tests that run_after and run_before callbacks are accumulated correctly,
when mixins are used with builders.
"""
s = spack.concretize.concretized(spack.spec.Spec("builder-and-mixins"))
s = spack.spec.Spec("builder-and-mixins").concretized()
builder = spack.builder.create(s.package)
# Check that callbacks added by the mixin are in the list

View File

@@ -5,7 +5,6 @@
import pytest
import spack.concretize
import spack.deptypes as dt
import spack.installer as inst
import spack.repo
@@ -23,7 +22,8 @@ def test_build_request_errors(install_mockery):
def test_build_request_basics(install_mockery):
spec = spack.concretize.concretized(spack.spec.Spec("dependent-install"))
spec = spack.spec.Spec("dependent-install")
spec.concretize()
assert spec.concrete
# Ensure key properties match expectations
@@ -40,7 +40,8 @@ def test_build_request_basics(install_mockery):
def test_build_request_strings(install_mockery):
"""Tests of BuildRequest repr and str for coverage purposes."""
# Using a package with one dependency
spec = spack.concretize.concretized(spack.spec.Spec("dependent-install"))
spec = spack.spec.Spec("dependent-install")
spec.concretize()
assert spec.concrete
# Ensure key properties match expectations
@@ -72,7 +73,7 @@ def test_build_request_deptypes(
package_deptypes,
dependencies_deptypes,
):
s = spack.concretize.concretized(spack.spec.Spec("dependent-install"))
s = spack.spec.Spec("dependent-install").concretized()
build_request = inst.BuildRequest(
s.package,

View File

@@ -5,7 +5,6 @@
import pytest
import spack.concretize
import spack.error
import spack.installer as inst
import spack.repo
@@ -26,7 +25,7 @@ def test_build_task_errors(install_mockery):
inst.BuildTask(pkg_cls(spec), None)
# Using a concretized package now means the request argument is checked.
spec = spack.concretize.concretized(spec)
spec.concretize()
assert spec.concrete
with pytest.raises(TypeError, match="is not a valid build request"):
@@ -49,7 +48,8 @@ def test_build_task_errors(install_mockery):
def test_build_task_basics(install_mockery):
spec = spack.concretize.concretized(spack.spec.Spec("dependent-install"))
spec = spack.spec.Spec("dependent-install")
spec.concretize()
assert spec.concrete
# Ensure key properties match expectations
@@ -70,7 +70,8 @@ def test_build_task_basics(install_mockery):
def test_build_task_strings(install_mockery):
"""Tests of build_task repr and str for coverage purposes."""
# Using a package with one dependency
spec = spack.concretize.concretized(spack.spec.Spec("dependent-install"))
spec = spack.spec.Spec("dependent-install")
spec.concretize()
assert spec.concrete
# Ensure key properties match expectations

View File

@@ -10,7 +10,6 @@
import llnl.util.filesystem as fs
import spack.ci as ci
import spack.concretize
import spack.environment as ev
import spack.error
import spack.paths as spack_paths
@@ -327,7 +326,7 @@ def test_ci_run_standalone_tests_not_installed_junit(
log_file = tmp_path / "junit.xml"
args = {
"log_file": str(log_file),
"job_spec": spack.concretize.concretized(spack.spec.Spec("printing-package")),
"job_spec": spack.spec.Spec("printing-package").concretized(),
"repro_dir": str(repro_dir),
"fail_fast": True,
}
@@ -346,7 +345,7 @@ def test_ci_run_standalone_tests_not_installed_cdash(
log_file = tmp_path / "junit.xml"
args = {
"log_file": str(log_file),
"job_spec": spack.concretize.concretized(spack.spec.Spec("printing-package")),
"job_spec": spack.spec.Spec("printing-package").concretized(),
"repro_dir": str(repro_dir),
}
@@ -379,7 +378,7 @@ def test_ci_run_standalone_tests_not_installed_cdash(
def test_ci_skipped_report(tmpdir, mock_packages, config):
"""Test explicit skipping of report as well as CI's 'package' arg."""
pkg = "trivial-smoke-test"
spec = spack.concretize.concretized(spack.spec.Spec(pkg))
spec = spack.spec.Spec(pkg).concretized()
ci_cdash = {
"url": "file://fake",
"build-group": "fake-group",

View File

@@ -11,11 +11,11 @@
import spack.bootstrap
import spack.bootstrap.core
import spack.concretize
import spack.config
import spack.environment as ev
import spack.main
import spack.mirrors.utils
import spack.mirror
import spack.spec
_bootstrap = spack.main.SpackCommand("bootstrap")
@@ -182,9 +182,9 @@ def test_bootstrap_mirror_metadata(mutable_config, linux_os, monkeypatch, tmpdir
`spack bootstrap add`. Here we don't download data, since that would be an
expensive operation for a unit test.
"""
old_create = spack.mirrors.utils.create
monkeypatch.setattr(spack.mirrors.utils, "create", lambda p, s: old_create(p, []))
monkeypatch.setattr(spack.concretize, "concretized", lambda p: p)
old_create = spack.mirror.create
monkeypatch.setattr(spack.mirror, "create", lambda p, s: old_create(p, []))
monkeypatch.setattr(spack.spec.Spec, "concretized", lambda p: p)
# Create the mirror in a temporary folder
compilers = [

View File

@@ -13,11 +13,10 @@
import spack.binary_distribution
import spack.cmd.buildcache
import spack.concretize
import spack.environment as ev
import spack.error
import spack.main
import spack.mirrors.mirror
import spack.mirror
import spack.spec
import spack.util.url
from spack.installer import PackageInstaller
@@ -83,7 +82,7 @@ def tests_buildcache_create(install_mockery, mock_fetch, monkeypatch, tmpdir):
buildcache("push", "--unsigned", str(tmpdir), pkg)
spec = spack.concretize.concretized(Spec(pkg))
spec = Spec(pkg).concretized()
tarball_path = spack.binary_distribution.tarball_path_name(spec, ".spack")
tarball = spack.binary_distribution.tarball_name(spec, ".spec.json")
assert os.path.exists(os.path.join(str(tmpdir), "build_cache", tarball_path))
@@ -103,7 +102,7 @@ def tests_buildcache_create_env(
buildcache("push", "--unsigned", str(tmpdir))
spec = spack.concretize.concretized(Spec(pkg))
spec = Spec(pkg).concretized()
tarball_path = spack.binary_distribution.tarball_path_name(spec, ".spack")
tarball = spack.binary_distribution.tarball_name(spec, ".spec.json")
assert os.path.exists(os.path.join(str(tmpdir), "build_cache", tarball_path))
@@ -147,7 +146,7 @@ def test_update_key_index(
gpg("create", "Test Signing Key", "nobody@nowhere.com")
s = spack.concretize.concretized(Spec("libdwarf"))
s = Spec("libdwarf").concretized()
# Install a package
install(s.name)
@@ -177,7 +176,7 @@ def test_buildcache_autopush(tmp_path, install_mockery, mock_fetch):
mirror("add", "--unsigned", "mirror", mirror_dir.as_uri())
mirror("add", "--autopush", "--unsigned", "mirror-autopush", mirror_autopush_dir.as_uri())
s = spack.concretize.concretized(Spec("libdwarf"))
s = Spec("libdwarf").concretized()
# Install and generate build cache index
PackageInstaller([s.package], explicit=True).install()
@@ -221,7 +220,7 @@ def verify_mirror_contents():
assert False
# Install a package and put it in the buildcache
s = spack.concretize.concretized(Spec(out_env_pkg))
s = Spec(out_env_pkg).concretized()
install(s.name)
buildcache("push", "-u", "-f", src_mirror_url, s.name)
@@ -331,7 +330,7 @@ def test_buildcache_create_install(
buildcache("push", "--unsigned", str(tmpdir), pkg)
spec = spack.concretize.concretized(Spec(pkg))
spec = Spec(pkg).concretized()
tarball_path = spack.binary_distribution.tarball_path_name(spec, ".spack")
tarball = spack.binary_distribution.tarball_name(spec, ".spec.json")
assert os.path.exists(os.path.join(str(tmpdir), "build_cache", tarball_path))
@@ -386,9 +385,7 @@ def test_correct_specs_are_pushed(
class DontUpload(spack.binary_distribution.Uploader):
def __init__(self):
super().__init__(
spack.mirrors.mirror.Mirror.from_local_path(str(tmpdir)), False, False
)
super().__init__(spack.mirror.Mirror.from_local_path(str(tmpdir)), False, False)
self.pushed = []
def push(self, specs: List[spack.spec.Spec]):
@@ -452,7 +449,7 @@ def test_push_and_install_with_mirror_marked_unsigned_does_not_require_extra_fla
def test_skip_no_redistribute(mock_packages, config):
specs = list(spack.concretize.concretized(Spec("no-redistribute-dependent")).traverse())
specs = list(Spec("no-redistribute-dependent").concretized().traverse())
filtered = spack.cmd.buildcache._skip_no_redistribute_for_public(specs)
assert not any(s.name == "no-redistribute" for s in filtered)
assert any(s.name == "no-redistribute-dependent" for s in filtered)
@@ -492,7 +489,7 @@ def test_push_without_build_deps(tmp_path, temporary_store, mock_packages, mutab
mirror("add", "--unsigned", "my-mirror", str(tmp_path))
s = spack.concretize.concretized(spack.spec.Spec("dtrun3"))
s = spack.spec.Spec("dtrun3").concretized()
PackageInstaller([s.package], explicit=True, fake=True).install()
s["dtbuild3"].package.do_uninstall()

View File

@@ -8,7 +8,6 @@
import pytest
import spack.cmd.checksum
import spack.concretize
import spack.error
import spack.package_base
import spack.repo
@@ -310,7 +309,7 @@ def test_checksum_url(mock_packages, config):
def test_checksum_verification_fails(default_mock_concretization, capsys, can_fetch_versions):
spec = spack.concretize.concretized(spack.spec.Spec("zlib"))
spec = spack.spec.Spec("zlib").concretized()
pkg = spec.package
versions = list(pkg.versions.keys())
version_hashes = {versions[0]: "abadhash", Version("0.1"): "123456789"}

View File

@@ -19,7 +19,6 @@
import spack.ci as ci
import spack.cmd
import spack.cmd.ci
import spack.concretize
import spack.environment as ev
import spack.hash_types as ht
import spack.main
@@ -146,7 +145,7 @@ def test_specs_staging(config, tmpdir):
builder.add_package("pkg-a", dependencies=[("pkg-b", None, None), ("pkg-c", None, None)])
with repo.use_repositories(builder.root):
spec_a = spack.concretize.concretized(Spec("pkg-a"))
spec_a = Spec("pkg-a").concretized()
spec_a_label = ci._spec_ci_label(spec_a)
spec_b_label = ci._spec_ci_label(spec_a["pkg-b"])
@@ -1109,7 +1108,7 @@ def test_ci_rebuild_index(
with working_dir(tmp_path):
env_cmd("create", "test", "./spack.yaml")
with ev.read("test"):
concrete_spec = spack.concretize.concretized(Spec("callpath"))
concrete_spec = Spec("callpath").concretized()
with open(tmp_path / "spec.json", "w") as f:
f.write(concrete_spec.to_json(hash=ht.dag_hash))
@@ -1230,10 +1229,12 @@ def test_ci_generate_read_broken_specs_url(
ci_base_environment,
):
"""Verify that `broken-specs-url` works as intended"""
spec_a = spack.concretize.concretized(Spec("pkg-a"))
spec_a = Spec("pkg-a")
spec_a.concretize()
a_dag_hash = spec_a.dag_hash()
spec_flattendeps = spack.concretize.concretized(Spec("flatten-deps"))
spec_flattendeps = Spec("flatten-deps")
spec_flattendeps.concretize()
flattendeps_dag_hash = spec_flattendeps.dag_hash()
broken_specs_url = tmp_path.as_uri()
@@ -1584,7 +1585,8 @@ def dynamic_mapping_setup(tmpdir):
"""
)
spec_a = spack.concretize.concretized(Spec("pkg-a"))
spec_a = Spec("pkg-a")
spec_a.concretize()
return ci.get_job_name(spec_a)

View File

@@ -11,10 +11,10 @@
import spack.caches
import spack.cmd.clean
import spack.concretize
import spack.environment as ev
import spack.main
import spack.package_base
import spack.spec
import spack.stage
import spack.store
@@ -78,7 +78,7 @@ def test_env_aware_clean(mock_stage, install_mockery, mutable_mock_env_path, mon
def fail(*args, **kwargs):
raise Exception("This should not have been called")
monkeypatch.setattr(spack.concretize, "concretized", fail)
monkeypatch.setattr(spack.spec.Spec, "concretize", fail)
with e:
clean("mpileaks")

View File

@@ -9,7 +9,6 @@
import llnl.util.filesystem as fs
import spack.concretize
import spack.config
import spack.database
import spack.environment as ev
@@ -595,7 +594,8 @@ def test_config_prefer_upstream(
prepared_db = spack.database.Database(mock_db_root, layout=gen_mock_layout("/a/"))
for spec in ["hdf5 +mpi", "hdf5 ~mpi", "boost+debug~icu+graph", "dependency-install", "patch"]:
dep = spack.concretize.concretized(spack.spec.Spec(spec))
dep = spack.spec.Spec(spec)
dep.concretize()
prepared_db.add(dep)
downstream_db_root = str(tmpdir_factory.mktemp("mock_downstream_db_root"))

View File

@@ -5,7 +5,6 @@
import pytest
import spack.concretize
import spack.spec
import spack.store
from spack.enums import InstallRecordStatus
@@ -68,8 +67,8 @@ def test_deprecate_deps(mock_packages, mock_archive, mock_fetch, install_mockery
install("libdwarf@20130729 ^libelf@0.8.13")
install("libdwarf@20130207 ^libelf@0.8.10")
new_spec = spack.concretize.concretized(spack.spec.Spec("libdwarf@20130729^libelf@0.8.13"))
old_spec = spack.concretize.concretized(spack.spec.Spec("libdwarf@20130207^libelf@0.8.10"))
new_spec = spack.spec.Spec("libdwarf@20130729^libelf@0.8.13").concretized()
old_spec = spack.spec.Spec("libdwarf@20130207^libelf@0.8.10").concretized()
all_installed = spack.store.STORE.db.query()
@@ -109,12 +108,12 @@ def test_deprecate_already_deprecated(mock_packages, mock_archive, mock_fetch, i
install("libelf@0.8.12")
install("libelf@0.8.10")
deprecated_spec = spack.concretize.concretized(spack.spec.Spec("libelf@0.8.10"))
deprecated_spec = spack.spec.Spec("libelf@0.8.10").concretized()
deprecate("-y", "libelf@0.8.10", "libelf@0.8.12")
deprecator = spack.store.STORE.db.deprecator(deprecated_spec)
assert deprecator == spack.concretize.concretized(spack.spec.Spec("libelf@0.8.12"))
assert deprecator == spack.spec.Spec("libelf@0.8.12").concretized()
deprecate("-y", "libelf@0.8.10", "libelf@0.8.13")
@@ -124,7 +123,7 @@ def test_deprecate_already_deprecated(mock_packages, mock_archive, mock_fetch, i
assert len(all_available) == 3
deprecator = spack.store.STORE.db.deprecator(deprecated_spec)
assert deprecator == spack.concretize.concretized(spack.spec.Spec("libelf@0.8.13"))
assert deprecator == spack.spec.Spec("libelf@0.8.13").concretized()
def test_deprecate_deprecator(mock_packages, mock_archive, mock_fetch, install_mockery):
@@ -134,9 +133,9 @@ def test_deprecate_deprecator(mock_packages, mock_archive, mock_fetch, install_m
install("libelf@0.8.12")
install("libelf@0.8.10")
first_deprecated_spec = spack.concretize.concretized(spack.spec.Spec("libelf@0.8.10"))
second_deprecated_spec = spack.concretize.concretized(spack.spec.Spec("libelf@0.8.12"))
final_deprecator = spack.concretize.concretized(spack.spec.Spec("libelf@0.8.13"))
first_deprecated_spec = spack.spec.Spec("libelf@0.8.10").concretized()
second_deprecated_spec = spack.spec.Spec("libelf@0.8.12").concretized()
final_deprecator = spack.spec.Spec("libelf@0.8.13").concretized()
deprecate("-y", "libelf@0.8.10", "libelf@0.8.12")
@@ -166,7 +165,7 @@ def test_concretize_deprecated(mock_packages, mock_archive, mock_fetch, install_
spec = spack.spec.Spec("libelf@0.8.10")
with pytest.raises(spack.spec.SpecDeprecatedError):
spack.concretize.concretized(spec)
spec.concretize()
@pytest.mark.usefixtures("mock_packages", "mock_archive", "mock_fetch", "install_mockery")

View File

@@ -9,7 +9,6 @@
import llnl.util.filesystem as fs
import spack.concretize
import spack.environment as ev
import spack.error
import spack.repo
@@ -25,9 +24,7 @@
def test_dev_build_basics(tmpdir, install_mockery):
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}").concretized()
assert "dev_path" in spec.variants
@@ -45,9 +42,7 @@ def test_dev_build_basics(tmpdir, install_mockery):
def test_dev_build_before(tmpdir, install_mockery):
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}").concretized()
with tmpdir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -63,9 +58,7 @@ def test_dev_build_before(tmpdir, install_mockery):
def test_dev_build_until(tmpdir, install_mockery):
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}").concretized()
with tmpdir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -83,9 +76,7 @@ def test_dev_build_until(tmpdir, install_mockery):
def test_dev_build_until_last_phase(tmpdir, install_mockery):
# Test that we ignore the last_phase argument if it is already last
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}").concretized()
with tmpdir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -103,9 +94,7 @@ def test_dev_build_until_last_phase(tmpdir, install_mockery):
def test_dev_build_before_until(tmpdir, install_mockery):
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={tmpdir}").concretized()
with tmpdir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -141,9 +130,8 @@ def test_dev_build_drop_in(tmpdir, mock_packages, monkeypatch, install_mockery,
def test_dev_build_fails_already_installed(tmpdir, install_mockery):
spec = spack.concretize.concretized(
spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % tmpdir)
)
spec = spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % tmpdir)
spec.concretize()
with tmpdir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -185,9 +173,8 @@ def test_dev_build_env(tmpdir, install_mockery, mutable_mock_env_path):
"""Test Spack does dev builds for packages in develop section of env."""
# setup dev-build-test-install package for dev build
build_dir = tmpdir.mkdir("build")
spec = spack.concretize.concretized(
spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % build_dir)
)
spec = spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % build_dir)
spec.concretize()
with build_dir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -222,9 +209,8 @@ def test_dev_build_env_with_vars(tmpdir, install_mockery, mutable_mock_env_path,
"""Test Spack does dev builds for packages in develop section of env (path with variables)."""
# setup dev-build-test-install package for dev build
build_dir = tmpdir.mkdir("build")
spec = spack.concretize.concretized(
spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={build_dir}")
)
spec = spack.spec.Spec(f"dev-build-test-install@0.0.0 dev_path={build_dir}")
spec.concretize()
# store the build path in an environment variable that will be used in the environment
monkeypatch.setenv("CUSTOM_BUILD_PATH", build_dir)
@@ -261,9 +247,8 @@ def test_dev_build_env_version_mismatch(tmpdir, install_mockery, mutable_mock_en
"""Test Spack constraints concretization by develop specs."""
# setup dev-build-test-install package for dev build
build_dir = tmpdir.mkdir("build")
spec = spack.concretize.concretized(
spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % tmpdir)
)
spec = spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % tmpdir)
spec.concretize()
with build_dir.as_cwd():
with open(spec.package.filename, "w") as f:
@@ -343,8 +328,8 @@ def test_dev_build_multiple(tmpdir, install_mockery, mutable_mock_env_path, mock
with ev.read("test"):
# Do concretization inside environment for dev info
# These specs are the source of truth to compare against the installs
leaf_spec = spack.concretize.concretized(leaf_spec)
root_spec = spack.concretize.concretized(root_spec)
leaf_spec.concretize()
root_spec.concretize()
# Do install
install()
@@ -390,8 +375,8 @@ def test_dev_build_env_dependency(tmpdir, install_mockery, mock_fetch, mutable_m
# concretize in the environment to get the dev build info
# equivalent to setting dev_build and dev_path variants
# on all specs above
spec = spack.concretize.concretized(spec)
dep_spec = spack.concretize.concretized(dep_spec)
spec.concretize()
dep_spec.concretize()
install()
# Ensure that both specs installed properly
@@ -415,9 +400,8 @@ def test_dev_build_rebuild_on_source_changes(
"""
# setup dev-build-test-install package for dev build
build_dir = tmpdir.mkdir("build")
spec = spack.concretize.concretized(
spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % build_dir)
)
spec = spack.spec.Spec("dev-build-test-install@0.0.0 dev_path=%s" % build_dir)
spec.concretize()
def reset_string():
with build_dir.as_cwd():

View File

@@ -9,7 +9,6 @@
import llnl.util.filesystem as fs
import spack.concretize
import spack.config
import spack.environment as ev
import spack.package_base
@@ -140,8 +139,7 @@ def check_path(stage, dest):
self.check_develop(e, spack.spec.Spec("mpich@=1.0"), path)
# Check modifications actually worked
result = spack.concretize.concretized(spack.spec.Spec("mpich@1.0"))
assert result.satisfies("dev_path=%s" % abspath)
assert spack.spec.Spec("mpich@1.0").concretized().satisfies("dev_path=%s" % abspath)
def test_develop_canonicalize_path_no_args(self, monkeypatch):
env("create", "test")
@@ -168,8 +166,7 @@ def check_path(stage, dest):
self.check_develop(e, spack.spec.Spec("mpich@=1.0"), path)
# Check modifications actually worked
result = spack.concretize.concretized(spack.spec.Spec("mpich@1.0"))
assert result.satisfies("dev_path=%s" % abspath)
assert spack.spec.Spec("mpich@1.0").concretized().satisfies("dev_path=%s" % abspath)
def _git_commit_list(git_repo_dir):
@@ -194,7 +191,7 @@ def test_develop_full_git_repo(
spack.package_base.PackageBase, "git", "file://%s" % repo_path, raising=False
)
spec = spack.concretize.concretized(spack.spec.Spec("git-test-commit@1.2"))
spec = spack.spec.Spec("git-test-commit@1.2").concretized()
try:
spec.package.do_stage()
commits = _git_commit_list(spec.package.stage[0].source_path)

View File

@@ -6,7 +6,6 @@
import pytest
import spack.cmd.diff
import spack.concretize
import spack.main
import spack.repo
import spack.spec
@@ -21,8 +20,6 @@
_p1 = (
"p1",
"""\
from spack.package import *
class P1(Package):
version("1.0")
@@ -38,8 +35,6 @@ class P1(Package):
_p2 = (
"p2",
"""\
from spack.package import *
class P2(Package):
version("1.0")
@@ -53,8 +48,6 @@ class P2(Package):
_p3 = (
"p3",
"""\
from spack.package import *
class P3(Package):
version("1.0")
@@ -65,8 +58,6 @@ class P3(Package):
_i1 = (
"i1",
"""\
from spack.package import *
class I1(Package):
version("1.0")
@@ -82,8 +73,6 @@ class I1(Package):
_i2 = (
"i2",
"""\
from spack.package import *
class I2(Package):
version("1.0")
@@ -100,8 +89,6 @@ class I2(Package):
_p4 = (
"p4",
"""\
from spack.package import *
class P4(Package):
version("1.0")
@@ -135,8 +122,8 @@ def test_repo(_create_test_repo, monkeypatch, mock_stage):
def test_diff_ignore(test_repo):
specA = spack.concretize.concretized(spack.spec.Spec("p1+usev1"))
specB = spack.concretize.concretized(spack.spec.Spec("p1~usev1"))
specA = spack.spec.Spec("p1+usev1").concretized()
specB = spack.spec.Spec("p1~usev1").concretized()
c1 = spack.cmd.diff.compare_specs(specA, specB, to_string=False)
@@ -156,8 +143,8 @@ def find(function_list, name, args):
# Check ignoring changes on multiple packages
specA = spack.concretize.concretized(spack.spec.Spec("p1+usev1 ^p3+p3var"))
specA = spack.concretize.concretized(spack.spec.Spec("p1~usev1 ^p3~p3var"))
specA = spack.spec.Spec("p1+usev1 ^p3+p3var").concretized()
specA = spack.spec.Spec("p1~usev1 ^p3~p3var").concretized()
c3 = spack.cmd.diff.compare_specs(specA, specB, to_string=False)
assert find(c3["a_not_b"], "variant_value", ["p3", "p3var"])
@@ -170,8 +157,8 @@ def find(function_list, name, args):
def test_diff_cmd(install_mockery, mock_fetch, mock_archive, mock_packages):
"""Test that we can install two packages and diff them"""
specA = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
specB = spack.concretize.concretized(spack.spec.Spec("mpileaks+debug"))
specA = spack.spec.Spec("mpileaks").concretized()
specB = spack.spec.Spec("mpileaks+debug").concretized()
# Specs should be the same as themselves
c = spack.cmd.diff.compare_specs(specA, specA, to_string=True)

View File

@@ -19,7 +19,6 @@
from llnl.util.symlink import readlink
import spack.cmd.env
import spack.concretize
import spack.config
import spack.environment as ev
import spack.environment.depfile as depfile
@@ -915,7 +914,7 @@ def test_lockfile_spliced_specs(environment_from_manifest, install_mockery):
"""Test that an environment can round-trip a spliced spec."""
# Create a local install for zmpi to splice in
# Default concretization is not using zmpi
zmpi = spack.concretize.concretized(spack.spec.Spec("zmpi"))
zmpi = spack.spec.Spec("zmpi").concretized()
PackageInstaller([zmpi.package], fake=True).install()
e1 = environment_from_manifest(
@@ -1278,43 +1277,39 @@ def test_config_change_existing(mutable_mock_env_path, tmp_path, mock_packages,
with e:
# List of requirements, flip a variant
config("change", "packages:mpich:require:~debug")
test_spec = spack.concretize.concretized(spack.spec.Spec("mpich"))
test_spec = spack.spec.Spec("mpich").concretized()
assert test_spec.satisfies("@3.0.2~debug")
# List of requirements, change the version (in a different scope)
config("change", "packages:mpich:require:@3.0.3")
test_spec = spack.concretize.concretized(spack.spec.Spec("mpich"))
test_spec = spack.spec.Spec("mpich").concretized()
assert test_spec.satisfies("@3.0.3")
# "require:" as a single string, also try specifying
# a spec string that requires enclosing in quotes as
# part of the config path
config("change", 'packages:libelf:require:"@0.8.12:"')
spack.concretize.concretized(spack.spec.Spec("libelf@0.8.12"))
spack.spec.Spec("libelf@0.8.12").concretized()
# No need for assert, if there wasn't a failure, we
# changed the requirement successfully.
# Use change to add a requirement for a package that
# has no requirements defined
config("change", "packages:fftw:require:+mpi")
test_spec = spack.concretize.concretized(spack.spec.Spec("fftw"))
test_spec = spack.spec.Spec("fftw").concretized()
assert test_spec.satisfies("+mpi")
config("change", "packages:fftw:require:~mpi")
test_spec = spack.concretize.concretized(spack.spec.Spec("fftw"))
test_spec = spack.spec.Spec("fftw").concretized()
assert test_spec.satisfies("~mpi")
config("change", "packages:fftw:require:@1.0")
test_spec = spack.concretize.concretized(spack.spec.Spec("fftw"))
test_spec = spack.spec.Spec("fftw").concretized()
assert test_spec.satisfies("@1.0~mpi")
# Use "--match-spec" to change one spec in a "one_of"
# list
config("change", "packages:bowtie:require:@1.2.2", "--match-spec", "@1.2.0")
# confirm that we can concretize to either value
spack.concretize.concretized(spack.spec.Spec("bowtie@1.3.0"))
spack.concretize.concretized(spack.spec.Spec("bowtie@1.2.2"))
# confirm that we cannot concretize to the old value
with pytest.raises(spack.solver.asp.UnsatisfiableSpecError):
spack.concretize.concretized(spack.spec.Spec("bowtie@1.2.0"))
spack.spec.Spec("bowtie@1.3.0").concretize()
spack.spec.Spec("bowtie@1.2.2").concretized()
def test_config_change_new(mutable_mock_env_path, tmp_path, mock_packages, mutable_config):
@@ -1329,8 +1324,8 @@ def test_config_change_new(mutable_mock_env_path, tmp_path, mock_packages, mutab
with ev.Environment(tmp_path):
config("change", "packages:mpich:require:~debug")
with pytest.raises(spack.solver.asp.UnsatisfiableSpecError):
spack.concretize.concretized(spack.spec.Spec("mpich+debug"))
spack.concretize.concretized(spack.spec.Spec("mpich~debug"))
spack.spec.Spec("mpich+debug").concretized()
spack.spec.Spec("mpich~debug").concretized()
# Now check that we raise an error if we need to add a require: constraint
# when preexisting config manually specified it as a singular spec
@@ -1344,7 +1339,7 @@ def test_config_change_new(mutable_mock_env_path, tmp_path, mock_packages, mutab
"""
)
with ev.Environment(tmp_path):
assert spack.concretize.concretized(spack.spec.Spec("mpich")).satisfies("@3.0.3")
assert spack.spec.Spec("mpich").concretized().satisfies("@3.0.3")
with pytest.raises(spack.error.ConfigError, match="not a list"):
config("change", "packages:mpich:require:~debug")
@@ -1652,7 +1647,7 @@ def test_stage(mock_stage, mock_fetch, install_mockery):
root = str(mock_stage)
def check_stage(spec):
spec = spack.concretize.concretized(Spec(spec))
spec = Spec(spec).concretized()
for dep in spec.traverse():
stage_name = "{0}{1}-{2}-{3}".format(
stage_prefix, dep.name, dep.version, dep.dag_hash()
@@ -1755,7 +1750,7 @@ def test_indirect_build_dep(tmp_path):
with spack.repo.use_repositories(builder.root):
x_spec = Spec("x")
x_concretized = spack.concretize.concretized(x_spec)
x_concretized = x_spec.concretized()
_env_create("test", with_view=False)
e = ev.read("test")
@@ -1788,10 +1783,10 @@ def test_store_different_build_deps(tmp_path):
with spack.repo.use_repositories(builder.root):
y_spec = Spec("y ^z@3")
y_concretized = spack.concretize.concretized(y_spec)
y_concretized = y_spec.concretized()
x_spec = Spec("x ^z@2")
x_concretized = spack.concretize.concretized(x_spec)
x_concretized = x_spec.concretized()
# Even though x chose a different 'z', the y it chooses should be identical
# *aside* from the dependency on 'z'. The dag_hash() will show the difference

View File

@@ -6,7 +6,6 @@
import pytest
import spack.concretize
from spack.installer import PackageInstaller
from spack.main import SpackCommand, SpackCommandError
from spack.spec import Spec
@@ -16,9 +15,7 @@
@pytest.fixture
def python_database(mock_packages, mutable_database):
specs = [
spack.concretize.concretized(Spec(s)) for s in ["python", "py-extension1", "py-extension2"]
]
specs = [Spec(s).concretized() for s in ["python", "py-extension1", "py-extension2"]]
PackageInstaller([s.package for s in specs], explicit=True, fake=True).install()
yield
@@ -26,7 +23,7 @@ def python_database(mock_packages, mutable_database):
@pytest.mark.not_on_windows("All Fetchers Failed")
@pytest.mark.db
def test_extensions(mock_packages, python_database, capsys):
ext2 = spack.concretize.concretized(Spec("py-extension2"))
ext2 = Spec("py-extension2").concretized()
def check_output(ni):
with capsys.disabled():

View File

@@ -13,7 +13,6 @@
import spack.cmd as cmd
import spack.cmd.find
import spack.concretize
import spack.environment as ev
import spack.repo
import spack.store
@@ -203,8 +202,7 @@ def test_find_json_deps(database):
@pytest.mark.db
def test_display_json(database, capsys):
specs = [
spack.concretize.concretized(Spec(s))
for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
Spec(s).concretized() for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
]
cmd.display_specs_as_json(specs)
@@ -219,8 +217,7 @@ def test_display_json(database, capsys):
@pytest.mark.db
def test_display_json_deps(database, capsys):
specs = [
spack.concretize.concretized(Spec(s))
for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
Spec(s).concretized() for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
]
cmd.display_specs_as_json(specs, deps=True)
@@ -279,7 +276,7 @@ def test_find_format_deps(database, config):
def test_find_format_deps_paths(database, config):
output = find("-dp", "--format", "{name}-{version}", "mpileaks", "^zmpi")
spec = spack.concretize.concretized(Spec("mpileaks ^zmpi"))
spec = Spec("mpileaks ^zmpi").concretized()
prefixes = [s.prefix for s in spec.traverse()]
assert (
@@ -304,8 +301,7 @@ def test_find_very_long(database, config):
output = find("-L", "--no-groups", "mpileaks")
specs = [
spack.concretize.concretized(Spec(s))
for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
Spec(s).concretized() for s in ["mpileaks ^zmpi", "mpileaks ^mpich", "mpileaks ^mpich2"]
]
assert set(output.strip().split("\n")) == set(
@@ -466,8 +462,6 @@ def test_environment_with_version_range_in_compiler_doesnt_fail(tmp_path):
_pkga = (
"a0",
"""\
from spack.package import *
class A0(Package):
version("1.2")
version("1.1")
@@ -481,8 +475,6 @@ class A0(Package):
_pkgb = (
"b0",
"""\
from spack.package import *
class B0(Package):
version("1.2")
version("1.1")
@@ -493,8 +485,6 @@ class B0(Package):
_pkgc = (
"c0",
"""\
from spack.package import *
class C0(Package):
version("1.2")
version("1.1")
@@ -507,8 +497,6 @@ class C0(Package):
_pkgd = (
"d0",
"""\
from spack.package import *
class D0(Package):
version("1.2")
version("1.1")
@@ -522,8 +510,6 @@ class D0(Package):
_pkge = (
"e0",
"""\
from spack.package import *
class E0(Package):
tags = ["tag1", "tag2"]

View File

@@ -6,7 +6,6 @@
import pytest
import spack.concretize
import spack.deptypes as dt
import spack.environment as ev
import spack.main
@@ -27,7 +26,8 @@ def test_gc_without_build_dependency(mutable_database):
@pytest.mark.db
def test_gc_with_build_dependency(mutable_database):
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], explicit=True, fake=True).install()
assert "There are no unused specs." in gc("-yb")
@@ -37,8 +37,8 @@ def test_gc_with_build_dependency(mutable_database):
@pytest.mark.db
def test_gc_with_constraints(mutable_database):
s_cmake1 = spack.concretize.concretized(spack.spec.Spec("simple-inheritance ^cmake@3.4.3"))
s_cmake2 = spack.concretize.concretized(spack.spec.Spec("simple-inheritance ^cmake@3.23.1"))
s_cmake1 = spack.spec.Spec("simple-inheritance ^cmake@3.4.3").concretized()
s_cmake2 = spack.spec.Spec("simple-inheritance ^cmake@3.23.1").concretized()
PackageInstaller([s_cmake1.package], explicit=True, fake=True).install()
PackageInstaller([s_cmake2.package], explicit=True, fake=True).install()
@@ -53,7 +53,8 @@ def test_gc_with_constraints(mutable_database):
@pytest.mark.db
def test_gc_with_environment(mutable_database, mutable_mock_env_path):
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], explicit=True, fake=True).install()
e = ev.create("test_gc")
@@ -68,7 +69,8 @@ def test_gc_with_environment(mutable_database, mutable_mock_env_path):
@pytest.mark.db
def test_gc_with_build_dependency_in_environment(mutable_database, mutable_mock_env_path):
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], explicit=True, fake=True).install()
e = ev.create("test_gc")
@@ -119,7 +121,8 @@ def test_gc_except_any_environments(mutable_database, mutable_mock_env_path):
@pytest.mark.db
def test_gc_except_specific_environments(mutable_database, mutable_mock_env_path):
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], explicit=True, fake=True).install()
assert mutable_database.query_local("zmpi")
@@ -145,7 +148,8 @@ def test_gc_except_nonexisting_dir_env(mutable_database, mutable_mock_env_path,
@pytest.mark.db
def test_gc_except_specific_dir_env(mutable_database, mutable_mock_env_path, tmpdir):
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], explicit=True, fake=True).install()
assert mutable_database.query_local("zmpi")

View File

@@ -20,7 +20,6 @@
import spack.build_environment
import spack.cmd.common.arguments
import spack.cmd.install
import spack.concretize
import spack.config
import spack.environment as ev
import spack.error
@@ -136,7 +135,7 @@ def test_package_output(tmpdir, capsys, install_mockery, mock_fetch):
# we can't use output capture here because it interferes with Spack's
# logging. TODO: see whether we can get multiple log_outputs to work
# when nested AND in pytest
spec = spack.concretize.concretized(Spec("printing-package"))
spec = Spec("printing-package").concretized()
pkg = spec.package
PackageInstaller([pkg], explicit=True, verbose=True).install()
@@ -176,7 +175,7 @@ def test_install_output_on_python_error(mock_packages, mock_archive, mock_fetch,
def test_install_with_source(mock_packages, mock_archive, mock_fetch, install_mockery):
"""Verify that source has been copied into place."""
install("--source", "--keep-stage", "trivial-install-test-package")
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
src = os.path.join(spec.prefix.share, "trivial-install-test-package", "src")
assert filecmp.cmp(
os.path.join(mock_archive.path, "configure"), os.path.join(src, "configure")
@@ -184,7 +183,8 @@ def test_install_with_source(mock_packages, mock_archive, mock_fetch, install_mo
def test_install_env_variables(mock_packages, mock_archive, mock_fetch, install_mockery):
spec = spack.concretize.concretized(Spec("libdwarf"))
spec = Spec("libdwarf")
spec.concretize()
install("libdwarf")
assert os.path.isfile(spec.package.install_env_path)
@@ -205,7 +205,8 @@ def test_show_log_on_error(mock_packages, mock_archive, mock_fetch, install_mock
def test_install_overwrite(mock_packages, mock_archive, mock_fetch, install_mockery):
# Try to install a spec and then to reinstall it.
spec = spack.concretize.concretized(Spec("libdwarf"))
spec = Spec("libdwarf")
spec.concretize()
install("libdwarf")
@@ -238,7 +239,8 @@ def test_install_overwrite(mock_packages, mock_archive, mock_fetch, install_mock
def test_install_overwrite_not_installed(mock_packages, mock_archive, mock_fetch, install_mockery):
# Try to install a spec and then to reinstall it.
spec = spack.concretize.concretized(Spec("libdwarf"))
spec = Spec("libdwarf")
spec.concretize()
assert not os.path.exists(spec.prefix)
@@ -259,7 +261,7 @@ def test_install_commit(mock_git_version_info, install_mockery, mock_packages, m
monkeypatch.setattr(spack.package_base.PackageBase, "git", file_url, raising=False)
# Use the earliest commit in the respository
spec = spack.concretize.concretized(Spec(f"git-test-commit@{commits[-1]}"))
spec = Spec(f"git-test-commit@{commits[-1]}").concretized()
PackageInstaller([spec.package], explicit=True).install()
# Ensure first commit file contents were written
@@ -272,11 +274,13 @@ def test_install_commit(mock_git_version_info, install_mockery, mock_packages, m
def test_install_overwrite_multiple(mock_packages, mock_archive, mock_fetch, install_mockery):
# Try to install a spec and then to reinstall it.
libdwarf = spack.concretize.concretized(Spec("libdwarf"))
libdwarf = Spec("libdwarf")
libdwarf.concretize()
install("libdwarf")
cmake = spack.concretize.concretized(Spec("cmake"))
cmake = Spec("cmake")
cmake.concretize()
install("cmake")
@@ -352,7 +356,7 @@ def test_install_invalid_spec(invalid_spec):
)
def test_install_from_file(spec, concretize, error_code, tmpdir):
if concretize:
spec = spack.concretize.concretized(spec)
spec.concretize()
specfile = tmpdir.join("spec.yaml")
@@ -482,7 +486,8 @@ def test_install_mix_cli_and_files(clispecs, filespecs, tmpdir):
for spec in filespecs:
filepath = tmpdir.join(spec + ".yaml")
args = ["-f", str(filepath)] + args
s = spack.concretize.concretized(Spec(spec))
s = Spec(spec)
s.concretize()
with filepath.open("w") as f:
s.to_yaml(f)
@@ -491,7 +496,8 @@ def test_install_mix_cli_and_files(clispecs, filespecs, tmpdir):
def test_extra_files_are_archived(mock_packages, mock_archive, mock_fetch, install_mockery):
s = spack.concretize.concretized(Spec("archive-files"))
s = Spec("archive-files")
s.concretize()
install("archive-files")
@@ -610,7 +616,8 @@ def test_cdash_install_from_spec_json(
with capfd.disabled(), tmpdir.as_cwd():
spec_json_path = str(tmpdir.join("spec.json"))
pkg_spec = spack.concretize.concretized(Spec("pkg-a"))
pkg_spec = Spec("pkg-a")
pkg_spec.concretize()
with open(spec_json_path, "w") as fd:
fd.write(pkg_spec.to_json(hash=ht.dag_hash))
@@ -686,8 +693,8 @@ def test_cache_only_fails(tmpdir, mock_fetch, install_mockery, capfd):
def test_install_only_dependencies(tmpdir, mock_fetch, install_mockery):
dep = spack.concretize.concretized(Spec("dependency-install"))
root = spack.concretize.concretized(Spec("dependent-install"))
dep = Spec("dependency-install").concretized()
root = Spec("dependent-install").concretized()
install("--only", "dependencies", "dependent-install")
@@ -708,8 +715,8 @@ def test_install_only_package(tmpdir, mock_fetch, install_mockery, capfd):
def test_install_deps_then_package(tmpdir, mock_fetch, install_mockery):
dep = spack.concretize.concretized(Spec("dependency-install"))
root = spack.concretize.concretized(Spec("dependent-install"))
dep = Spec("dependency-install").concretized()
root = Spec("dependent-install").concretized()
install("--only", "dependencies", "dependent-install")
assert os.path.exists(dep.prefix)
@@ -727,8 +734,8 @@ def test_install_only_dependencies_in_env(
env("create", "test")
with ev.read("test"):
dep = spack.concretize.concretized(Spec("dependency-install"))
root = spack.concretize.concretized(Spec("dependent-install"))
dep = Spec("dependency-install").concretized()
root = Spec("dependent-install").concretized()
install("-v", "--only", "dependencies", "--add", "dependent-install")
@@ -744,8 +751,8 @@ def test_install_only_dependencies_of_all_in_env(
with ev.read("test"):
roots = [
spack.concretize.concretized(Spec("dependent-install@1.0")),
spack.concretize.concretized(Spec("dependent-install@2.0")),
Spec("dependent-install@1.0").concretized(),
Spec("dependent-install@2.0").concretized(),
]
add("dependent-install@1.0")
@@ -894,7 +901,7 @@ def test_cdash_configure_warning(tmpdir, mock_fetch, install_mockery, capfd):
# Ensure that even on non-x86_64 architectures, there are no
# dependencies installed
spec = spack.concretize.concretized(Spec("configure-warning"))
spec = Spec("configure-warning").concretized()
spec.clear_dependencies()
specfile = "./spec.json"
with open(specfile, "w") as f:
@@ -940,7 +947,7 @@ def test_install_env_with_tests_all(
):
env("create", "test")
with ev.read("test"):
test_dep = spack.concretize.concretized(Spec("test-dependency"))
test_dep = Spec("test-dependency").concretized()
add("depb")
install("--test", "all")
assert os.path.exists(test_dep.prefix)
@@ -952,7 +959,7 @@ def test_install_env_with_tests_root(
):
env("create", "test")
with ev.read("test"):
test_dep = spack.concretize.concretized(Spec("test-dependency"))
test_dep = Spec("test-dependency").concretized()
add("depb")
install("--test", "root")
assert not os.path.exists(test_dep.prefix)

View File

@@ -8,7 +8,6 @@
import pytest
import spack.concretize
import spack.spec
import spack.user_environment as uenv
from spack.main import SpackCommand
@@ -51,7 +50,7 @@ def test_load_shell(shell, set_command):
"""Test that `spack load` applies prefix inspections of its required runtime deps in
topo-order"""
install("mpileaks")
mpileaks_spec = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
mpileaks_spec = spack.spec.Spec("mpileaks").concretized()
# Ensure our reference variable is clean.
os.environ["CMAKE_PREFIX_PATH"] = "/hello" + os.pathsep + "/world"
@@ -168,7 +167,7 @@ def test_unload(
"""Tests that any variables set in the user environment are undone by the
unload command"""
install("mpileaks")
mpileaks_spec = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
mpileaks_spec = spack.spec.Spec("mpileaks").concretized()
# Set so unload has something to do
os.environ["FOOBAR"] = "mpileaks"
@@ -189,7 +188,7 @@ def test_unload_fails_no_shell(
):
"""Test that spack unload prints an error message without a shell."""
install("mpileaks")
mpileaks_spec = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
mpileaks_spec = spack.spec.Spec("mpileaks").concretized()
os.environ[uenv.spack_loaded_hashes_var] = mpileaks_spec.dag_hash()
out = unload("mpileaks", fail_on_error=False)

View File

@@ -9,7 +9,6 @@
from llnl.util.filesystem import mkdirp
import spack.concretize
import spack.environment as ev
import spack.paths
import spack.spec
@@ -27,7 +26,7 @@
@pytest.fixture
def mock_spec():
# Make it look like the source was actually expanded.
s = spack.concretize.concretized(spack.spec.Spec("externaltest"))
s = spack.spec.Spec("externaltest").concretized()
source_path = s.package.stage.source_path
mkdirp(source_path)
yield s, s.package

View File

@@ -14,7 +14,6 @@
import spack
import spack.cmd.logs
import spack.concretize
import spack.main
import spack.spec
from spack.main import SpackCommand
@@ -55,7 +54,7 @@ def disable_capture(capfd):
def test_logs_cmd_errors(install_mockery, mock_fetch, mock_archive, mock_packages):
spec = spack.concretize.concretized(spack.spec.Spec("libelf"))
spec = spack.spec.Spec("libelf").concretized()
assert not spec.installed
with pytest.raises(spack.main.SpackCommandError, match="is not installed or staged"):
@@ -84,7 +83,7 @@ def test_dump_logs(install_mockery, mock_fetch, mock_archive, mock_packages, dis
decompress them.
"""
cmdline_spec = spack.spec.Spec("libelf")
concrete_spec = spack.concretize.concretized(cmdline_spec)
concrete_spec = cmdline_spec.concretized()
# Sanity check, make sure this test is checking what we want: to
# start with

View File

@@ -8,11 +8,10 @@
import pytest
import spack.cmd.mirror
import spack.concretize
import spack.config
import spack.environment as ev
import spack.error
import spack.mirrors.utils
import spack.mirror
import spack.spec
import spack.util.url as url_util
import spack.version
@@ -62,7 +61,7 @@ def test_mirror_from_env(tmp_path, mock_packages, mock_fetch, mutable_mock_env_p
@pytest.fixture
def source_for_pkg_with_hash(mock_packages, tmpdir):
s = spack.concretize.concretized(spack.spec.Spec("trivial-pkg-with-valid-hash"))
s = spack.spec.Spec("trivial-pkg-with-valid-hash").concretized()
local_url_basename = os.path.basename(s.package.url)
local_path = os.path.join(str(tmpdir), local_url_basename)
with open(local_path, "w") as f:
@@ -74,11 +73,8 @@ def source_for_pkg_with_hash(mock_packages, tmpdir):
def test_mirror_skip_unstable(tmpdir_factory, mock_packages, config, source_for_pkg_with_hash):
mirror_dir = str(tmpdir_factory.mktemp("mirror-dir"))
specs = [
spack.concretize.concretized(spack.spec.Spec(x))
for x in ["git-test", "trivial-pkg-with-valid-hash"]
]
spack.mirrors.utils.create(mirror_dir, specs, skip_unstable_versions=True)
specs = [spack.spec.Spec(x).concretized() for x in ["git-test", "trivial-pkg-with-valid-hash"]]
spack.mirror.create(mirror_dir, specs, skip_unstable_versions=True)
assert set(os.listdir(mirror_dir)) - set(["_source-cache"]) == set(
["trivial-pkg-with-valid-hash"]
@@ -116,8 +112,7 @@ def test_exclude_specs(mock_packages, config):
mirror_specs, _ = spack.cmd.mirror._specs_and_action(args)
expected_include = set(
spack.concretize.concretized(spack.spec.Spec(x))
for x in ["mpich@3.0.3", "mpich@3.0.4", "mpich@3.0"]
spack.spec.Spec(x).concretized() for x in ["mpich@3.0.3", "mpich@3.0.4", "mpich@3.0"]
)
expected_exclude = set(spack.spec.Spec(x) for x in ["mpich@3.0.1", "mpich@3.0.2", "mpich@1.0"])
assert expected_include <= set(mirror_specs)
@@ -151,8 +146,7 @@ def test_exclude_file(mock_packages, tmpdir, config):
mirror_specs, _ = spack.cmd.mirror._specs_and_action(args)
expected_include = set(
spack.concretize.concretized(spack.spec.Spec(x))
for x in ["mpich@3.0.3", "mpich@3.0.4", "mpich@3.0"]
spack.spec.Spec(x).concretized() for x in ["mpich@3.0.3", "mpich@3.0.4", "mpich@3.0"]
)
expected_exclude = set(spack.spec.Spec(x) for x in ["mpich@3.0.1", "mpich@3.0.2", "mpich@1.0"])
assert expected_include <= set(mirror_specs)

View File

@@ -8,7 +8,6 @@
import pytest
import spack.concretize
import spack.config
import spack.main
import spack.modules
@@ -35,7 +34,7 @@ def ensure_module_files_are_there(mock_repo_path, mock_store, mock_configuration
def _module_files(module_type, *specs):
specs = [spack.concretize.concretized(spack.spec.Spec(x)) for x in specs]
specs = [spack.spec.Spec(x).concretized() for x in specs]
writer_cls = spack.modules.module_types[module_type]
return [writer_cls(spec, "default").layout.filename for spec in specs]
@@ -186,15 +185,12 @@ def test_setdefault_command(mutable_database, mutable_config):
# Install two different versions of pkg-a
other_spec, preferred = "pkg-a@1.0", "pkg-a@2.0"
specs = [
spack.concretize.concretized(spack.spec.Spec(other_spec)),
spack.concretize.concretized(spack.spec.Spec(preferred)),
]
specs = [spack.spec.Spec(other_spec).concretized(), spack.spec.Spec(preferred).concretized()]
PackageInstaller([s.package for s in specs], explicit=True, fake=True).install()
writers = {
preferred: writer_cls(specs[1], "default"),
other_spec: writer_cls(specs[0], "default"),
preferred: writer_cls(spack.spec.Spec(preferred).concretized(), "default"),
other_spec: writer_cls(spack.spec.Spec(other_spec).concretized(), "default"),
}
# Create two module files for the same software

View File

@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import spack.concretize
import spack.main
import spack.repo
import spack.spec
@@ -49,7 +48,7 @@ class tag_path:
def test_tags_installed(install_mockery, mock_fetch):
s = spack.concretize.concretized(spack.spec.Spec("mpich"))
s = spack.spec.Spec("mpich").concretized()
PackageInstaller([s.package], explicit=True, fake=True).install()
out = tags("-i")

View File

@@ -12,7 +12,6 @@
import spack.cmd.common.arguments
import spack.cmd.test
import spack.concretize
import spack.config
import spack.install_test
import spack.paths
@@ -242,7 +241,7 @@ def test_read_old_results(mock_packages, mock_test_stage):
def test_test_results_none(mock_packages, mock_test_stage):
name = "trivial"
spec = spack.concretize.concretized(spack.spec.Spec("trivial-smoke-test"))
spec = spack.spec.Spec("trivial-smoke-test").concretized()
suite = spack.install_test.TestSuite([spec], name)
suite.ensure_stage()
spack.install_test.write_test_suite_file(suite)
@@ -257,7 +256,7 @@ def test_test_results_none(mock_packages, mock_test_stage):
def test_test_results_status(mock_packages, mock_test_stage, status):
"""Confirm 'spack test results' returns expected status."""
name = "trivial"
spec = spack.concretize.concretized(spack.spec.Spec("trivial-smoke-test"))
spec = spack.spec.Spec("trivial-smoke-test").concretized()
suite = spack.install_test.TestSuite([spec], name)
suite.ensure_stage()
spack.install_test.write_test_suite_file(suite)
@@ -280,7 +279,7 @@ def test_test_results_status(mock_packages, mock_test_stage, status):
def test_report_filename_for_cdash(install_mockery, mock_fetch):
"""Test that the temporary file used to write Testing.xml for CDash is not the upload URL"""
name = "trivial"
spec = spack.concretize.concretized(spack.spec.Spec("trivial-smoke-test"))
spec = spack.spec.Spec("trivial-smoke-test").concretized()
suite = spack.install_test.TestSuite([spec], name)
suite.ensure_stage()

View File

@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import spack.concretize
import spack.environment as ev
import spack.spec
from spack.main import SpackCommand
@@ -32,9 +31,9 @@ def test_undevelop(tmpdir, mutable_config, mock_packages, mutable_mock_env_path)
env("create", "test", "./spack.yaml")
with ev.read("test"):
before = spack.concretize.concretized(spack.spec.Spec("mpich"))
before = spack.spec.Spec("mpich").concretized()
undevelop("mpich")
after = spack.concretize.concretized(spack.spec.Spec("mpich"))
after = spack.spec.Spec("mpich").concretized()
# Removing dev spec from environment changes concretization
assert before.satisfies("dev_path=*")

View File

@@ -8,7 +8,6 @@
import llnl.util.filesystem as fs
import spack.concretize
import spack.spec
import spack.store
import spack.util.spack_json as sjson
@@ -67,7 +66,7 @@ def test_single_file_verify_cmd(tmpdir):
def test_single_spec_verify_cmd(tmpdir, mock_packages, mock_archive, mock_fetch, install_mockery):
# Test the verify command interface to verify a single spec
install("libelf")
s = spack.concretize.concretized(spack.spec.Spec("libelf"))
s = spack.spec.Spec("libelf").concretized()
prefix = s.prefix
hash = s.dag_hash()

View File

@@ -10,7 +10,6 @@
from llnl.util.symlink import _windows_can_symlink
import spack.concretize
import spack.util.spack_yaml as s_yaml
from spack.installer import PackageInstaller
from spack.main import SpackCommand
@@ -192,7 +191,7 @@ def test_view_fails_with_missing_projections_file(tmpdir):
def test_view_files_not_ignored(
tmpdir, mock_packages, mock_archive, mock_fetch, install_mockery, cmd, with_projection
):
spec = spack.concretize.concretized(Spec("view-not-ignored"))
spec = Spec("view-not-ignored").concretized()
pkg = spec.package
PackageInstaller([pkg], explicit=True).install()
pkg.assert_installed(spec.prefix)

View File

@@ -210,7 +210,7 @@ def test_missing_command():
"""Ensure that we raise the expected exception if the desired command is
not present.
"""
with pytest.raises(spack.cmd.CommandNotFoundError):
with pytest.raises(spack.extensions.CommandNotFoundError):
spack.cmd.get_module("no-such-command")
@@ -220,9 +220,9 @@ def test_missing_command():
("/my/bad/extension", spack.extensions.ExtensionNamingError),
("", spack.extensions.ExtensionNamingError),
("/my/bad/spack--extra-hyphen", spack.extensions.ExtensionNamingError),
("/my/good/spack-extension", spack.cmd.CommandNotFoundError),
("/my/still/good/spack-extension/", spack.cmd.CommandNotFoundError),
("/my/spack-hyphenated-extension", spack.cmd.CommandNotFoundError),
("/my/good/spack-extension", spack.extensions.CommandNotFoundError),
("/my/still/good/spack-extension/", spack.extensions.CommandNotFoundError),
("/my/spack-hyphenated-extension", spack.extensions.CommandNotFoundError),
],
ids=["no_stem", "vacuous", "leading_hyphen", "basic_good", "trailing_slash", "hyphenated"],
)

View File

@@ -9,7 +9,6 @@
import archspec.cpu
import spack.concretize
import spack.config
import spack.paths
import spack.repo
@@ -22,7 +21,7 @@
def _concretize_with_reuse(*, root_str, reused_str):
reused_spec = spack.concretize.concretized(spack.spec.Spec(reused_str))
reused_spec = spack.spec.Spec(reused_str).concretized()
setup = spack.solver.asp.SpackSolverSetup(tests=False)
driver = spack.solver.asp.PyclingoDriver()
result, _, _ = driver.solve(setup, [spack.spec.Spec(f"{root_str}")], reuse=[reused_spec])
@@ -46,7 +45,7 @@ def enable_runtimes():
def test_correct_gcc_runtime_is_injected_as_dependency(runtime_repo):
s = spack.concretize.concretized(spack.spec.Spec("pkg-a%gcc@10.2.1 ^pkg-b%gcc@9.4.0"))
s = spack.spec.Spec("pkg-a%gcc@10.2.1 ^pkg-b%gcc@9.4.0").concretized()
a, b = s["pkg-a"], s["pkg-b"]
# Both a and b should depend on the same gcc-runtime directly
@@ -63,7 +62,7 @@ def test_external_nodes_do_not_have_runtimes(runtime_repo, mutable_config, tmp_p
packages_yaml = {"pkg-b": {"externals": [{"spec": "pkg-b@1.0", "prefix": f"{str(tmp_path)}"}]}}
spack.config.set("packages", packages_yaml)
s = spack.concretize.concretized(spack.spec.Spec("pkg-a%gcc@10.2.1"))
s = spack.spec.Spec("pkg-a%gcc@10.2.1").concretized()
a, b = s["pkg-a"], s["pkg-b"]

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,6 @@
import pytest
import spack.concretize
import spack.config
import spack.solver.asp
import spack.spec
@@ -59,7 +58,7 @@ def test_error_messages(error_messages, config_set, spec, mock_packages, mutable
spack.config.set(path, conf)
with pytest.raises(spack.solver.asp.UnsatisfiableSpecError) as e:
_ = spack.concretize.concretized(spack.spec.Spec(spec))
_ = spack.spec.Spec(spec).concretized()
for em in error_messages:
assert em in str(e.value)

View File

@@ -6,7 +6,6 @@
import pytest
import spack.concretize
import spack.config
import spack.environment as ev
import spack.paths
@@ -64,12 +63,12 @@ def test_mix_spec_and_requirements(concretize_scope, test_repo):
"""
update_concretize_scope(conf_str, "packages")
s1 = spack.concretize.concretized(Spec('y cflags="-a"'))
s1 = Spec('y cflags="-a"').concretized()
assert s1.satisfies('cflags="-a -c"')
def test_mix_spec_and_dependent(concretize_scope, test_repo):
s1 = spack.concretize.concretized(Spec('x ^y cflags="-a"'))
s1 = Spec('x ^y cflags="-a"').concretized()
assert s1["y"].satisfies('cflags="-a -d1"')
@@ -94,7 +93,7 @@ def test_mix_spec_and_compiler_cfg(concretize_scope, test_repo):
conf_str = _compiler_cfg_one_entry_with_cflags("-Wall")
update_concretize_scope(conf_str, "compilers")
s1 = spack.concretize.concretized(Spec('y %gcc@12.100.100 cflags="-O2"'))
s1 = Spec('y %gcc@12.100.100 cflags="-O2"').concretized()
assert s1.satisfies('cflags="-Wall -O2"')
@@ -149,7 +148,7 @@ def test_flag_order_and_grouping(
if cmd_flags:
spec_str += f' cflags="{cmd_flags}"'
root_spec = spack.concretize.concretized(Spec(spec_str))
root_spec = Spec(spec_str).concretized()
spec = root_spec["y"]
satisfy_flags = " ".join(x for x in [cmd_flags, req_flags, cmp_flags, expected_dflags] if x)
assert spec.satisfies(f'cflags="{satisfy_flags}"')
@@ -157,11 +156,11 @@ def test_flag_order_and_grouping(
def test_two_dependents_flag_mixing(concretize_scope, test_repo):
root_spec1 = spack.concretize.concretized(Spec("w~moveflaglater"))
root_spec1 = Spec("w~moveflaglater").concretized()
spec1 = root_spec1["y"]
assert spec1.compiler_flags["cflags"] == "-d0 -d1 -d2".split()
root_spec2 = spack.concretize.concretized(Spec("w+moveflaglater"))
root_spec2 = Spec("w+moveflaglater").concretized()
spec2 = root_spec2["y"]
assert spec2.compiler_flags["cflags"] == "-d3 -d1 -d2".split()
@@ -170,7 +169,7 @@ def test_propagate_and_compiler_cfg(concretize_scope, test_repo):
conf_str = _compiler_cfg_one_entry_with_cflags("-f2")
update_concretize_scope(conf_str, "compilers")
root_spec = spack.concretize.concretized(Spec("v %gcc@12.100.100 cflags=='-f1'"))
root_spec = Spec("v %gcc@12.100.100 cflags=='-f1'").concretized()
assert root_spec["y"].satisfies("cflags='-f1 -f2'")
@@ -179,7 +178,7 @@ def test_propagate_and_compiler_cfg(concretize_scope, test_repo):
def test_propagate_and_pkg_dep(concretize_scope, test_repo):
root_spec1 = spack.concretize.concretized(Spec("x ~activatemultiflag cflags=='-f1'"))
root_spec1 = Spec("x ~activatemultiflag cflags=='-f1'").concretized()
assert root_spec1["y"].satisfies("cflags='-f1 -d1'")
@@ -191,7 +190,7 @@ def test_propagate_and_require(concretize_scope, test_repo):
"""
update_concretize_scope(conf_str, "packages")
root_spec1 = spack.concretize.concretized(Spec("v cflags=='-f1'"))
root_spec1 = Spec("v cflags=='-f1'").concretized()
assert root_spec1["y"].satisfies("cflags='-f1 -f2'")
# Next, check that a requirement does not "undo" a request for
@@ -203,7 +202,7 @@ def test_propagate_and_require(concretize_scope, test_repo):
"""
update_concretize_scope(conf_str, "packages")
root_spec2 = spack.concretize.concretized(Spec("v cflags=='-f1'"))
root_spec2 = Spec("v cflags=='-f1'").concretized()
assert root_spec2["y"].satisfies("cflags='-f1'")
# Note: requirements cannot enforce propagation: any attempt to do
@@ -247,7 +246,7 @@ def test_diamond_dep_flag_mixing(concretize_scope, test_repo):
nodes of the diamond always appear in the same order).
`Spec.traverse` is responsible for handling both of these needs.
"""
root_spec1 = spack.concretize.concretized(Spec("t"))
root_spec1 = Spec("t").concretized()
spec1 = root_spec1["y"]
assert spec1.satisfies('cflags="-c1 -c2 -d1 -d2 -e1 -e2"')
assert spec1.compiler_flags["cflags"] == "-c1 -c2 -e1 -e2 -d1 -d2".split()

View File

@@ -8,7 +8,6 @@
import pytest
import spack.concretize
import spack.config
import spack.package_prefs
import spack.repo
@@ -48,7 +47,7 @@ def configure_permissions():
def concretize(abstract_spec):
return spack.concretize.concretized(Spec(abstract_spec))
return Spec(abstract_spec).concretized()
def update_packages(pkgname, section, value):
@@ -113,7 +112,7 @@ def test_preferred_variants_from_wildcard(self):
def test_preferred_compilers(self, compiler_str, spec_str):
"""Test preferred compilers are applied correctly"""
update_packages("all", "compiler", [compiler_str])
spec = spack.concretize.concretized(spack.spec.Spec(spec_str))
spec = spack.spec.Spec(spec_str).concretized()
assert spec.compiler == CompilerSpec(compiler_str)
def test_preferred_target(self, mutable_mock_repo):
@@ -215,13 +214,15 @@ def test_config_set_pkg_property_new(self, mock_repo_path):
def test_preferred(self):
""" "Test packages with some version marked as preferred=True"""
spec = spack.concretize.concretized(Spec("python"))
spec = Spec("python")
spec.concretize()
assert spec.version == Version("2.7.11")
# now add packages.yaml with versions other than preferred
# ensure that once config is in place, non-preferred version is used
update_packages("python", "version", ["3.5.0"])
spec = spack.concretize.concretized(Spec("python"))
spec = Spec("python")
spec.concretize()
assert spec.version == Version("3.5.0")
def test_preferred_undefined_raises(self):
@@ -229,7 +230,7 @@ def test_preferred_undefined_raises(self):
update_packages("python", "version", ["3.5.0.1"])
spec = Spec("python")
with pytest.raises(ConfigError):
spack.concretize.concretized(spec)
spec.concretize()
def test_preferred_truncated(self):
"""Versions without "=" are treated as version ranges: if there is
@@ -237,29 +238,35 @@ def test_preferred_truncated(self):
(don't define a new version).
"""
update_packages("python", "version", ["3.5"])
spec = spack.concretize.concretized(Spec("python"))
spec = Spec("python")
spec.concretize()
assert spec.satisfies("@3.5.1")
def test_develop(self):
"""Test concretization with develop-like versions"""
spec = spack.concretize.concretized(Spec("develop-test"))
spec = Spec("develop-test")
spec.concretize()
assert spec.version == Version("0.2.15")
spec = spack.concretize.concretized(Spec("develop-test2"))
spec = Spec("develop-test2")
spec.concretize()
assert spec.version == Version("0.2.15")
# now add packages.yaml with develop-like versions
# ensure that once config is in place, develop-like version is used
update_packages("develop-test", "version", ["develop"])
spec = spack.concretize.concretized(Spec("develop-test"))
spec = Spec("develop-test")
spec.concretize()
assert spec.version == Version("develop")
update_packages("develop-test2", "version", ["0.2.15.develop"])
spec = spack.concretize.concretized(Spec("develop-test2"))
spec = Spec("develop-test2")
spec.concretize()
assert spec.version == Version("0.2.15.develop")
def test_external_mpi(self):
# make sure this doesn't give us an external first.
spec = spack.concretize.concretized(Spec("mpi"))
spec = Spec("mpi")
spec.concretize()
assert not spec["mpi"].external
# load config
@@ -278,7 +285,8 @@ def test_external_mpi(self):
spack.config.set("packages", conf, scope="concretize")
# ensure that once config is in place, external is used
spec = spack.concretize.concretized(Spec("mpi"))
spec = Spec("mpi")
spec.concretize()
assert spec["mpich"].external_path == os.path.sep + os.path.join("dummy", "path")
def test_external_module(self, monkeypatch):
@@ -293,7 +301,8 @@ def mock_module(cmd, module):
monkeypatch.setattr(spack.util.module_cmd, "module", mock_module)
spec = spack.concretize.concretized(Spec("mpi"))
spec = Spec("mpi")
spec.concretize()
assert not spec["mpi"].external
# load config
@@ -312,7 +321,8 @@ def mock_module(cmd, module):
spack.config.set("packages", conf, scope="concretize")
# ensure that once config is in place, external is used
spec = spack.concretize.concretized(Spec("mpi"))
spec = Spec("mpi")
spec.concretize()
assert spec["mpich"].external_path == os.path.sep + os.path.join("dummy", "path")
def test_buildable_false(self):
@@ -458,7 +468,7 @@ def test_variant_not_flipped_to_pull_externals(self):
"""Test that a package doesn't prefer pulling in an
external to using the default value of a variant.
"""
s = spack.concretize.concretized(Spec("vdefault-or-external-root"))
s = Spec("vdefault-or-external-root").concretized()
assert "~external" in s["vdefault-or-external"]
assert "externaltool" not in s
@@ -470,7 +480,7 @@ def test_dependencies_cant_make_version_parent_score_better(self):
that makes the overall version score even or better and maybe
has a better score in some lower priority criteria.
"""
s = spack.concretize.concretized(Spec("version-test-root"))
s = Spec("version-test-root").concretized()
assert s.satisfies("^version-test-pkg@2.4.6")
assert "version-test-dependency-preferred" not in s
@@ -488,13 +498,13 @@ def test_multivalued_variants_are_lower_priority_than_providers(self):
with spack.config.override(
"packages:all", {"providers": {"somevirtual": ["some-virtual-preferred"]}}
):
s = spack.concretize.concretized(Spec("somevirtual"))
s = Spec("somevirtual").concretized()
assert s.name == "some-virtual-preferred"
@pytest.mark.regression("26721,19736")
def test_sticky_variant_accounts_for_packages_yaml(self):
with spack.config.override("packages:sticky-variant", {"variants": "+allow-gcc"}):
s = spack.concretize.concretized(Spec("sticky-variant %gcc"))
s = Spec("sticky-variant %gcc").concretized()
assert s.satisfies("%gcc") and s.satisfies("+allow-gcc")
@pytest.mark.regression("41134")
@@ -503,5 +513,5 @@ def test_default_preference_variant_different_type_does_not_error(self):
packages.yaml doesn't fail with an error.
"""
with spack.config.override("packages:all", {"variants": "+foo"}):
s = spack.concretize.concretized(Spec("pkg-a"))
s = Spec("pkg-a").concretized()
assert s.satisfies("foo=bar")

View File

@@ -7,7 +7,6 @@
import pytest
import spack.concretize
import spack.config
import spack.error
import spack.package_base
@@ -44,7 +43,7 @@ def test_one_package_multiple_reqs(concretize_scope, test_repo):
- "~shared"
"""
update_packages_config(conf_str)
y_spec = spack.concretize.concretized(Spec("y"))
y_spec = Spec("y").concretized()
assert y_spec.satisfies("@2.4~shared")
@@ -59,7 +58,7 @@ def test_requirement_isnt_optional(concretize_scope, test_repo):
"""
update_packages_config(conf_str)
with pytest.raises(UnsatisfiableSpecError):
spack.concretize.concretized(Spec("x@1.1"))
Spec("x@1.1").concretize()
def test_require_undefined_version(concretize_scope, test_repo):
@@ -76,7 +75,7 @@ def test_require_undefined_version(concretize_scope, test_repo):
"""
update_packages_config(conf_str)
with pytest.raises(spack.error.ConfigError):
spack.concretize.concretized(Spec("x"))
Spec("x").concretize()
def test_require_truncated(concretize_scope, test_repo):
@@ -91,7 +90,7 @@ def test_require_truncated(concretize_scope, test_repo):
require: "@1"
"""
update_packages_config(conf_str)
xspec = spack.concretize.concretized(Spec("x"))
xspec = Spec("x").concretized()
assert xspec.satisfies("@1.1")
@@ -161,7 +160,7 @@ def test_requirement_adds_new_version(
)
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("v"))
s1 = Spec("v").concretized()
assert s1.satisfies("@2.2")
# Make sure the git commit info is retained
assert isinstance(s1.version, spack.version.GitVersion)
@@ -182,7 +181,7 @@ def test_requirement_adds_version_satisfies(
)
# Sanity check: early version of T does not include U
s0 = spack.concretize.concretized(Spec("t@2.0"))
s0 = Spec("t@2.0").concretized()
assert not ("u" in s0)
conf_str = """\
@@ -194,7 +193,7 @@ def test_requirement_adds_version_satisfies(
)
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("t"))
s1 = Spec("t").concretized()
assert "u" in s1
assert s1.satisfies("@2.2")
@@ -220,7 +219,7 @@ def test_requirement_adds_git_hash_version(
"""
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("v"))
s1 = Spec("v").concretized()
assert isinstance(s1.version, spack.version.GitVersion)
assert s1.satisfies(f"v@{a_commit_hash}")
@@ -241,8 +240,8 @@ def test_requirement_adds_multiple_new_versions(
"""
update_packages_config(conf_str)
assert spack.concretize.concretized(Spec("v")).satisfies(f"@{commits[0]}=2.2")
assert spack.concretize.concretized(Spec("v@2.3")).satisfies(f"v@{commits[1]}=2.3")
assert Spec("v").concretized().satisfies(f"@{commits[0]}=2.2")
assert Spec("v@2.3").concretized().satisfies(f"v@{commits[1]}=2.3")
# TODO: this belongs in the concretize_preferences test module but uses
@@ -265,11 +264,11 @@ def test_preference_adds_new_version(
"""
update_packages_config(conf_str)
assert spack.concretize.concretized(Spec("v")).satisfies(f"@{commits[0]}=2.2")
assert spack.concretize.concretized(Spec("v@2.3")).satisfies(f"@{commits[1]}=2.3")
assert Spec("v").concretized().satisfies(f"@{commits[0]}=2.2")
assert Spec("v@2.3").concretized().satisfies(f"@{commits[1]}=2.3")
# When installing by hash, a lookup is triggered, so it's not mapped to =2.3.
s3 = spack.concretize.concretized(Spec(f"v@{commits[1]}"))
s3 = Spec(f"v@{commits[1]}").concretized()
assert s3.satisfies(f"v@{commits[1]}")
assert not s3.satisfies("@2.3")
@@ -289,7 +288,7 @@ def test_external_adds_new_version_that_is_preferred(concretize_scope, test_repo
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("x"))
spec = Spec("x").concretized()
assert spec["y"].satisfies("@2.7")
assert spack.version.Version("2.7") not in spec["y"].package.versions
@@ -298,7 +297,7 @@ def test_requirement_is_successfully_applied(concretize_scope, test_repo):
"""If a simple requirement can be satisfied, make sure the
concretization succeeds and the requirement spec is applied.
"""
s1 = spack.concretize.concretized(Spec("x"))
s1 = Spec("x").concretized()
# Without any requirements/preferences, the later version is preferred
assert s1.satisfies("@1.1")
@@ -308,7 +307,7 @@ def test_requirement_is_successfully_applied(concretize_scope, test_repo):
require: "@1.0"
"""
update_packages_config(conf_str)
s2 = spack.concretize.concretized(Spec("x"))
s2 = Spec("x").concretized()
# The requirement forces choosing the eariler version
assert s2.satisfies("@1.0")
@@ -325,7 +324,7 @@ def test_multiple_packages_requirements_are_respected(concretize_scope, test_rep
require: "@2.4"
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("x"))
spec = Spec("x").concretized()
assert spec["x"].satisfies("@1.0")
assert spec["y"].satisfies("@2.4")
@@ -341,7 +340,7 @@ def test_oneof(concretize_scope, test_repo):
- one_of: ["@2.4", "~shared"]
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("x"))
spec = Spec("x").concretized()
# The concretizer only has to satisfy one of @2.4/~shared, and @2.4
# comes first so it is prioritized
assert spec["y"].satisfies("@2.4+shared")
@@ -360,10 +359,10 @@ def test_one_package_multiple_oneof_groups(concretize_scope, test_repo):
"""
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("y@2.5"))
s1 = Spec("y@2.5").concretized()
assert s1.satisfies("%clang~shared")
s2 = spack.concretize.concretized(Spec("y@2.4"))
s2 = Spec("y@2.4").concretized()
assert s2.satisfies("%gcc+shared")
@@ -379,10 +378,10 @@ def test_require_cflags(concretize_scope, mock_packages):
"""
update_packages_config(conf_str)
spec_mpich2 = spack.concretize.concretized(Spec("mpich2"))
spec_mpich2 = Spec("mpich2").concretized()
assert spec_mpich2.satisfies("cflags=-g")
spec_mpi = spack.concretize.concretized(Spec("mpi"))
spec_mpi = Spec("mpi").concretized()
assert spec_mpi.satisfies("mpich cflags=-O1")
@@ -405,7 +404,7 @@ def test_requirements_for_package_that_is_not_needed(concretize_scope, test_repo
"""
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("v"))
s1 = Spec("v").concretized()
assert s1.satisfies("@2.1")
@@ -422,10 +421,10 @@ def test_oneof_ordering(concretize_scope, test_repo):
"""
update_packages_config(conf_str)
s1 = spack.concretize.concretized(Spec("y"))
s1 = Spec("y").concretized()
assert s1.satisfies("@2.4")
s2 = spack.concretize.concretized(Spec("y@2.5"))
s2 = Spec("y@2.5").concretized()
assert s2.satisfies("@2.5")
@@ -439,14 +438,14 @@ def test_reuse_oneof(concretize_scope, test_repo, tmp_path, mock_fetch):
store_dir = tmp_path / "store"
with spack.store.use_store(str(store_dir)):
s1 = spack.concretize.concretized(Spec("y@2.5~shared"))
s1 = Spec("y@2.5 ~shared").concretized()
PackageInstaller([s1.package], fake=True, explicit=True).install()
update_packages_config(conf_str)
with spack.config.override("concretizer:reuse", True):
s2 = spack.concretize.concretized(Spec("y"))
assert not s2.satisfies("@2.5~shared")
s2 = Spec("y").concretized()
assert not s2.satisfies("@2.5 ~shared")
@pytest.mark.parametrize(
@@ -474,7 +473,7 @@ def test_requirements_and_deprecated_versions(
update_packages_config(conf_str)
with spack.config.override("config:deprecated", allow_deprecated):
s1 = spack.concretize.concretized(Spec("y"))
s1 = Spec("y").concretized()
for constrain in expected:
assert s1.satisfies(constrain)
@@ -492,7 +491,7 @@ def test_default_requirements_with_all(spec_str, requirement_str, concretize_sco
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec(spec_str))
spec = Spec(spec_str).concretized()
for s in spec.traverse():
assert s.satisfies(requirement_str)
@@ -501,7 +500,7 @@ def test_default_requirements_with_all(spec_str, requirement_str, concretize_sco
"requirements,expectations",
[
(("%gcc", "%clang"), ("%gcc", "%clang")),
(("%gcc~shared", "@1.0"), ("%gcc~shared", "@1.0+shared")),
(("%gcc ~shared", "@1.0"), ("%gcc ~shared", "@1.0 +shared")),
],
)
def test_default_and_package_specific_requirements(
@@ -519,7 +518,7 @@ def test_default_and_package_specific_requirements(
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("x"))
spec = Spec("x").concretized()
assert spec.satisfies(specific_exp)
for s in spec.traverse(root=False):
assert s.satisfies(generic_exp)
@@ -534,7 +533,7 @@ def test_requirements_on_virtual(mpi_requirement, concretize_scope, mock_package
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("callpath"))
spec = Spec("callpath").concretized()
assert "mpi" in spec
assert mpi_requirement in spec
@@ -555,7 +554,7 @@ def test_requirements_on_virtual_and_on_package(
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("callpath"))
spec = Spec("callpath").concretized()
assert "mpi" in spec
assert mpi_requirement in spec
assert spec["mpi"].satisfies(specific_requirement)
@@ -569,10 +568,10 @@ def test_incompatible_virtual_requirements_raise(concretize_scope, mock_packages
"""
update_packages_config(conf_str)
spec = Spec("callpath^zmpi")
spec = Spec("callpath ^zmpi")
# TODO (multiple nodes): recover a better error message later
with pytest.raises((UnsatisfiableSpecError, InternalConcretizerError)):
spack.concretize.concretized(spec)
spec.concretize()
def test_non_existing_variants_under_all(concretize_scope, mock_packages):
@@ -584,7 +583,7 @@ def test_non_existing_variants_under_all(concretize_scope, mock_packages):
"""
update_packages_config(conf_str)
spec = spack.concretize.concretized(Spec("callpath^zmpi"))
spec = Spec("callpath ^zmpi").concretized()
assert "~foo" not in spec
@@ -659,7 +658,7 @@ def test_conditional_requirements_from_packages_yaml(
and optional when the condition is not met.
"""
update_packages_config(packages_yaml)
spec = spack.concretize.concretized(Spec(spec_str))
spec = Spec(spec_str).concretized()
for match_str, expected in expected_satisfies:
assert spec.satisfies(match_str) is expected
@@ -735,7 +734,7 @@ def test_requirements_fail_with_custom_message(
"""
update_packages_config(packages_yaml)
with pytest.raises(spack.error.SpackError, match=expected_message):
spack.concretize.concretized(Spec(spec_str))
Spec(spec_str).concretized()
def test_skip_requirement_when_default_requirement_condition_cannot_be_met(
@@ -754,9 +753,9 @@ def test_skip_requirement_when_default_requirement_condition_cannot_be_met(
when: "+shared"
"""
update_packages_config(packages_yaml)
s = spack.concretize.concretized(Spec("mpileaks"))
s = Spec("mpileaks").concretized()
assert s.satisfies("%clang+shared")
assert s.satisfies("%clang +shared")
# Sanity checks that 'callpath' doesn't have the shared variant, but that didn't
# cause failures during concretization.
assert "shared" not in s["callpath"].variants
@@ -783,12 +782,12 @@ def test_requires_directive(concretize_scope, mock_packages):
spack.config.CONFIG.clear_caches()
# This package requires either clang or gcc
s = spack.concretize.concretized(Spec("requires_clang_or_gcc"))
s = Spec("requires_clang_or_gcc").concretized()
assert s.satisfies("%gcc@12.0.0")
# This package can only be compiled with clang
with pytest.raises(spack.error.SpackError, match="can only be compiled with Clang"):
spack.concretize.concretized(Spec("requires_clang"))
Spec("requires_clang").concretized()
@pytest.mark.parametrize(
@@ -841,20 +840,20 @@ def test_default_requirements_semantic(packages_yaml, concretize_scope, mock_pac
"""
update_packages_config(packages_yaml)
# Regular zlib concretize to+shared
s = spack.concretize.concretized(Spec("zlib"))
# Regular zlib concretize to +shared
s = Spec("zlib").concretized()
assert s.satisfies("+shared")
# If we specify the variant we can concretize only the one matching the constraint
s = spack.concretize.concretized(Spec("zlib+shared"))
s = Spec("zlib +shared").concretized()
assert s.satisfies("+shared")
with pytest.raises(UnsatisfiableSpecError):
spack.concretize.concretized(Spec("zlib~shared"))
Spec("zlib ~shared").concretized()
# A spec without the shared variant still concretize
s = spack.concretize.concretized(Spec("pkg-a"))
assert not s.satisfies("pkg-a+shared")
assert not s.satisfies("pkg-a~shared")
s = Spec("pkg-a").concretized()
assert not s.satisfies("pkg-a +shared")
assert not s.satisfies("pkg-a ~shared")
@pytest.mark.parametrize(
@@ -898,7 +897,7 @@ def test_default_requirements_semantic(packages_yaml, concretize_scope, mock_pac
"""
packages:
all:
require: "libs=static+feefoo"
require: "libs=static +feefoo"
""",
"multivalue-variant",
["libs=shared"],
@@ -913,7 +912,7 @@ def test_default_requirements_semantic_with_mv_variants(
from MV variants.
"""
update_packages_config(packages_yaml)
s = spack.concretize.concretized(Spec(spec_str))
s = Spec(spec_str).concretized()
for constraint in expected:
assert s.satisfies(constraint), constraint
@@ -938,7 +937,7 @@ def test_requiring_package_on_multiple_virtuals(concretize_scope, mock_packages)
require: intel-parallel-studio
"""
)
s = spack.concretize.concretized(Spec("dla-future"))
s = Spec("dla-future").concretized()
assert s["blas"].name == "intel-parallel-studio"
assert s["lapack"].name == "intel-parallel-studio"
@@ -991,7 +990,7 @@ def test_strong_preferences_packages_yaml(
):
"""Tests that "preferred" specs are stronger than usual preferences, but can be overridden."""
update_packages_config(packages_yaml)
s = spack.concretize.concretized(Spec(spec_str))
s = Spec(spec_str).concretized()
for constraint in expected:
assert s.satisfies(constraint), constraint
@@ -1040,29 +1039,29 @@ def test_conflict_packages_yaml(packages_yaml, spec_str, concretize_scope, mock_
"""Tests conflicts that are specified from configuration files."""
update_packages_config(packages_yaml)
with pytest.raises(UnsatisfiableSpecError):
spack.concretize.concretized(Spec(spec_str))
Spec(spec_str).concretized()
@pytest.mark.parametrize(
"spec_str,expected,not_expected",
[
(
"forward-multi-value+cuda cuda_arch=10^dependency-mv~cuda",
"forward-multi-value +cuda cuda_arch=10 ^dependency-mv~cuda",
["cuda_arch=10", "^dependency-mv~cuda"],
["cuda_arch=11", "^dependency-mv cuda_arch=10", "^dependency-mv cuda_arch=11"],
),
(
"forward-multi-value+cuda cuda_arch=10^dependency-mv+cuda",
"forward-multi-value +cuda cuda_arch=10 ^dependency-mv+cuda",
["cuda_arch=10", "^dependency-mv cuda_arch=10"],
["cuda_arch=11", "^dependency-mv cuda_arch=11"],
),
(
"forward-multi-value+cuda cuda_arch=11^dependency-mv+cuda",
"forward-multi-value +cuda cuda_arch=11 ^dependency-mv+cuda",
["cuda_arch=11", "^dependency-mv cuda_arch=11"],
["cuda_arch=10", "^dependency-mv cuda_arch=10"],
),
(
"forward-multi-value+cuda cuda_arch=10,11^dependency-mv+cuda",
"forward-multi-value +cuda cuda_arch=10,11 ^dependency-mv+cuda",
["cuda_arch=10,11", "^dependency-mv cuda_arch=10,11"],
[],
),
@@ -1075,9 +1074,9 @@ def test_forward_multi_valued_variant_using_requires(
`requires` directives of the form:
for _val in ("shared", "static"):
requires(f"^some-virtual-mv libs={_val}", when=f"libs={_val}^some-virtual-mv")
requires(f"^some-virtual-mv libs={_val}", when=f"libs={_val} ^some-virtual-mv")
"""
s = spack.concretize.concretized(Spec(spec_str))
s = Spec(spec_str).concretized()
for constraint in expected:
assert s.satisfies(constraint)
@@ -1088,7 +1087,7 @@ def test_forward_multi_valued_variant_using_requires(
def test_strong_preferences_higher_priority_than_reuse(concretize_scope, mock_packages):
"""Tests that strong preferences have a higher priority than reusing specs."""
reused_spec = spack.concretize.concretized(Spec("adios2~bzip2"))
reused_spec = Spec("adios2~bzip2").concretized()
reuse_nodes = list(reused_spec.traverse())
root_specs = [Spec("ascent+adios2")]
@@ -1123,7 +1122,7 @@ def test_strong_preferences_higher_priority_than_reuse(concretize_scope, mock_pa
solver = spack.solver.asp.Solver()
setup = spack.solver.asp.SpackSolverSetup()
result, _, _ = solver.driver.solve(
setup, [Spec("ascent+adios2^adios2~bzip2")], reuse=reuse_nodes
setup, [Spec("ascent+adios2 ^adios2~bzip2")], reuse=reuse_nodes
)
ascent = result.specs[0]
assert ascent["adios2"].dag_hash() == reused_spec.dag_hash(), ascent

View File

@@ -5,7 +5,6 @@
import pytest
import spack.concretize
import spack.spec
import spack.store
@@ -15,7 +14,7 @@
def test_set_install_hash_length(hash_length, mutable_config, tmpdir):
mutable_config.set("config:install_hash_length", hash_length)
with spack.store.use_store(str(tmpdir)):
spec = spack.concretize.concretized(spack.spec.Spec("libelf"))
spec = spack.spec.Spec("libelf").concretized()
prefix = spec.prefix
hash_str = prefix.rsplit("-")[-1]
assert len(hash_str) == hash_length
@@ -25,7 +24,7 @@ def test_set_install_hash_length(hash_length, mutable_config, tmpdir):
def test_set_install_hash_length_upper_case(mutable_config, tmpdir):
mutable_config.set("config:install_hash_length", 5)
with spack.store.use_store(str(tmpdir), extra_data={"projections": {"all": "{name}-{HASH}"}}):
spec = spack.concretize.concretized(spack.spec.Spec("libelf"))
spec = spack.spec.Spec("libelf").concretized()
prefix = spec.prefix
hash_str = prefix.rsplit("-")[-1]
assert len(hash_str) == 5

View File

@@ -37,7 +37,6 @@
import spack.caches
import spack.compiler
import spack.compilers
import spack.concretize
import spack.config
import spack.directives_meta
import spack.environment as ev
@@ -856,7 +855,7 @@ def _populate(mock_db):
"""
def _install(spec):
s = spack.concretize.concretized(spack.spec.Spec(spec))
s = spack.spec.Spec(spec).concretized()
PackageInstaller([s.package], fake=True, explicit=True).install()
_install("mpileaks ^mpich")
@@ -1990,9 +1989,7 @@ def default_mock_concretization(config, mock_packages, concretized_specs_cache):
def _func(spec_str, tests=False):
key = spec_str, tests
if key not in concretized_specs_cache:
concretized_specs_cache[key] = spack.concretize.concretized(
spack.spec.Spec(spec_str), tests=tests
)
concretized_specs_cache[key] = spack.spec.Spec(spec_str).concretized(tests=tests)
return concretized_specs_cache[key].copy()
return _func

View File

@@ -9,7 +9,6 @@
from llnl.util.filesystem import mkdirp, touch, working_dir
import spack.concretize
from spack.fetch_strategy import CvsFetchStrategy
from spack.spec import Spec
from spack.stage import Stage
@@ -39,7 +38,7 @@ def test_fetch(type_of_test, mock_cvs_repository, config, mutable_mock_repo):
get_date = mock_cvs_repository.get_date
# Construct the package under test
spec = spack.concretize.concretized(Spec("cvs-test"))
spec = Spec("cvs-test").concretized()
spec.package.versions[Version("cvs")] = test.args
# Enter the stage directory and check some properties

View File

@@ -27,7 +27,6 @@
import llnl.util.lock as lk
from llnl.util.tty.colify import colify
import spack.concretize
import spack.database
import spack.deptypes as dt
import spack.package_base
@@ -79,8 +78,8 @@ def test_query_by_install_tree(
up_write_db, up_db, down_db = upstream_and_downstream_db
# Set the upstream DB to contain "pkg-c" and downstream to contain "pkg-b")
b = spack.concretize.concretized(spack.spec.Spec("pkg-b"))
c = spack.concretize.concretized(spack.spec.Spec("pkg-c"))
b = spack.spec.Spec("pkg-b").concretized()
c = spack.spec.Spec("pkg-c").concretized()
up_write_db.add(c)
up_db._read()
down_db.add(b)
@@ -97,7 +96,7 @@ def test_spec_installed_upstream(
# a known installed spec should say that it's installed
with spack.repo.use_repositories(mock_custom_repository):
spec = spack.concretize.concretized(spack.spec.Spec("pkg-c"))
spec = spack.spec.Spec("pkg-c").concretized()
assert not spec.installed
assert not spec.installed_upstream
@@ -126,7 +125,7 @@ def test_installed_upstream(upstream_and_downstream_db, tmpdir):
builder.add_package("w", dependencies=[("x", None, None), ("y", None, None)])
with spack.repo.use_repositories(builder.root):
spec = spack.concretize.concretized(spack.spec.Spec("w"))
spec = spack.spec.Spec("w").concretized()
for dep in spec.traverse(root=False):
upstream_write_db.add(dep)
upstream_db._read()
@@ -137,7 +136,7 @@ def test_installed_upstream(upstream_and_downstream_db, tmpdir):
with pytest.raises(spack.database.ForbiddenLockError):
upstream_db.get_by_hash(dep.dag_hash())
new_spec = spack.concretize.concretized(spack.spec.Spec("w"))
new_spec = spack.spec.Spec("w").concretized()
downstream_db.add(new_spec)
for dep in new_spec.traverse(root=False):
upstream, record = downstream_db.query_by_spec_hash(dep.dag_hash())
@@ -159,7 +158,7 @@ def test_removed_upstream_dep(upstream_and_downstream_db, tmpdir, capsys, config
builder.add_package("y", dependencies=[("z", None, None)])
with spack.repo.use_repositories(builder):
y = spack.concretize.concretized(spack.spec.Spec("y"))
y = spack.spec.Spec("y").concretized()
z = y["z"]
# add dependency to upstream, dependents to downstream
@@ -191,7 +190,7 @@ def test_add_to_upstream_after_downstream(upstream_and_downstream_db, tmpdir):
builder.add_package("x")
with spack.repo.use_repositories(builder.root):
spec = spack.concretize.concretized(spack.spec.Spec("x"))
spec = spack.spec.Spec("x").concretized()
downstream_db.add(spec)
upstream_write_db.add(spec)
@@ -223,7 +222,7 @@ def test_cannot_write_upstream(tmp_path, mock_packages, config):
db = spack.database.Database(str(tmp_path), is_upstream=True)
with pytest.raises(spack.database.ForbiddenLockError):
db.add(spack.concretize.concretized(spack.spec.Spec("pkg-a")))
db.add(spack.spec.Spec("pkg-a").concretized())
@pytest.mark.usefixtures("config", "temporary_store")
@@ -237,7 +236,7 @@ def test_recursive_upstream_dbs(tmpdir, gen_mock_layout):
builder.add_package("x", dependencies=[("y", None, None)])
with spack.repo.use_repositories(builder.root):
spec = spack.concretize.concretized(spack.spec.Spec("x"))
spec = spack.spec.Spec("x").concretized()
db_c = spack.database.Database(roots[2], layout=layouts[2])
db_c.add(spec["z"])
@@ -387,7 +386,7 @@ def _check_remove_and_add_package(database: spack.database.Database, spec):
def _mock_install(spec: str):
s = spack.concretize.concretized(spack.spec.Spec(spec))
s = spack.spec.Spec(spec).concretized()
PackageInstaller([s.package], fake=True, explicit=True).install()
@@ -732,7 +731,8 @@ def test_regression_issue_8036(mutable_database, usr_folder_exists):
# existing. Even when the package prefix exists, the package should
# not be considered installed until it is added to the database by
# the installer with install().
s = spack.concretize.concretized(spack.spec.Spec("externaltool@0.9"))
s = spack.spec.Spec("externaltool@0.9")
s.concretize()
assert not s.installed
# Now install the external package and check again the `installed` property
@@ -747,7 +747,8 @@ def test_old_external_entries_prefix(mutable_database):
jsonschema.validate(db_obj, schema)
s = spack.concretize.concretized(spack.spec.Spec("externaltool"))
s = spack.spec.Spec("externaltool")
s.concretize()
db_obj["database"]["installs"][s.dag_hash()]["path"] = "None"
@@ -776,7 +777,8 @@ def test_uninstall_by_spec(mutable_database):
def test_query_unused_specs(mutable_database):
# This spec installs a fake cmake as a build only dependency
s = spack.concretize.concretized(spack.spec.Spec("simple-inheritance"))
s = spack.spec.Spec("simple-inheritance")
s.concretize()
PackageInstaller([s.package], fake=True, explicit=True).install()
si = s.dag_hash()
@@ -818,7 +820,8 @@ def check_unused(roots, deptype, expected):
def test_query_spec_with_conditional_dependency(mutable_database):
# The issue is triggered by having dependencies that are
# conditional on a Boolean variant
s = spack.concretize.concretized(spack.spec.Spec("hdf5~mpi"))
s = spack.spec.Spec("hdf5~mpi")
s.concretize()
PackageInstaller([s.package], fake=True, explicit=True).install()
results = spack.store.STORE.db.query_local("hdf5 ^mpich")
@@ -858,7 +861,7 @@ def _is(self, spec):
# Pretend the spec has been failure locked
monkeypatch.setattr(spack.database.FailureTracker, "lock_taken", _is)
s = spack.concretize.concretized(spack.spec.Spec("pkg-a"))
s = spack.spec.Spec("pkg-a").concretized()
spack.store.STORE.failure_tracker.clear(s)
out = capfd.readouterr()[0]
assert "Retaining failure marking" in out
@@ -876,7 +879,7 @@ def _is(self, spec):
# Ensure raise OSError when try to remove the non-existent marking
monkeypatch.setattr(spack.database.FailureTracker, "persistent_mark", _is)
s = spack.concretize.concretized(spack.spec.Spec("pkg-a"))
s = spack.spec.Spec("pkg-a").concretized()
spack.store.STORE.failure_tracker.clear(s, force=True)
out = capfd.readouterr()[1]
assert "Removing failure marking despite lock" in out
@@ -891,7 +894,7 @@ def _raise_exc(lock):
raise lk.LockTimeoutError("write", "/mock-lock", 1.234, 10)
with tmpdir.as_cwd():
s = spack.concretize.concretized(spack.spec.Spec("pkg-a"))
s = spack.spec.Spec("pkg-a").concretized()
# Ensure attempt to acquire write lock on the mark raises the exception
monkeypatch.setattr(lk.Lock, "acquire_write", _raise_exc)
@@ -907,7 +910,7 @@ def _raise_exc(lock):
def test_prefix_failed(mutable_database, monkeypatch):
"""Add coverage to failed operation."""
s = spack.concretize.concretized(spack.spec.Spec("pkg-a"))
s = spack.spec.Spec("pkg-a").concretized()
# Confirm the spec is not already marked as failed
assert not spack.store.STORE.failure_tracker.has_failed(s)
@@ -931,7 +934,7 @@ def test_prefix_write_lock_error(mutable_database, monkeypatch):
def _raise(db, spec):
raise lk.LockError("Mock lock error")
s = spack.concretize.concretized(spack.spec.Spec("pkg-a"))
s = spack.spec.Spec("pkg-a").concretized()
# Ensure subsequent lock operations fail
monkeypatch.setattr(lk.Lock, "acquire_write", _raise)
@@ -1139,7 +1142,7 @@ def test_reindex_with_upstreams(tmp_path, monkeypatch, mock_packages, config):
# we install `mpileaks` locally with dependencies in the upstream. And we even install
# `mpileaks` with the same hash in the upstream. After reindexing, `mpileaks` should still be
# in the local db, and `callpath` should not.
mpileaks = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
mpileaks = spack.spec.Spec("mpileaks").concretized()
callpath = mpileaks.dependencies("callpath")[0]
upstream_store = spack.store.create(

View File

@@ -6,7 +6,6 @@
import pytest
import spack.concretize
import spack.directives
import spack.repo
import spack.spec
@@ -61,8 +60,8 @@ def test_constraints_from_context_are_merged(mock_packages):
@pytest.mark.regression("27754")
def test_extends_spec(config, mock_packages):
extender = spack.concretize.concretized(spack.spec.Spec("extends-spec"))
extendee = spack.concretize.concretized(spack.spec.Spec("extendee"))
extender = spack.spec.Spec("extends-spec").concretized()
extendee = spack.spec.Spec("extendee").concretized()
assert extender.dependencies
assert extender.package.extends(extendee)
@@ -149,8 +148,6 @@ def test_version_type_validation():
_pkgx = (
"x",
"""\
from spack.package import *
class X(Package):
version("1.3")
version("1.2")
@@ -169,8 +166,6 @@ class X(Package):
_pkgy = (
"y",
"""\
from spack.package import *
class Y(Package):
version("2.1")
version("2.0")
@@ -208,7 +203,7 @@ def test_repo(_create_test_repo, monkeypatch, mock_stage):
def test_redistribute_directive(test_repo, spec_str, distribute_src, distribute_bin):
spec = spack.spec.Spec(spec_str)
assert spec.package_class.redistribute_source(spec) == distribute_src
concretized_spec = spack.concretize.concretized(spec)
concretized_spec = spec.concretized()
assert concretized_spec.package.redistribute_binary == distribute_bin
@@ -224,10 +219,10 @@ class MockPackage:
disable_redistribute = {}
cls = MockPackage
spack.directives._execute_redistribute(cls, source=False, binary=None, when="@1.0")
spack.directives._execute_redistribute(cls, source=False, when="@1.0")
spec_key = spack.directives._make_when_spec("@1.0")
assert not cls.disable_redistribute[spec_key].binary
assert cls.disable_redistribute[spec_key].source
spack.directives._execute_redistribute(cls, source=None, binary=False, when="@1.0")
spack.directives._execute_redistribute(cls, binary=False, when="@1.0")
assert cls.disable_redistribute[spec_key].binary
assert cls.disable_redistribute[spec_key].source

View File

@@ -14,7 +14,6 @@
from llnl.path import path_to_os_path
import spack.concretize
import spack.hash_types
import spack.paths
import spack.repo
@@ -61,7 +60,7 @@ def test_yaml_directory_layout_parameters(tmpdir, default_mock_concretization):
assert package7 == path_package7
# Test separation of architecture or namespace
spec2 = spack.concretize.concretized(Spec("libelf"))
spec2 = Spec("libelf").concretized()
arch_scheme = (
"{architecture.platform}/{architecture.target}/{architecture.os}/{name}/{version}/{hash:7}"
@@ -99,7 +98,7 @@ def test_read_and_write_spec(temporary_store, config, mock_packages):
# If a spec fails to concretize, just skip it. If it is a
# real error, it will be caught by concretization tests.
try:
spec = spack.concretize.concretized(spack.spec.Spec(name))
spec = spack.spec.Spec(name).concretized()
except Exception:
continue
@@ -138,7 +137,7 @@ def test_read_and_write_spec(temporary_store, config, mock_packages):
assert norm.eq_dag(spec_from_file)
# TODO: revise this when build deps are in dag_hash
conc = spack.concretize.concretized(read_separately).copy(deps=stored_deptypes)
conc = read_separately.concretized().copy(deps=stored_deptypes)
assert conc == spec_from_file
assert conc.eq_dag(spec_from_file)
@@ -174,10 +173,12 @@ def test_handle_unknown_package(temporary_store, config, mock_packages, tmp_path
# Create all the packages that are not in mock.
installed_specs = {}
for pkg_name in packages:
spec = spack.spec.Spec(pkg_name)
# If a spec fails to concretize, just skip it. If it is a
# real error, it will be caught by concretization tests.
try:
spec = spack.concretize.concretized(spack.spec.Spec(pkg_name))
spec.concretize()
except Exception:
continue
@@ -209,7 +210,7 @@ def test_find(temporary_store, config, mock_packages):
if name.startswith("external"):
# External package tests cannot be installed
continue
spec = spack.concretize.concretized(spack.spec.Spec(name))
spec = spack.spec.Spec(name).concretized()
installed_specs[spec.name] = spec
layout.create_install_directory(spec)

View File

@@ -8,7 +8,6 @@
import pytest
import spack.build_environment
import spack.concretize
import spack.spec
from spack.package import build_system_flags, env_flags, inject_flags
@@ -32,10 +31,10 @@ def add_o3_to_build_system_cflags(pkg, name, flags):
class TestFlagHandlers:
def test_no_build_system_flags(self, temp_env):
# Test that both autotools and cmake work getting no build_system flags
s1 = spack.concretize.concretized(spack.spec.Spec("cmake-client"))
s1 = spack.spec.Spec("cmake-client").concretized()
spack.build_environment.setup_package(s1.package, False)
s2 = spack.concretize.concretized(spack.spec.Spec("patchelf"))
s2 = spack.spec.Spec("patchelf").concretized()
spack.build_environment.setup_package(s2.package, False)
# Use cppflags as a canary
@@ -45,28 +44,28 @@ def test_no_build_system_flags(self, temp_env):
def test_unbound_method(self, temp_env):
# Other tests test flag_handlers set as bound methods and functions.
# This tests an unbound method in python2 (no change in python3).
s = spack.concretize.concretized(spack.spec.Spec("mpileaks cppflags=-g"))
s = spack.spec.Spec("mpileaks cppflags=-g").concretized()
s.package.flag_handler = s.package.__class__.inject_flags
spack.build_environment.setup_package(s.package, False)
assert os.environ["SPACK_CPPFLAGS"] == "-g"
assert "CPPFLAGS" not in os.environ
def test_inject_flags(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("mpileaks cppflags=-g"))
s = spack.spec.Spec("mpileaks cppflags=-g").concretized()
s.package.flag_handler = inject_flags
spack.build_environment.setup_package(s.package, False)
assert os.environ["SPACK_CPPFLAGS"] == "-g"
assert "CPPFLAGS" not in os.environ
def test_env_flags(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("mpileaks cppflags=-g"))
s = spack.spec.Spec("mpileaks cppflags=-g").concretized()
s.package.flag_handler = env_flags
spack.build_environment.setup_package(s.package, False)
assert os.environ["CPPFLAGS"] == "-g"
assert "SPACK_CPPFLAGS" not in os.environ
def test_build_system_flags_cmake(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake-client cppflags=-g"))
s = spack.spec.Spec("cmake-client cppflags=-g").concretized()
s.package.flag_handler = build_system_flags
spack.build_environment.setup_package(s.package, False)
assert "SPACK_CPPFLAGS" not in os.environ
@@ -78,7 +77,7 @@ def test_build_system_flags_cmake(self, temp_env):
}
def test_build_system_flags_autotools(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("patchelf cppflags=-g"))
s = spack.spec.Spec("patchelf cppflags=-g").concretized()
s.package.flag_handler = build_system_flags
spack.build_environment.setup_package(s.package, False)
assert "SPACK_CPPFLAGS" not in os.environ
@@ -87,7 +86,7 @@ def test_build_system_flags_autotools(self, temp_env):
def test_build_system_flags_not_implemented(self, temp_env):
"""Test the command line flags method raises a NotImplementedError"""
s = spack.concretize.concretized(spack.spec.Spec("mpileaks cppflags=-g"))
s = spack.spec.Spec("mpileaks cppflags=-g").concretized()
s.package.flag_handler = build_system_flags
try:
spack.build_environment.setup_package(s.package, False)
@@ -96,7 +95,7 @@ def test_build_system_flags_not_implemented(self, temp_env):
assert True
def test_add_build_system_flags_autotools(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("patchelf cppflags=-g"))
s = spack.spec.Spec("patchelf cppflags=-g").concretized()
s.package.flag_handler = add_o3_to_build_system_cflags
spack.build_environment.setup_package(s.package, False)
assert "-g" in os.environ["SPACK_CPPFLAGS"]
@@ -104,7 +103,7 @@ def test_add_build_system_flags_autotools(self, temp_env):
assert s.package.configure_flag_args == ["CFLAGS=-O3"]
def test_add_build_system_flags_cmake(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake-client cppflags=-g"))
s = spack.spec.Spec("cmake-client cppflags=-g").concretized()
s.package.flag_handler = add_o3_to_build_system_cflags
spack.build_environment.setup_package(s.package, False)
assert "-g" in os.environ["SPACK_CPPFLAGS"]
@@ -112,7 +111,7 @@ def test_add_build_system_flags_cmake(self, temp_env):
assert s.package.cmake_flag_args == ["-DCMAKE_C_FLAGS=-O3"]
def test_ld_flags_cmake(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake-client ldflags=-mthreads"))
s = spack.spec.Spec("cmake-client ldflags=-mthreads").concretized()
s.package.flag_handler = build_system_flags
spack.build_environment.setup_package(s.package, False)
assert "SPACK_LDFLAGS" not in os.environ
@@ -124,7 +123,7 @@ def test_ld_flags_cmake(self, temp_env):
}
def test_ld_libs_cmake(self, temp_env):
s = spack.concretize.concretized(spack.spec.Spec("cmake-client ldlibs=-lfoo"))
s = spack.spec.Spec("cmake-client ldlibs=-lfoo").concretized()
s.package.flag_handler = build_system_flags
spack.build_environment.setup_package(s.package, False)
assert "SPACK_LDLIBS" not in os.environ
@@ -140,7 +139,7 @@ def test_flag_handler(self, name, flags):
flags.append("-foo")
return (flags, None, None)
s = spack.concretize.concretized(spack.spec.Spec("cmake-client"))
s = spack.spec.Spec("cmake-client").concretized()
s.package.flag_handler = test_flag_handler
spack.build_environment.setup_package(s.package, False)

View File

@@ -11,7 +11,6 @@
from llnl.util.filesystem import mkdirp, touch, working_dir
import spack.concretize
import spack.config
import spack.error
import spack.fetch_strategy
@@ -187,9 +186,8 @@ def test_adhoc_version_submodules(
monkeypatch.setitem(pkg_class.versions, Version("git"), t.args)
monkeypatch.setattr(pkg_class, "git", "file://%s" % mock_git_repository.path, raising=False)
spec = spack.concretize.concretized(
Spec("git-test@{0}".format(mock_git_repository.unversioned_commit))
)
spec = Spec("git-test@{0}".format(mock_git_repository.unversioned_commit))
spec.concretize()
spec.package.do_stage()
collected_fnames = set()
for root, dirs, files in os.walk(spec.package.stage.source_path):

View File

@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import io
import spack.concretize
import spack.graph
import spack.spec
@@ -40,7 +39,7 @@ def test_dynamic_dot_graph_mpileaks(default_mock_concretization):
def test_ascii_graph_mpileaks(config, mock_packages, monkeypatch):
monkeypatch.setattr(spack.graph.AsciiGraph, "_node_label", lambda self, node: node.name)
s = spack.concretize.concretized(spack.spec.Spec("mpileaks"))
s = spack.spec.Spec("mpileaks").concretized()
stream = io.StringIO()
graph = spack.graph.AsciiGraph()

View File

@@ -9,7 +9,6 @@
from llnl.util.filesystem import mkdirp, touch, working_dir
import spack.concretize
import spack.config
from spack.fetch_strategy import HgFetchStrategy
from spack.spec import Spec
@@ -42,7 +41,7 @@ def test_fetch(type_of_test, secure, mock_hg_repository, config, mutable_mock_re
h = mock_hg_repository.hash
# Construct the package under test
s = spack.concretize.concretized(Spec("hg-test"))
s = Spec("hg-test").concretized()
monkeypatch.setitem(s.package.versions, Version("hg"), t.args)
# Enter the stage directory and check some properties

View File

@@ -12,13 +12,11 @@
import llnl.util.filesystem as fs
import spack.build_environment
import spack.concretize
import spack.config
import spack.database
import spack.error
import spack.installer
import spack.mirrors.mirror
import spack.mirrors.utils
import spack.mirror
import spack.package_base
import spack.patch
import spack.repo
@@ -43,7 +41,7 @@ def find_nothing(*args):
def test_install_and_uninstall(install_mockery, mock_fetch, monkeypatch):
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
PackageInstaller([spec.package], explicit=True).install()
assert spec.installed
@@ -55,7 +53,7 @@ def test_install_and_uninstall(install_mockery, mock_fetch, monkeypatch):
@pytest.mark.regression("11870")
def test_uninstall_non_existing_package(install_mockery, mock_fetch, monkeypatch):
"""Ensure that we can uninstall a package that has been deleted from the repo"""
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
PackageInstaller([spec.package], explicit=True).install()
assert spec.installed
@@ -73,7 +71,8 @@ def test_uninstall_non_existing_package(install_mockery, mock_fetch, monkeypatch
def test_pkg_attributes(install_mockery, mock_fetch, monkeypatch):
# Get a basic concrete spec for the dummy package.
spec = spack.concretize.concretized(Spec("attributes-foo-app ^attributes-foo"))
spec = Spec("attributes-foo-app ^attributes-foo")
spec.concretize()
assert spec.concrete
pkg = spec.package
@@ -128,7 +127,7 @@ def remove_prefix(self):
def test_partial_install_delete_prefix_and_stage(install_mockery, mock_fetch, working_env):
s = spack.concretize.concretized(Spec("canfail"))
s = Spec("canfail").concretized()
instance_rm_prefix = s.package.remove_prefix
@@ -158,7 +157,7 @@ def test_failing_overwrite_install_should_keep_previous_installation(
the original install prefix instead of cleaning it.
"""
# Do a successful install
s = spack.concretize.concretized(Spec("canfail"))
s = Spec("canfail").concretized()
s.package.set_install_succeed()
# Do a failing overwrite install
@@ -174,11 +173,13 @@ def test_failing_overwrite_install_should_keep_previous_installation(
def test_dont_add_patches_to_installed_package(install_mockery, mock_fetch, monkeypatch):
dependency = spack.concretize.concretized(Spec("dependency-install"))
dependency = Spec("dependency-install")
dependency.concretize()
PackageInstaller([dependency.package], explicit=True).install()
dependency_hash = dependency.dag_hash()
dependent = spack.concretize.concretized(Spec("dependent-install ^/" + dependency_hash))
dependent = Spec("dependent-install ^/" + dependency_hash)
dependent.concretize()
monkeypatch.setitem(
dependency.package.patches,
@@ -190,18 +191,20 @@ def test_dont_add_patches_to_installed_package(install_mockery, mock_fetch, monk
def test_installed_dependency_request_conflicts(install_mockery, mock_fetch, mutable_mock_repo):
dependency = spack.concretize.concretized(Spec("dependency-install"))
dependency = Spec("dependency-install")
dependency.concretize()
PackageInstaller([dependency.package], explicit=True).install()
dependency_hash = dependency.dag_hash()
dependent = Spec("conflicting-dependent ^/" + dependency_hash)
with pytest.raises(spack.error.UnsatisfiableSpecError):
spack.concretize.concretized(dependent)
dependent.concretize()
def test_install_dependency_symlinks_pkg(install_mockery, mock_fetch, mutable_mock_repo):
"""Test dependency flattening/symlinks mock package."""
spec = spack.concretize.concretized(Spec("flatten-deps"))
spec = Spec("flatten-deps")
spec.concretize()
pkg = spec.package
PackageInstaller([pkg], explicit=True).install()
@@ -212,7 +215,7 @@ def test_install_dependency_symlinks_pkg(install_mockery, mock_fetch, mutable_mo
def test_install_times(install_mockery, mock_fetch, mutable_mock_repo):
"""Test install times added."""
spec = spack.concretize.concretized(Spec("dev-build-test-install-phases"))
spec = Spec("dev-build-test-install-phases").concretized()
PackageInstaller([spec.package], explicit=True).install()
# Ensure dependency directory exists after the installation.
@@ -233,7 +236,8 @@ def test_flatten_deps(install_mockery, mock_fetch, mutable_mock_repo):
"""Explicitly test the flattening code for coverage purposes."""
# Unfortunately, executing the 'flatten-deps' spec's installation does
# not affect code coverage results, so be explicit here.
spec = spack.concretize.concretized(Spec("dependent-install"))
spec = Spec("dependent-install")
spec.concretize()
pkg = spec.package
PackageInstaller([pkg], explicit=True).install()
@@ -268,7 +272,7 @@ def install_upstream(tmpdir_factory, gen_mock_layout, install_mockery):
def _install_upstream(*specs):
for spec_str in specs:
prepared_db.add(spack.concretize.concretized(Spec(spec_str)))
prepared_db.add(Spec(spec_str).concretized())
downstream_root = str(tmpdir_factory.mktemp("mock_downstream_db_root"))
return downstream_root, upstream_layout
@@ -281,7 +285,8 @@ def test_installed_upstream_external(install_upstream, mock_fetch):
"""
store_root, _ = install_upstream("externaltool")
with spack.store.use_store(store_root):
dependent = spack.concretize.concretized(Spec("externaltest"))
dependent = Spec("externaltest")
dependent.concretize()
new_dependency = dependent["externaltool"]
assert new_dependency.external
@@ -299,8 +304,8 @@ def test_installed_upstream(install_upstream, mock_fetch):
"""
store_root, upstream_layout = install_upstream("dependency-install")
with spack.store.use_store(store_root):
dependency = spack.concretize.concretized(Spec("dependency-install"))
dependent = spack.concretize.concretized(Spec("dependent-install"))
dependency = Spec("dependency-install").concretized()
dependent = Spec("dependent-install").concretized()
new_dependency = dependent["dependency-install"]
assert new_dependency.installed_upstream
@@ -314,7 +319,7 @@ def test_installed_upstream(install_upstream, mock_fetch):
@pytest.mark.disable_clean_stage_check
def test_partial_install_keep_prefix(install_mockery, mock_fetch, monkeypatch, working_env):
s = spack.concretize.concretized(Spec("canfail"))
s = Spec("canfail").concretized()
# If remove_prefix is called at any point in this test, that is an error
monkeypatch.setattr(spack.package_base.PackageBase, "remove_prefix", mock_remove_prefix)
@@ -331,7 +336,7 @@ def test_partial_install_keep_prefix(install_mockery, mock_fetch, monkeypatch, w
def test_second_install_no_overwrite_first(install_mockery, mock_fetch, monkeypatch):
s = spack.concretize.concretized(Spec("canfail"))
s = Spec("canfail").concretized()
monkeypatch.setattr(spack.package_base.PackageBase, "remove_prefix", mock_remove_prefix)
s.package.set_install_succeed()
@@ -351,8 +356,8 @@ def test_install_prefix_collision_fails(config, mock_fetch, mock_packages, tmpdi
projections = {"projections": {"all": "one-prefix-per-package-{name}"}}
with spack.store.use_store(str(tmpdir), extra_data=projections):
with spack.config.override("config:checksum", False):
pkg_a = spack.concretize.concretized(Spec("libelf@0.8.13")).package
pkg_b = spack.concretize.concretized(Spec("libelf@0.8.12")).package
pkg_a = Spec("libelf@0.8.13").concretized().package
pkg_b = Spec("libelf@0.8.12").concretized().package
PackageInstaller([pkg_a], explicit=True, fake=True).install()
with pytest.raises(InstallError, match="Install prefix collision"):
@@ -360,14 +365,14 @@ def test_install_prefix_collision_fails(config, mock_fetch, mock_packages, tmpdi
def test_store(install_mockery, mock_fetch):
spec = spack.concretize.concretized(Spec("cmake-client"))
spec = Spec("cmake-client").concretized()
pkg = spec.package
PackageInstaller([pkg], fake=True, explicit=True).install()
@pytest.mark.disable_clean_stage_check
def test_failing_build(install_mockery, mock_fetch, capfd):
spec = spack.concretize.concretized(Spec("failing-build"))
spec = Spec("failing-build").concretized()
pkg = spec.package
with pytest.raises(spack.build_environment.ChildError, match="Expected failure"):
@@ -382,7 +387,8 @@ def test_uninstall_by_spec_errors(mutable_database):
"""Test exceptional cases with the uninstall command."""
# Try to uninstall a spec that has not been installed
spec = spack.concretize.concretized(Spec("dependent-install"))
spec = Spec("dependent-install")
spec.concretize()
with pytest.raises(InstallError, match="is not installed"):
PackageBase.uninstall_by_spec(spec)
@@ -395,7 +401,7 @@ def test_uninstall_by_spec_errors(mutable_database):
@pytest.mark.disable_clean_stage_check
def test_nosource_pkg_install(install_mockery, mock_fetch, mock_packages, capfd, ensure_debug):
"""Test install phases with the nosource package."""
spec = spack.concretize.concretized(Spec("nosource"))
spec = Spec("nosource").concretized()
pkg = spec.package
# Make sure install works even though there is no associated code.
@@ -412,7 +418,7 @@ def test_nosource_bundle_pkg_install(
install_mockery, mock_fetch, mock_packages, capfd, ensure_debug
):
"""Test install phases with the nosource-bundle package."""
spec = spack.concretize.concretized(Spec("nosource-bundle"))
spec = Spec("nosource-bundle").concretized()
pkg = spec.package
# Make sure install works even though there is no associated code.
@@ -426,7 +432,7 @@ def test_nosource_bundle_pkg_install(
def test_nosource_pkg_install_post_install(install_mockery, mock_fetch, mock_packages):
"""Test install phases with the nosource package with post-install."""
spec = spack.concretize.concretized(Spec("nosource-install"))
spec = Spec("nosource-install").concretized()
pkg = spec.package
# Make sure both the install and post-install package methods work.
@@ -443,14 +449,14 @@ def test_nosource_pkg_install_post_install(install_mockery, mock_fetch, mock_pac
def test_pkg_build_paths(install_mockery):
# Get a basic concrete spec for the trivial install package.
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
assert spec.package.log_path.endswith(_spack_build_logfile)
assert spec.package.env_path.endswith(_spack_build_envfile)
def test_pkg_install_paths(install_mockery):
# Get a basic concrete spec for the trivial install package.
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
log_path = os.path.join(spec.prefix, ".spack", _spack_build_logfile + ".gz")
assert spec.package.install_log_path == log_path
@@ -487,7 +493,7 @@ def test_pkg_install_paths(install_mockery):
def test_log_install_without_build_files(install_mockery):
"""Test the installer log function when no build files are present."""
# Get a basic concrete spec for the trivial install package.
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
# Attempt installing log without the build log file
with pytest.raises(IOError, match="No such file or directory"):
@@ -509,7 +515,7 @@ def _install(src, dest):
monkeypatch.setattr(fs, "install", _install)
spec = spack.concretize.concretized(Spec("trivial-install-test-package"))
spec = Spec("trivial-install-test-package").concretized()
# Set up mock build files and try again to include archive failure
log_path = spec.package.log_path
@@ -581,7 +587,7 @@ def test_empty_install_sanity_check_prefix(
monkeypatch, install_mockery, mock_fetch, mock_packages
):
"""Test empty install triggers sanity_check_prefix."""
spec = spack.concretize.concretized(Spec("failing-empty-install"))
spec = Spec("failing-empty-install").concretized()
with pytest.raises(spack.build_environment.ChildError, match="Nothing was installed"):
PackageInstaller([spec.package], explicit=True).install()
@@ -593,7 +599,7 @@ def test_install_from_binary_with_missing_patch_succeeds(
pushing the package to a binary cache, installation from that binary cache shouldn't error out
because of the missing patch."""
# Create a spec s with non-existing patches
s = spack.concretize.concretized(Spec("trivial-install-test-package"))
s = Spec("trivial-install-test-package").concretized()
patches = ["a" * 64]
s_dict = s.to_dict()
s_dict["spec"]["nodes"][0]["patches"] = patches
@@ -609,7 +615,7 @@ def test_install_from_binary_with_missing_patch_succeeds(
temporary_store.db.add(s, explicit=True)
# Push it to a binary cache
mirror = spack.mirrors.mirror.Mirror.from_local_path(str(tmp_path / "my_build_cache"))
mirror = spack.mirror.Mirror.from_local_path(str(tmp_path / "my_build_cache"))
with binary_distribution.make_uploader(mirror=mirror) as uploader:
uploader.push_or_raise([s])
@@ -622,7 +628,7 @@ def test_install_from_binary_with_missing_patch_succeeds(
PackageInstaller([s.package], explicit=True).install()
# Binary install: succeeds, we don't need the patch.
spack.mirrors.utils.add(mirror)
spack.mirror.add(mirror)
PackageInstaller(
[s.package],
explicit=True,

Some files were not shown because too many files have changed in this diff Show More