Skip to content

Commit c6f0f20

Browse files
committed
Avoid sorting packages to uninstall them
This approach seems to uninstall specs considerably faster, in particular for large number of specs.
1 parent 8f3c5c2 commit c6f0f20

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

lib/spack/spack/cmd/uninstall.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,14 @@ def do_uninstall(env, specs, force):
213213
if env:
214214
_remove_from_env(item, env)
215215

216-
# Sort packages to be uninstalled by the number of installed dependents
217-
# This ensures we do things in the right order
218-
def num_installed_deps(pkg):
219-
dependents = spack.store.db.installed_relatives(
220-
pkg.spec, 'parents', True)
221-
return len(dependents)
222-
223-
packages.sort(key=num_installed_deps)
224-
for item in packages:
225-
item.do_uninstall(force=force)
216+
is_ready = lambda x: not spack.store.db.query_by_spec_hash(x)[1].ref_count
217+
while packages:
218+
ready = [x for x in packages if is_ready(x.spec.dag_hash())]
219+
if not ready:
220+
raise RuntimeError('cannot proceed uninstalling specs')
221+
packages = [x for x in packages if x not in ready]
222+
for item in ready:
223+
item.do_uninstall(force=force)
226224

227225
# write any changes made to the active environment
228226
if env:

0 commit comments

Comments
 (0)