diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index b5f7640baf..9b6f104fe5 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -726,14 +726,14 @@ def first_repo(self): """Get the first repo in precedence order.""" return self.repos[0] if self.repos else None + @llnl.util.lang.memoized + def _all_package_names_set(self, include_virtuals): + return {name for repo in self.repos for name in repo.all_package_names(include_virtuals)} + @llnl.util.lang.memoized def _all_package_names(self, include_virtuals): """Return all unique package names in all repositories.""" - 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()) + return sorted(self._all_package_names_set(include_virtuals), key=lambda n: n.lower()) def all_package_names(self, include_virtuals=False): return self._all_package_names(include_virtuals) @@ -794,7 +794,11 @@ def patch_index(self): @autospec def providers_for(self, vpkg_spec): - providers = self.provider_index.providers_for(vpkg_spec) + providers = [ + spec + for spec in self.provider_index.providers_for(vpkg_spec) + if spec.name in self._all_package_names_set(include_virtuals=False) + ] if not providers: raise UnknownPackageError(vpkg_spec.fullname) return providers