spack remove: fix traversal when user specs intersect (#37882)

drop unnecessary double loop over the matching user specs.
This commit is contained in:
Harmen Stoppels 2023-05-24 15:23:46 +02:00 committed by Massimiliano Culpo
parent 0052f330be
commit f2d3818d5c

View File

@ -1221,28 +1221,27 @@ def remove(self, query_spec, list_name=user_speclist_name, force=False):
old_specs = set(self.user_specs) old_specs = set(self.user_specs)
new_specs = set() new_specs = set()
for spec in matches: for spec in matches:
if spec in list_to_change: if spec not in list_to_change:
try: continue
list_to_change.remove(spec) try:
self.update_stale_references(list_name) list_to_change.remove(spec)
new_specs = set(self.user_specs) self.update_stale_references(list_name)
except spack.spec_list.SpecListError: new_specs = set(self.user_specs)
# define new specs list except spack.spec_list.SpecListError:
new_specs = set(self.user_specs) # define new specs list
msg = f"Spec '{spec}' is part of a spec matrix and " new_specs = set(self.user_specs)
msg += f"cannot be removed from list '{list_to_change}'." msg = f"Spec '{spec}' is part of a spec matrix and "
if force: msg += f"cannot be removed from list '{list_to_change}'."
msg += " It will be removed from the concrete specs." if force:
# Mock new specs, so we can remove this spec from concrete spec lists msg += " It will be removed from the concrete specs."
new_specs.remove(spec) # Mock new specs, so we can remove this spec from concrete spec lists
tty.warn(msg) new_specs.remove(spec)
tty.warn(msg)
else:
if list_name == user_speclist_name:
self.manifest.remove_user_spec(str(spec))
else: else:
if list_name == user_speclist_name: self.manifest.remove_definition(str(spec), list_name=list_name)
for user_spec in matches:
self.manifest.remove_user_spec(str(user_spec))
else:
for user_spec in matches:
self.manifest.remove_definition(str(user_spec), list_name=list_name)
# If force, update stale concretized specs # If force, update stale concretized specs
for spec in old_specs - new_specs: for spec in old_specs - new_specs: