summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-11-01 09:16:30 +0100
committerGitHub <noreply@github.com>2021-11-01 02:16:30 -0600
commitd73b1b9742a77b36f0d319e7e9cdb461d7d6bbf9 (patch)
treed8fa72b986c01298a73173523ba583e6af01ce05
parentb87678c2dd28bb79439633fe0dc5c8d8b90cfb9d (diff)
downloadspack-d73b1b9742a77b36f0d319e7e9cdb461d7d6bbf9.tar.gz
spack-d73b1b9742a77b36f0d319e7e9cdb461d7d6bbf9.tar.bz2
spack-d73b1b9742a77b36f0d319e7e9cdb461d7d6bbf9.tar.xz
spack-d73b1b9742a77b36f0d319e7e9cdb461d7d6bbf9.zip
Fix caching of spack.repo.all_package_names() (#26991)
fixes #24522
-rw-r--r--lib/spack/spack/repo.py19
-rw-r--r--lib/spack/spack/test/repo.py6
2 files changed, 16 insertions, 9 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index b78ba28eca..7dc269065f 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -473,7 +473,6 @@ class RepoPath(object):
self.repos = []
self.by_namespace = nm.NamespaceTrie()
- self._all_package_names = None
self._provider_index = None
self._patch_index = None
@@ -544,15 +543,17 @@ class RepoPath(object):
"""Get the first repo in precedence order."""
return self.repos[0] if self.repos else None
- def all_package_names(self, include_virtuals=False):
+ @llnl.util.lang.memoized
+ def _all_package_names(self, include_virtuals):
"""Return all unique package names in all repositories."""
- if self._all_package_names is None:
- all_pkgs = set()
- for repo in self.repos:
- for name in repo.all_package_names(include_virtuals):
- all_pkgs.add(name)
- self._all_package_names = sorted(all_pkgs, key=lambda n: n.lower())
- return self._all_package_names
+ all_pkgs = set()
+ for repo in self.repos:
+ for name in repo.all_package_names(include_virtuals):
+ all_pkgs.add(name)
+ return sorted(all_pkgs, key=lambda n: n.lower())
+
+ def all_package_names(self, include_virtuals=False):
+ return self._all_package_names(include_virtuals)
def packages_with_tags(self, *tags):
r = set()
diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py
index f4c83f630a..66faddb10f 100644
--- a/lib/spack/spack/test/repo.py
+++ b/lib/spack/spack/test/repo.py
@@ -80,3 +80,9 @@ def test_namespace_hasattr(attr_name, exists, mutable_mock_repo):
# of a custom __getattr__ implementation
nms = spack.repo.SpackNamespace('spack.pkg.builtin.mock')
assert hasattr(nms, attr_name) == exists
+
+
+@pytest.mark.regression('24552')
+def test_all_package_names_is_cached_correctly():
+ assert 'mpi' in spack.repo.all_package_names(include_virtuals=True)
+ assert 'mpi' not in spack.repo.all_package_names(include_virtuals=False)