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.
This commit is contained in:
Peter Scheibel 2024-05-24 15:00:50 -07:00 committed by GitHub
parent 7c87253fd8
commit 72deb53832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -106,7 +106,8 @@ def clean(parser, args):
# Then do the cleaning falling through the cases # Then do the cleaning falling through the cases
if args.specs: 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: for spec in specs:
msg = "Cleaning build stage [{0}]" msg = "Cleaning build stage [{0}]"
tty.msg(msg.format(spec.short_spec)) tty.msg(msg.format(spec.short_spec))

View File

@ -11,6 +11,7 @@
import spack.caches import spack.caches
import spack.cmd.clean import spack.cmd.clean
import spack.environment as ev
import spack.main import spack.main
import spack.package_base import spack.package_base
import spack.stage 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) 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): def test_remove_python_cache(tmpdir, monkeypatch):
cache_files = ["file1.pyo", "file2.pyc"] cache_files = ["file1.pyo", "file2.pyc"]
source_file = "file1.py" source_file = "file1.py"