From 84bb63d79ce5b584e1320334710220c4a963b695 Mon Sep 17 00:00:00 2001
From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de>
Date: Mon, 21 Aug 2023 13:33:34 +0200
Subject: [PATCH] remove  toolchain lua; and test the change

---
 src/mpsd_software_manager/mpsd_software.py |  8 +++++++-
 tests/test_mpsd_software.py                | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py
index b724291..b26344a 100755
--- a/src/mpsd_software_manager/mpsd_software.py
+++ b/src/mpsd_software_manager/mpsd_software.py
@@ -1186,7 +1186,8 @@ def remove_spack_environment(spack_dir, environment_name, build_log_path=None):
     First activate the environment,
     then uninstall all packages exclusive to the environment,
     then deactivate the environment,
-    and finally remove the environment.
+    remove the environment,
+    and finally remove the environment lua file.
 
     Parameters
     ----------
@@ -1215,6 +1216,11 @@ def remove_spack_environment(spack_dir, environment_name, build_log_path=None):
         shell=True,
         check=True,
     )
+    # remove the environment lua file
+    lua_file = (
+        spack_dir / ".." / "lmod" / "Core" / "toolchains" / f"{environment_name}.lua"
+    )
+    run(f"rm {lua_file}", shell=True, check=True)
 
 
 def remove_spack_package(spack_dir, package, build_log_path=None):
diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py
index 31ecf26..46967af 100644
--- a/tests/test_mpsd_software.py
+++ b/tests/test_mpsd_software.py
@@ -763,6 +763,11 @@ def test_remove_package_sets(tmp_path, simple_toolchain):
         len(list((release_dir / "spack" / "var" / "spack" / "environments").iterdir()))
         == 2
     )
+    # check that the two toolchains have the "handmade" module files
+    toolchains_list = list(mod.environment_status(release_to_test, tmp_path).values())[
+        0
+    ]
+    assert set(toolchains_list) == set(["toolchain1", "toolchain2"])
 
     # remove toolchain2
     # toolchain1 contains - zlib@1.2
@@ -781,6 +786,12 @@ def test_remove_package_sets(tmp_path, simple_toolchain):
         len(list((release_dir / "spack" / "var" / "spack" / "environments").iterdir()))
         == 1
     )
+    # check that the only one toolchains has the "handmade" module files
+    toolchains_list = list(mod.environment_status(release_to_test, tmp_path).values())[
+        0
+    ]
+    assert set(toolchains_list) == set(["toolchain1"])
+
     # check that zlib@1.2 is still installed
     # spack location -i <package> exit 0 if installed and 1 if not installed
     source_spack = (
-- 
GitLab