Skip to content
Snippets Groups Projects

Remove cmd

Merged Ashwin Kumar Karnad requested to merge continue-with-remove-cmd into main
3 unresolved threads
Files
2
@@ -1137,19 +1137,48 @@ def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove
# 3rd case: remove specific package_sets from release
for package_set in package_sets:
# we load the spack environment and remove the package_set
if package_set not in ["global_packages", "global"]:
if package_set not in ["global_generic", "global"]:
remove_spack_environment(dir_to_remove / "spack", package_set)
else:
# TODO remove global packages by calling remove_spack_package
pass
# list all specs from the global_packages.list
spe_folder = root_dir / mpsd_release / "spack-environments"
package_list_file = (
spe_folder / "toolchains" / package_set / "global_packages.list"
)
with open(package_list_file, "r") as f:
package_dump = f.read()
# remove all content from # to the end of the line
package_dump = re.sub(r"#.*\n", "\n", package_dump)
# replace \\n with "" to remove line breaks
package_list = package_dump.replace("\\\n", "").split("\n")
# remove all empty lines
package_list = [line for line in package_list if line != ""]
# remove all packages in package_list
for package in package_list:
logging.info(f"Removing package {package} from installation")
remove_spack_package(dir_to_remove / "spack", package)
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
@@ -1162,11 +1191,23 @@ def remove_spack_environment(spack_dir, environment_name):
def remove_spack_package(spack_dir, package):
"""Remove spack package."""
"""Remove spack package.
Used to remove global packages.
Parameters
----------
spack_dir : pathlib.Path
A Path object representing the path to the spack directory.
package : str
A string representing the name of the spack package to remove.
"""
logging.info(f"Removing spack package {package}")
spack_env = spack_dir / "share" / "spack" / "setup-env.sh"
commands_to_execute = [
f"source {spack_env}",
f"export SPACK_DIR={spack_dir}", # need to set SPACK_DIR in dash and sh
f". {spack_env}",
f"spack uninstall -y {package}",
]
run(" && ".join(commands_to_execute), shell=True, check=True)
Loading