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
This commit is contained in:
Greg Becker 2024-10-09 11:13:56 -07:00 committed by GitHub
parent 8e4e3c9060
commit f807337273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View File

@ -1159,6 +1159,8 @@ def clear(self, re_read=False):
# 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 @@ def remove_user_spec(self, user_spec: str) -> None:
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.

View File

@ -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")