diff options
author | Peter Scheibel <scheibel1@llnl.gov> | 2024-05-24 15:00:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 15:00:50 -0700 |
commit | 72deb53832477792b1eff8bd9b6289e84ca85ead (patch) | |
tree | ec49ed05982dd7def565ea6b914af3a0321a4966 /lib | |
parent | 7c87253fd86bdb067e5a33725d61fd8a680038e8 (diff) | |
download | spack-72deb53832477792b1eff8bd9b6289e84ca85ead.tar.gz spack-72deb53832477792b1eff8bd9b6289e84ca85ead.tar.bz2 spack-72deb53832477792b1eff8bd9b6289e84ca85ead.tar.xz spack-72deb53832477792b1eff8bd9b6289e84ca85ead.zip |
Make `spack clean` env-aware (#44227)
`spack clean <spec>` will now resolve specs based on the active environment if one is active.
If an env is active but no matching spec is found, this will fall back on fully concretizing.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/clean.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/clean.py | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/clean.py b/lib/spack/spack/cmd/clean.py index 3a9a7f32ab..9dd3efa459 100644 --- a/lib/spack/spack/cmd/clean.py +++ b/lib/spack/spack/cmd/clean.py @@ -106,7 +106,8 @@ def clean(parser, args): # Then do the cleaning falling through the cases if args.specs: - specs = spack.cmd.parse_specs(args.specs, concretize=True) + specs = spack.cmd.parse_specs(args.specs, concretize=False) + specs = list(spack.cmd.matching_spec_from_env(x) for x in specs) for spec in specs: msg = "Cleaning build stage [{0}]" tty.msg(msg.format(spec.short_spec)) diff --git a/lib/spack/spack/test/cmd/clean.py b/lib/spack/spack/test/cmd/clean.py index 43441c487c..4c35868333 100644 --- a/lib/spack/spack/test/cmd/clean.py +++ b/lib/spack/spack/test/cmd/clean.py @@ -11,6 +11,7 @@ import llnl.util.filesystem as fs import spack.caches import spack.cmd.clean +import spack.environment as ev import spack.main import spack.package_base import spack.stage @@ -68,6 +69,20 @@ def test_function_calls(command_line, effects, mock_calls_for_clean): assert mock_calls_for_clean[name] == (1 if name in effects else 0) +def test_env_aware_clean(mock_stage, install_mockery, mutable_mock_env_path, monkeypatch): + e = ev.create("test", with_view=False) + e.add("mpileaks") + e.concretize() + + def fail(*args, **kwargs): + raise Exception("This should not have been called") + + monkeypatch.setattr(spack.spec.Spec, "concretize", fail) + + with e: + clean("mpileaks") + + def test_remove_python_cache(tmpdir, monkeypatch): cache_files = ["file1.pyo", "file2.pyc"] source_file = "file1.py" |