diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2016-06-05 01:27:54 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2016-08-08 21:04:23 -0700 |
commit | 5e5024342f95fe3bea86b25ae488c8e738566a2e (patch) | |
tree | 28946fd7bad8d45da5ec7e947baf75cd3b727511 /lib | |
parent | 4de45c268417e518c7ee616d7454c1c91a5b8b35 (diff) | |
download | spack-5e5024342f95fe3bea86b25ae488c8e738566a2e.tar.gz spack-5e5024342f95fe3bea86b25ae488c8e738566a2e.tar.bz2 spack-5e5024342f95fe3bea86b25ae488c8e738566a2e.tar.xz spack-5e5024342f95fe3bea86b25ae488c8e738566a2e.zip |
Fix iterator invalidation issues.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/provider_index.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/spack/spack/provider_index.py b/lib/spack/spack/provider_index.py index 785ab98918..6cd2134e96 100644 --- a/lib/spack/spack/provider_index.py +++ b/lib/spack/spack/provider_index.py @@ -50,9 +50,10 @@ class ProviderIndex(object): matching implementation of MPI. """ def __init__(self, specs=None, **kwargs): - # TODO: come up with another name for this. This "restricts" values to - # the verbatim impu specs (i.e., it doesn't pre-apply package's constraints, and - # keeps things as broad as possible, so it's really the wrong name) + # TODO: come up with another name for this. This "restricts" + # values to the verbatim impu specs (i.e., it doesn't + # pre-apply package's constraints, and keeps things as broad + # as possible, so it's really the wrong name) if specs is None: specs = [] self.restrict = kwargs.setdefault('restrict', False) @@ -229,16 +230,24 @@ class ProviderIndex(object): def remove_provider(self, pkg_name): """Remove a provider from the ProviderIndex.""" - for pkg in self.providers: - pkg_dict = self.providers[pkg] + empty_pkg_dict = [] + for pkg, pkg_dict in self.providers.items(): + empty_pset = [] for provided, pset in pkg_dict.items(): - for provider in pset: - if provider.fullname == pkg_name: - pset.remove(provider) + same_name = set(p for p in pset if p.fullname == pkg_name) + pset.difference_update(same_name) + if not pset: - del pkg_dict[provided] + empty_pset.append(provided) + + for provided in empty_pset: + del pkg_dict[provided] + if not pkg_dict: - del self.providers[pkg] + empty_pkg_dict.append(pkg) + + for pkg in empty_pkg_dict: + del self.providers[pkg] def copy(self): |