Add an alias for SpecfileLatest

This commit is contained in:
Massimiliano Culpo 2025-02-04 07:14:11 +01:00
parent 99489c236f
commit 15f0871a6f
No known key found for this signature in database
GPG Key ID: 3E52BB992233066C
3 changed files with 13 additions and 2 deletions

View File

@ -240,8 +240,8 @@ def from_json(stream, repository):
index.providers = _transform(
providers,
lambda vpkg, plist: (
spack.spec.SpecfileV5.from_node_dict(vpkg),
set(spack.spec.SpecfileV5.from_node_dict(p) for p in plist),
spack.spec.SpecfileLatest.from_node_dict(vpkg),
set(spack.spec.SpecfileLatest.from_node_dict(p) for p in plist),
),
)
return index

View File

@ -5103,6 +5103,10 @@ def legacy_compiler(cls, node):
raise RuntimeError("The 'compiler' option is unexpected in specfiles at v5 or greater")
#: Alias to the latest version of specfiles
SpecfileLatest = SpecfileV5
class LazySpecCache(collections.defaultdict):
"""Cache for Specs that uses a spec_like as key, and computes lazily
the corresponding value ``Spec(spec_like``.

View File

@ -504,3 +504,10 @@ def test_pickle_roundtrip_for_abstract_specs(spec_str):
t = pickle.loads(pickle.dumps(s))
assert s == t
assert str(s) == str(t)
def test_specfile_alias_is_updated():
"""Tests that the SpecfileLatest alias gets updated on a Specfile version bump"""
specfile_class_name = f"SpecfileV{spack.spec.SPECFILE_FORMAT_VERSION}"
specfile_cls = getattr(spack.spec, specfile_class_name)
assert specfile_cls is spack.spec.SpecfileLatest