From ee8d857866332adc8ba3ec934e479bd2986abfbd Mon Sep 17 00:00:00 2001
From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de>
Date: Mon, 7 Aug 2023 14:50:11 +0200
Subject: [PATCH] add comments and docs to remove_spack_environment

---
 src/mpsd_software_manager/mpsd_software.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py
index 871b4aa..0d09055 100755
--- a/src/mpsd_software_manager/mpsd_software.py
+++ b/src/mpsd_software_manager/mpsd_software.py
@@ -1153,11 +1153,23 @@ def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove
 
 
 def remove_spack_environment(spack_dir, environment_name):
-    """Remove spack environment."""
+    """Remove spack environment including packages exclusive to it.
+
+    First activate the environment,
+    then uninstall all packages exclusive to the environment,
+    then deactivate the environment,
+    and finally remove the environment.
+    Parameters
+    ----------
+    spack_dir : pathlib.Path
+        A Path object representing the path to the spack directory.
+    environment_name : str
+        A string representing the name of the spack environment to remove.
+    """
     logging.warning(f"Removing spack environment {environment_name}")
     spack_env = spack_dir / "share" / "spack" / "setup-env.sh"
     commands_to_execute = [
-        f"export SPACK_DIR={spack_dir}",
+        f"export SPACK_DIR={spack_dir}",  # need to set SPACK_DIR in dash and sh
         f". {spack_env}",
         f"spack env activate {environment_name}",
         f"for spec in $(spack -e {environment_name} find"  # this line continues
-- 
GitLab