def do_uninstall(specs, force): """ Uninstalls all the specs in a list. Args: specs: list of specs to be uninstalled force: force uninstallation (boolean) """ packages = [] for item in specs: try: # should work if package is known to spack packages.append(item.package) except spack.repository.UnknownPackageError as e: # The package.py file has gone away -- but still # want to uninstall. spack.Package(item).do_uninstall(force=True) # Sort packages to be uninstalled by the number of installed dependents # This ensures we do things in the right order def num_installed_deps(pkg): return len(pkg.installed_dependents) packages.sort(key=num_installed_deps) for item in packages: item.do_uninstall(force=force)
def uninstall(parser, args): if not args.packages: tty.die("uninstall requires at least one package argument.") specs = spack.cmd.parse_specs(args.packages) # For each spec provided, make sure it refers to only one package. # Fail and ask user to be unambiguous if it doesn't pkgs = [] for spec in specs: matching_specs = spack.db.get_installed(spec) if not args.all and len(matching_specs) > 1: args = [ "%s matches multiple packages." % spec, "Matching packages:" ] args += [" " + str(s) for s in matching_specs] args += [ "You can either:", " a) Use spack uninstall -a to uninstall ALL matching specs, or", " b) use a more specific spec." ] tty.die(*args) if len(matching_specs) == 0: tty.die("%s does not match any installed packages." % spec) for s in matching_specs: try: # should work if package is known to spack pkgs.append(spack.db.get(s)) except spack.packages.UnknownPackageError, e: # The package.py file has gone away -- but still want to uninstall. spack.Package(s).do_uninstall(force=True)