Add subscript notation to packages (#48467)
This PR allows using the subscript notation directly on packages. The intent is to reduce the boilerplate needed to retrieve package properties from nodes other than root.
This commit is contained in:

committed by
GitHub

parent
b670205e54
commit
dd69b646ad
@@ -767,6 +767,9 @@ def __init__(self, spec):
|
||||
self.win_rpath = fsys.WindowsSimulatedRPath(self)
|
||||
super().__init__()
|
||||
|
||||
def __getitem__(self, key: str) -> "PackageBase":
|
||||
return self.spec[key].package
|
||||
|
||||
@classmethod
|
||||
def dependency_names(cls):
|
||||
return _subkeys(cls.dependencies)
|
||||
|
@@ -285,3 +285,16 @@ def compilers(compiler, arch_spec):
|
||||
error = capfd.readouterr()[1]
|
||||
assert "Skipping tests for package" in error
|
||||
assert "test requires missing compiler" in error
|
||||
|
||||
|
||||
def test_package_subscript(default_mock_concretization):
|
||||
"""Tests that we can use the subscript notation on packages, and that it returns a package"""
|
||||
root = default_mock_concretization("mpileaks")
|
||||
root_pkg = root.package
|
||||
|
||||
# Subscript of a virtual
|
||||
assert isinstance(root_pkg["mpi"], spack.package_base.PackageBase)
|
||||
|
||||
# Subscript on concrete
|
||||
for d in root.traverse():
|
||||
assert isinstance(root_pkg[d.name], spack.package_base.PackageBase)
|
||||
|
Reference in New Issue
Block a user