summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/repo.py12
-rw-r--r--lib/spack/spack/test/package_sanity.py14
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index d9dddce6b6..484034bb06 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -537,6 +537,10 @@ class RepoPath(object):
for name in self.all_package_names():
yield self.get(name)
+ def all_package_classes(self):
+ for name in self.all_package_names():
+ yield self.get_pkg_class(name)
+
@property
def provider_index(self):
"""Merged ProviderIndex from all Repos in the RepoPath."""
@@ -1015,6 +1019,14 @@ class Repo(object):
for name in self.all_package_names():
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):
"""Whether a package with the supplied name exists."""
return pkg_name in self._pkg_checker
diff --git a/lib/spack/spack/test/package_sanity.py b/lib/spack/spack/test/package_sanity.py
index 6475b3377e..3be74be7f8 100644
--- a/lib/spack/spack/test/package_sanity.py
+++ b/lib/spack/spack/test/package_sanity.py
@@ -56,6 +56,20 @@ def test_packages_are_pickleable():
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():
"""Get the mock packages once each too."""
db = spack.repo.RepoPath(spack.paths.mock_packages_path)