summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2024-09-27 21:59:14 +0200
committerGitHub <noreply@github.com>2024-09-27 12:59:14 -0700
commit639854ba8b132e5713930b8ea38982f9ee274134 (patch)
tree85041a2a67423ece4653ca0aad18a46c67754cd6 /lib
parentcd5c85ba130dfe0e8a9612059219d557e078fd8d (diff)
downloadspack-639854ba8b132e5713930b8ea38982f9ee274134.tar.gz
spack-639854ba8b132e5713930b8ea38982f9ee274134.tar.bz2
spack-639854ba8b132e5713930b8ea38982f9ee274134.tar.xz
spack-639854ba8b132e5713930b8ea38982f9ee274134.zip
spec: simplify string formatting (#46609)
This PR shorten the string representation for concrete specs, in order to make it more legible. Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/spec.py4
-rw-r--r--lib/spack/spack/test/bindist.py10
-rw-r--r--lib/spack/spack/test/cmd/ci.py9
-rw-r--r--lib/spack/spack/test/modules/conftest.py6
-rw-r--r--lib/spack/spack/test/modules/tcl.py2
-rw-r--r--lib/spack/spack/test/spec_semantics.py7
6 files changed, 20 insertions, 18 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 6ae8fa036d..eac51b0f46 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -4016,8 +4016,12 @@ class Spec:
return str(path_ctor(*output_path_components))
def __str__(self):
+ if self._concrete:
+ return self.format("{name}{@version}{/hash:7}")
+
if not self._dependencies:
return self.format()
+
root_str = [self.format()]
sorted_dependencies = sorted(
self.traverse(root=False), key=lambda x: (x.name, x.abstract_hash)
diff --git a/lib/spack/spack/test/bindist.py b/lib/spack/spack/test/bindist.py
index 57a810e8cd..f2be8fd004 100644
--- a/lib/spack/spack/test/bindist.py
+++ b/lib/spack/spack/test/bindist.py
@@ -676,11 +676,13 @@ def test_build_manifest_visitor(tmpdir):
assert all(os.path.islink(f) for f in visitor.symlinks)
-def test_text_relocate_if_needed(install_mockery, mock_fetch, monkeypatch, capfd):
- spec = Spec("needs-text-relocation").concretized()
- install_cmd(str(spec))
+def test_text_relocate_if_needed(install_mockery, temporary_store, mock_fetch, monkeypatch, capfd):
+ install_cmd("needs-text-relocation")
+
+ specs = temporary_store.db.query("needs-text-relocation")
+ assert len(specs) == 1
+ manifest = get_buildfile_manifest(specs[0])
- manifest = get_buildfile_manifest(spec)
assert join_path("bin", "exe") in manifest["text_to_relocate"]
assert join_path("bin", "otherexe") not in manifest["text_to_relocate"]
assert join_path("bin", "secretexe") not in manifest["text_to_relocate"]
diff --git a/lib/spack/spack/test/cmd/ci.py b/lib/spack/spack/test/cmd/ci.py
index 01e3e4e569..40a5285cd1 100644
--- a/lib/spack/spack/test/cmd/ci.py
+++ b/lib/spack/spack/test/cmd/ci.py
@@ -933,15 +933,16 @@ spack:
"""
)
env_cmd("create", "test", "./spack.yaml")
- with ev.read("test"):
- concrete_spec = Spec("patchelf").concretized()
+ with ev.read("test") as current_env:
+ current_env.concretize()
+ install_cmd("--keep-stage")
+
+ concrete_spec = list(current_env.roots())[0]
spec_json = concrete_spec.to_json(hash=ht.dag_hash)
json_path = str(tmp_path / "spec.json")
with open(json_path, "w") as ypfd:
ypfd.write(spec_json)
- install_cmd("--add", "--keep-stage", json_path)
-
for s in concrete_spec.traverse():
ci.push_to_build_cache(s, mirror_url, True)
diff --git a/lib/spack/spack/test/modules/conftest.py b/lib/spack/spack/test/modules/conftest.py
index 5a2e0ceaed..1feee7adcb 100644
--- a/lib/spack/spack/test/modules/conftest.py
+++ b/lib/spack/spack/test/modules/conftest.py
@@ -16,8 +16,10 @@ def modulefile_content(request):
"""Returns a function that generates the content of a module file as a list of lines."""
writer_cls = getattr(request.module, "writer_cls")
- def _impl(spec_str, module_set_name="default", explicit=True):
- spec = spack.spec.Spec(spec_str).concretized()
+ def _impl(spec_like, module_set_name="default", explicit=True):
+ if isinstance(spec_like, str):
+ spec_like = spack.spec.Spec(spec_like)
+ spec = spec_like.concretized()
generator = writer_cls(spec, module_set_name, explicit)
generator.write(overwrite=True)
written_module = pathlib.Path(generator.layout.filename)
diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py
index 12cc770a89..6e0fd5c1a5 100644
--- a/lib/spack/spack/test/modules/tcl.py
+++ b/lib/spack/spack/test/modules/tcl.py
@@ -388,7 +388,7 @@ class TestTcl:
spec = spack.spec.Spec("mpileaks")
spec.concretize()
- content = modulefile_content(str(spec["callpath"]))
+ content = modulefile_content(spec["callpath"])
assert len([x for x in content if "setenv FOOBAR" in x]) == 1
assert len([x for x in content if "setenv FOOBAR {callpath}" in x]) == 1
diff --git a/lib/spack/spack/test/spec_semantics.py b/lib/spack/spack/test/spec_semantics.py
index d6e7e168af..dc7f72c331 100644
--- a/lib/spack/spack/test/spec_semantics.py
+++ b/lib/spack/spack/test/spec_semantics.py
@@ -715,13 +715,6 @@ class TestSpecSemantics:
def test_spec_formatting(self, default_mock_concretization):
spec = default_mock_concretization("multivalue-variant cflags=-O2")
- # Since the default is the full spec see if the string rep of
- # spec is the same as the output of spec.format()
- # ignoring whitespace (though should we?) and ignoring dependencies
- spec_string = str(spec)
- idx = spec_string.index(" ^")
- assert spec_string[:idx] == spec.format().strip()
-
# Testing named strings ie {string} and whether we get
# the correct component
# Mixed case intentional to test both