repo: Add all_package_classes() method.
- We were able to get names and instances previously - Add a convenience function to get package classes
This commit is contained in:
parent
72bc6cdf61
commit
5b725a37bc
@ -537,6 +537,10 @@ def all_packages(self):
|
|||||||
for name in self.all_package_names():
|
for name in self.all_package_names():
|
||||||
yield self.get(name)
|
yield self.get(name)
|
||||||
|
|
||||||
|
def all_package_classes(self):
|
||||||
|
for name in self.all_package_names():
|
||||||
|
yield self.get_pkg_class(name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def provider_index(self):
|
def provider_index(self):
|
||||||
"""Merged ProviderIndex from all Repos in the RepoPath."""
|
"""Merged ProviderIndex from all Repos in the RepoPath."""
|
||||||
@ -1015,6 +1019,14 @@ def all_packages(self):
|
|||||||
for name in self.all_package_names():
|
for name in self.all_package_names():
|
||||||
yield self.get(name)
|
yield self.get(name)
|
||||||
|
|
||||||
|
def all_package_classes(self):
|
||||||
|
"""Iterator over all package *classes* in the repository.
|
||||||
|
|
||||||
|
Use this with care, because loading packages is slow.
|
||||||
|
"""
|
||||||
|
for name in self.all_package_names():
|
||||||
|
yield self.get_pkg_class(name)
|
||||||
|
|
||||||
def exists(self, pkg_name):
|
def exists(self, pkg_name):
|
||||||
"""Whether a package with the supplied name exists."""
|
"""Whether a package with the supplied name exists."""
|
||||||
return pkg_name in self._pkg_checker
|
return pkg_name in self._pkg_checker
|
||||||
|
@ -56,6 +56,20 @@ def test_packages_are_pickleable():
|
|||||||
pickle.dumps(pkg)
|
pickle.dumps(pkg)
|
||||||
|
|
||||||
|
|
||||||
|
def test_repo_getpkg_names_and_classes():
|
||||||
|
"""Ensure that all_packages/names/classes are consistent."""
|
||||||
|
names = spack.repo.path.all_package_names()
|
||||||
|
print(names)
|
||||||
|
classes = spack.repo.path.all_package_classes()
|
||||||
|
print(list(classes))
|
||||||
|
pkgs = spack.repo.path.all_packages()
|
||||||
|
print(list(pkgs))
|
||||||
|
|
||||||
|
for name, cls, pkg in zip(names, classes, pkgs):
|
||||||
|
assert cls.name == name
|
||||||
|
assert pkg.name == name
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_mock_packages():
|
def test_get_all_mock_packages():
|
||||||
"""Get the mock packages once each too."""
|
"""Get the mock packages once each too."""
|
||||||
db = spack.repo.RepoPath(spack.paths.mock_packages_path)
|
db = spack.repo.RepoPath(spack.paths.mock_packages_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user