summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-07-07 16:03:15 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2020-11-17 10:04:13 -0800
commit5b725a37bc08c89627fced7d478edf03bfe80c75 (patch)
tree1ce90996c5c60f70f09f22d57524e235097dfe21
parent72bc6cdf6103fedfdc47c8949bb7714d79a35d09 (diff)
downloadspack-5b725a37bc08c89627fced7d478edf03bfe80c75.tar.gz
spack-5b725a37bc08c89627fced7d478edf03bfe80c75.tar.bz2
spack-5b725a37bc08c89627fced7d478edf03bfe80c75.tar.xz
spack-5b725a37bc08c89627fced7d478edf03bfe80c75.zip
repo: Add all_package_classes() method.
- We were able to get names and instances previously - Add a convenience function to get package classes
-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)