diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index b724291ba7db836910c678e393bd6b41ccc39e52..b26344a4b570773dd2e997dba95dd06e70ca3847 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 31ecf268feac4c39bea62b363d71a4341d9ae8ff..46967afd3c4dca32392a30845d544ff22c559b44 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 = (