From f10e95db09635ea5d9366aac0fbb5c4a9c179788 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Mon, 7 Aug 2023 14:39:57 +0200 Subject: [PATCH] use . instead of source to be POSIX compliant --- src/mpsd_software_manager/mpsd_software.py | 39 ++++++++++++++++++---- tests/test_mpsd_software.py | 3 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 8ee343b..871b4aa 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -1079,17 +1079,41 @@ def install_environment( def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove=False): - """Remove release from installation.""" + """Remove release from installation. + + Handle 3 situations : + 1. remove dosent specify what to remove + -> warn and exit + 2. remove all package_sets from release + -> remove release folder except logs + 3. remove specific package_sets from release + -> remove spack environments via spack commands + + Parameters + ---------- + mpsd_release : str + A string representing the MPSD release version. + root_dir : pathlib.Path + A Path object representing the path to the directory where + the release and package_sets will be installed. + package_sets : list of str + A list of strings representing the package_sets to install + (e.g., "foss2021a-mpi", "global_generic", "ALL"). + force_remove : bool, optional + A boolean indicating whether to force remove the release. + If False, the user will be prompted to confirm the removal. + Defaults to False. + + Raises + ------ + ValueError + + """ msg = ( f"Removing release {mpsd_release}" f" with package_sets {package_sets} from {root_dir}" ) logging.warning(msg) - # Handle 3 situations : - # 1. remove dosent specify what to remove -> warn and exit - # 2. remove all package_sets from release -> remove release folder except logs - # 3. remove specific package_sets from release - # -> remove spack environments via spack commands if package_sets == "NONE": logging.warning( @@ -1133,7 +1157,8 @@ def remove_spack_environment(spack_dir, environment_name): logging.warning(f"Removing spack environment {environment_name}") spack_env = spack_dir / "share" / "spack" / "setup-env.sh" commands_to_execute = [ - f"source {spack_env}", + f"export SPACK_DIR={spack_dir}", + f". {spack_env}", f"spack env activate {environment_name}", f"for spec in $(spack -e {environment_name} find" # this line continues r' --format "{name}@{version}%{compiler.name}@{compiler.version}");do' diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 1183250..a6b281b 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -778,7 +778,8 @@ def test_remove_package_sets(tmp_path, simple_toolchain): # check that zlib@1.2 is still installed # spack location -i <package> exit 0 if installed and 1 if not installed source_spack = ( - f'source {release_dir / "spack" / "share" / "spack" / "setup-env.sh"}' + f"export SPACK_DIR={release_dir} &&" + f'. {release_dir / "spack" / "share" / "spack" / "setup-env.sh"}' ) mod.run(f"{source_spack} && spack location -i zlib", shell=True, check=True) # check that zstd@1.5 is not installed -- GitLab