gc
: restrict to specific specs (#46790)
`spack gc` has so far been a global or environment-specific thing. This adds the ability to restrict garbage collection to specific specs, e.g. if you *just* want to get rid of all your unused python installations, you could write: ```console spack gc python ``` - [x] add `constraint` arg to `spack gc` - [x] add a simple test Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
This commit is contained in:
@@ -41,7 +41,7 @@ def setup_parser(subparser):
|
||||
help="do not remove installed build-only dependencies of roots\n"
|
||||
"(default is to keep only link & run dependencies)",
|
||||
)
|
||||
spack.cmd.common.arguments.add_common_arguments(subparser, ["yes_to_all"])
|
||||
spack.cmd.common.arguments.add_common_arguments(subparser, ["yes_to_all", "constraint"])
|
||||
|
||||
|
||||
def roots_from_environments(args, active_env):
|
||||
@@ -97,6 +97,12 @@ def gc(parser, args):
|
||||
root_hashes = None
|
||||
|
||||
specs = spack.store.STORE.db.unused_specs(root_hashes=root_hashes, deptype=deptype)
|
||||
|
||||
# limit search to constraint specs if provided
|
||||
if args.constraint:
|
||||
hashes = set(spec.dag_hash() for spec in args.specs())
|
||||
specs = [spec for spec in specs if spec.dag_hash() in hashes]
|
||||
|
||||
if not specs:
|
||||
tty.msg("There are no unused specs. Spack's store is clean.")
|
||||
return
|
||||
|
@@ -35,6 +35,22 @@ def test_gc_with_build_dependency(mutable_database):
|
||||
assert "There are no unused specs." in gc("-y")
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
def test_gc_with_constraints(mutable_database):
|
||||
s_cmake1 = spack.spec.Spec("simple-inheritance ^cmake@3.4.3").concretized()
|
||||
s_cmake2 = spack.spec.Spec("simple-inheritance ^cmake@3.23.1").concretized()
|
||||
PackageInstaller([s_cmake1.package], explicit=True, fake=True).install()
|
||||
PackageInstaller([s_cmake2.package], explicit=True, fake=True).install()
|
||||
|
||||
assert "There are no unused specs." in gc("python")
|
||||
|
||||
assert "Successfully uninstalled cmake@3.4.3" in gc("-y", "cmake@3.4.3")
|
||||
assert "There are no unused specs." in gc("-y", "cmake@3.4.3")
|
||||
|
||||
assert "Successfully uninstalled cmake" in gc("-y", "cmake@3.23.1")
|
||||
assert "There are no unused specs." in gc("-y", "cmake")
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
def test_gc_with_environment(mutable_database, mutable_mock_env_path):
|
||||
s = spack.spec.Spec("simple-inheritance")
|
||||
|
Reference in New Issue
Block a user