summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2024-10-09 11:13:56 -0700
committerGitHub <noreply@github.com>2024-10-09 11:13:56 -0700
commitf8073372733b526c273d4a674e7e7dfaf19648c9 (patch)
tree838da9f274e82549339490f606675156915bc41d
parent8e4e3c90602e96479214d29bac1ce122e6999679 (diff)
downloadspack-f8073372733b526c273d4a674e7e7dfaf19648c9.tar.gz
spack-f8073372733b526c273d4a674e7e7dfaf19648c9.tar.bz2
spack-f8073372733b526c273d4a674e7e7dfaf19648c9.tar.xz
spack-f8073372733b526c273d4a674e7e7dfaf19648c9.zip
Environment.clear: ensure clearing is passed through to manifest (#46880)
* Environment.clear: ensure clearing is passed through to manifest * test/cmd/env: make test_remove_commmand round-trip to disk * cleanup vestigial variables
-rw-r--r--lib/spack/spack/environment/environment.py7
-rw-r--r--lib/spack/spack/test/cmd/env.py34
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py
index 28588f07b6..4f5cd14df8 100644
--- a/lib/spack/spack/environment/environment.py
+++ b/lib/spack/spack/environment/environment.py
@@ -1159,6 +1159,8 @@ class Environment:
# things that cannot be recreated from file
self.new_specs = [] # write packages for these on write()
+ self.manifest.clear()
+
@property
def active(self):
"""True if this environment is currently active."""
@@ -2789,6 +2791,11 @@ class EnvironmentManifestFile(collections.abc.Mapping):
raise SpackEnvironmentError(msg) from e
self.changed = True
+ def clear(self) -> None:
+ """Clear all user specs from the list of root specs"""
+ self.configuration["specs"] = []
+ self.changed = True
+
def override_user_spec(self, user_spec: str, idx: int) -> None:
"""Overrides the user spec at index idx with the one passed as input.
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 234533e523..1dbc808ad8 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -574,42 +574,76 @@ def test_remove_command():
with ev.read("test"):
add("mpileaks")
+
+ with ev.read("test"):
assert "mpileaks" in find()
assert "mpileaks@" not in find()
assert "mpileaks@" not in find("--show-concretized")
with ev.read("test"):
remove("mpileaks")
+
+ with ev.read("test"):
assert "mpileaks" not in find()
assert "mpileaks@" not in find()
assert "mpileaks@" not in find("--show-concretized")
with ev.read("test"):
add("mpileaks")
+
+ with ev.read("test"):
assert "mpileaks" in find()
assert "mpileaks@" not in find()
assert "mpileaks@" not in find("--show-concretized")
with ev.read("test"):
concretize()
+
+ with ev.read("test"):
assert "mpileaks" in find()
assert "mpileaks@" not in find()
assert "mpileaks@" in find("--show-concretized")
with ev.read("test"):
remove("mpileaks")
+
+ with ev.read("test"):
assert "mpileaks" not in find()
# removed but still in last concretized specs
assert "mpileaks@" in find("--show-concretized")
with ev.read("test"):
concretize()
+
+ with ev.read("test"):
assert "mpileaks" not in find()
assert "mpileaks@" not in find()
# now the lockfile is regenerated and it's gone.
assert "mpileaks@" not in find("--show-concretized")
+def test_remove_command_all():
+ # Need separate ev.read calls for each command to ensure we test round-trip to disk
+ env("create", "test")
+ test_pkgs = ("mpileaks", "zlib")
+
+ with ev.read("test"):
+ for name in test_pkgs:
+ add(name)
+
+ with ev.read("test"):
+ for name in test_pkgs:
+ assert name in find()
+ assert f"{name}@" not in find()
+
+ with ev.read("test"):
+ remove("-a")
+
+ with ev.read("test"):
+ for name in test_pkgs:
+ assert name not in find()
+
+
def test_bad_remove_included_env():
env("create", "test")
test = ev.read("test")