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>
This commit is contained in:
parent
cd5c85ba13
commit
639854ba8b
@ -4016,8 +4016,12 @@ def format_path(
|
|||||||
return str(path_ctor(*output_path_components))
|
return str(path_ctor(*output_path_components))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if self._concrete:
|
||||||
|
return self.format("{name}{@version}{/hash:7}")
|
||||||
|
|
||||||
if not self._dependencies:
|
if not self._dependencies:
|
||||||
return self.format()
|
return self.format()
|
||||||
|
|
||||||
root_str = [self.format()]
|
root_str = [self.format()]
|
||||||
sorted_dependencies = sorted(
|
sorted_dependencies = sorted(
|
||||||
self.traverse(root=False), key=lambda x: (x.name, x.abstract_hash)
|
self.traverse(root=False), key=lambda x: (x.name, x.abstract_hash)
|
||||||
|
@ -676,11 +676,13 @@ def test_build_manifest_visitor(tmpdir):
|
|||||||
assert all(os.path.islink(f) for f in visitor.symlinks)
|
assert all(os.path.islink(f) for f in visitor.symlinks)
|
||||||
|
|
||||||
|
|
||||||
def test_text_relocate_if_needed(install_mockery, mock_fetch, monkeypatch, capfd):
|
def test_text_relocate_if_needed(install_mockery, temporary_store, mock_fetch, monkeypatch, capfd):
|
||||||
spec = Spec("needs-text-relocation").concretized()
|
install_cmd("needs-text-relocation")
|
||||||
install_cmd(str(spec))
|
|
||||||
|
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", "exe") in manifest["text_to_relocate"]
|
||||||
assert join_path("bin", "otherexe") not 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"]
|
assert join_path("bin", "secretexe") not in manifest["text_to_relocate"]
|
||||||
|
@ -933,15 +933,16 @@ def test_push_to_build_cache(
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
env_cmd("create", "test", "./spack.yaml")
|
env_cmd("create", "test", "./spack.yaml")
|
||||||
with ev.read("test"):
|
with ev.read("test") as current_env:
|
||||||
concrete_spec = Spec("patchelf").concretized()
|
current_env.concretize()
|
||||||
|
install_cmd("--keep-stage")
|
||||||
|
|
||||||
|
concrete_spec = list(current_env.roots())[0]
|
||||||
spec_json = concrete_spec.to_json(hash=ht.dag_hash)
|
spec_json = concrete_spec.to_json(hash=ht.dag_hash)
|
||||||
json_path = str(tmp_path / "spec.json")
|
json_path = str(tmp_path / "spec.json")
|
||||||
with open(json_path, "w") as ypfd:
|
with open(json_path, "w") as ypfd:
|
||||||
ypfd.write(spec_json)
|
ypfd.write(spec_json)
|
||||||
|
|
||||||
install_cmd("--add", "--keep-stage", json_path)
|
|
||||||
|
|
||||||
for s in concrete_spec.traverse():
|
for s in concrete_spec.traverse():
|
||||||
ci.push_to_build_cache(s, mirror_url, True)
|
ci.push_to_build_cache(s, mirror_url, True)
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@ def modulefile_content(request):
|
|||||||
"""Returns a function that generates the content of a module file as a list of lines."""
|
"""Returns a function that generates the content of a module file as a list of lines."""
|
||||||
writer_cls = getattr(request.module, "writer_cls")
|
writer_cls = getattr(request.module, "writer_cls")
|
||||||
|
|
||||||
def _impl(spec_str, module_set_name="default", explicit=True):
|
def _impl(spec_like, module_set_name="default", explicit=True):
|
||||||
spec = spack.spec.Spec(spec_str).concretized()
|
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 = writer_cls(spec, module_set_name, explicit)
|
||||||
generator.write(overwrite=True)
|
generator.write(overwrite=True)
|
||||||
written_module = pathlib.Path(generator.layout.filename)
|
written_module = pathlib.Path(generator.layout.filename)
|
||||||
|
@ -388,7 +388,7 @@ def test_setup_environment(self, modulefile_content, module_configuration):
|
|||||||
|
|
||||||
spec = spack.spec.Spec("mpileaks")
|
spec = spack.spec.Spec("mpileaks")
|
||||||
spec.concretize()
|
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" in x]) == 1
|
||||||
assert len([x for x in content if "setenv FOOBAR {callpath}" in x]) == 1
|
assert len([x for x in content if "setenv FOOBAR {callpath}" in x]) == 1
|
||||||
|
@ -715,13 +715,6 @@ def test_exceptional_paths_for_constructor(self):
|
|||||||
def test_spec_formatting(self, default_mock_concretization):
|
def test_spec_formatting(self, default_mock_concretization):
|
||||||
spec = default_mock_concretization("multivalue-variant cflags=-O2")
|
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
|
# Testing named strings ie {string} and whether we get
|
||||||
# the correct component
|
# the correct component
|
||||||
# Mixed case intentional to test both
|
# Mixed case intentional to test both
|
||||||
|
Loading…
Reference in New Issue
Block a user