Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpsd-software-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MPSD Computational Science
mpsd-software-manager
Merge requests
!82
Remove cmd
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Remove cmd
continue-with-remove-cmd
into
main
Overview
21
Commits
34
Pipelines
18
Changes
2
Merged
Ashwin Kumar Karnad
requested to merge
continue-with-remove-cmd
into
main
1 year ago
Overview
4
Commits
34
Pipelines
18
Changes
7
Expand
0
0
Merge request reports
Compare
version 1
version 17
84bb63d7
1 year ago
version 16
58aaf20b
1 year ago
version 15
5488b012
1 year ago
version 14
14d157c9
1 year ago
version 13
091e3853
1 year ago
version 12
95820236
1 year ago
version 11
56343803
1 year ago
version 10
6013d566
1 year ago
version 9
019c7cf1
1 year ago
version 8
247743d1
1 year ago
version 7
62d27b56
1 year ago
version 6
dab2d516
1 year ago
version 5
f798d117
1 year ago
version 4
120c3429
1 year ago
version 3
834b21e6
1 year ago
version 2
1eb99e7b
1 year ago
version 1
cb319aa9
1 year ago
main (base)
and
version 2
latest version
23c82bca
34 commits,
1 year ago
version 17
84bb63d7
33 commits,
1 year ago
version 16
58aaf20b
32 commits,
1 year ago
version 15
5488b012
29 commits,
1 year ago
version 14
14d157c9
28 commits,
1 year ago
version 13
091e3853
27 commits,
1 year ago
version 12
95820236
26 commits,
1 year ago
version 11
56343803
22 commits,
1 year ago
version 10
6013d566
17 commits,
1 year ago
version 9
019c7cf1
17 commits,
1 year ago
version 8
247743d1
14 commits,
1 year ago
version 7
62d27b56
13 commits,
1 year ago
version 6
dab2d516
11 commits,
1 year ago
version 5
f798d117
10 commits,
1 year ago
version 4
120c3429
9 commits,
1 year ago
version 3
834b21e6
6 commits,
1 year ago
version 2
1eb99e7b
3 commits,
1 year ago
version 1
cb319aa9
3 commits,
1 year ago
Show latest version
7 files
+
588
−
186
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
src/mpsd_software_manager/mpsd_software.py
+
161
−
24
Options
@@ -5,18 +5,17 @@
import
argparse
import
datetime
import
importlib.metadata
import
logging
import
os
import
re
import
subprocess
import
sys
import
tempfile
import
time
from
functools
import
cache
from
pathlib
import
Path
from
typing
import
List
,
Tuple
,
Union
import
re
import
shutil
from
functools
import
cache
import
importlib.metadata
__version__
=
importlib
.
metadata
.
version
(
__package__
or
__name__
)
@@ -1080,39 +1079,177 @@ 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 does not 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 remove
(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
)
if
package_sets
==
"
NONE
"
:
logging
.
warning
(
"
Please specify package_sets to remove, or
'
ALL
'
to remove all
toolchain
s
"
"
Please specify package_sets to remove, or
'
ALL
'
to remove all
package_set
s
"
)
sys
.
exit
(
1
)
sys
.
exit
(
50
)
# 2nd case: remove the entire release for microarchitecture
dir_to_remove
=
root_dir
/
mpsd_release
/
get_native_microarchitecture
()
if
"
ALL
"
in
package_sets
:
# we need to remove the entire release folder
logging
.
warning
(
f
"
Removing release
{
mpsd_release
}
from
{
root_dir
}
"
"
do you want to continue? [y/n]
"
f
"
Removing release
{
mpsd_release
}
"
f
"
from
{
root_dir
}
for
{
get_native_microarchitecture
()
}
"
)
if
force_remove
or
input
().
lower
()
==
"
y
"
:
folders_to_remove
=
os
.
listdir
(
root_dir
/
mpsd_release
)
# skip logs folder
if
"
logs
"
in
folders_to_remove
:
folders_to_remove
.
remove
(
"
logs
"
)
for
folder
in
folders_to_remove
:
shutil
.
rmtree
(
root_dir
/
mpsd_release
/
folder
)
sys
.
exit
(
0
)
if
not
force_remove
:
logging
.
warning
(
"
do you want to continue? [y/n]
"
)
if
input
().
lower
()
!=
"
y
"
:
sys
.
exit
(
60
)
# Set the remove log file name from create_log_file_names
build_log_path
=
get_log_file_path
(
mpsd_release
,
"
remove
"
,
root_dir
,
"
ALL
"
)
logging
.
info
(
f
"
> Logging removal of
{
mpsd_release
}
at
{
build_log_path
}
"
)
folders_to_remove
=
os
.
listdir
(
dir_to_remove
)
for
folder
in
folders_to_remove
:
# shutil.rmtree(dir_to_remove / folder) #dosent delete file
run
(
f
"
rm -rf
{
dir_to_remove
/
folder
}
2>&1 | tee -a
{
build_log_path
}
"
,
shell
=
True
,
check
=
True
,
)
logging
.
warning
(
f
"
Removed release
{
mpsd_release
}
from
{
root_dir
}
"
)
return
# 3rd case: remove specific package_sets from release
for
package_set
in
package_sets
:
# we load the spack environment and remove the package_set
spack_env
=
""
commands_to_execute
=
[
f
"
source
{
spack_env
}
"
,
f
"
spack env remove -y
{
package_set
}
"
,
]
run
(
"
&&
"
.
join
(
commands_to_execute
),
shell
=
True
,
check
=
True
)
build_log_path
=
get_log_file_path
(
mpsd_release
,
"
remove
"
,
root_dir
,
package_set
)
logging
.
info
(
f
"
> Logging removal of
{
package_set
}
at
{
build_log_path
}
"
)
if
package_set
not
in
[
"
global_generic
"
,
"
global
"
]:
remove_spack_environment
(
dir_to_remove
/
"
spack
"
,
package_set
,
build_log_path
)
else
:
# 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
,
build_log_path
)
def
remove_spack_environment
(
spack_dir
,
environment_name
,
build_log_path
=
None
):
"""
Remove spack environment including packages exclusive to it.
First activate the environment,
then uninstall all packages exclusive to the environment,
then deactivate the environment,
remove the environment,
and finally remove the environment lua file.
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.
build_log_path : pathlib.Path, optional
A Path object representing the path to where the logs will be teed
"""
logging
.
warning
(
f
"
Removing spack environment
{
environment_name
}
"
)
spack_env
=
spack_dir
/
"
share
"
/
"
spack
"
/
"
setup-env.sh
"
commands_to_execute
=
[
f
"
export SPACK_ROOT=
{
spack_dir
}
"
,
# need to set SPACK_ROOT 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
r
'
--format
"
{name}@{version}%{compiler.name}@{compiler.version}
"
);do
'
"
spack uninstall -y $spec; done
"
,
"
spack env deactivate
"
,
f
"
spack env remove -y
{
environment_name
}
"
,
]
build_log_path
=
build_log_path
or
"
/dev/null
"
run
(
"
(
"
+
"
&&
"
.
join
(
commands_to_execute
)
+
f
"
) 2>&1 |tee -a
{
build_log_path
}
"
,
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
):
"""
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.
build_log_path : pathlib.Path, optional
A Path object representing the path to where the logs will be teed
"""
logging
.
info
(
f
"
Removing spack package
{
package
}
"
)
spack_env
=
spack_dir
/
"
share
"
/
"
spack
"
/
"
setup-env.sh
"
commands_to_execute
=
[
f
"
export SPACK_ROOT=
{
spack_dir
}
"
,
# need to set SPACK_ROOT in dash and sh
f
"
.
{
spack_env
}
"
,
f
"
spack uninstall -y
{
package
}
"
,
]
run
(
"
(
"
+
"
&&
"
.
join
(
commands_to_execute
)
+
f
"
) 2>&1 |tee -a
{
build_log_path
}
"
,
shell
=
True
,
check
=
True
,
)
def
start_new_environment
(
release
,
from_release
,
target_dir
):
@@ -1315,7 +1452,7 @@ def main():
(
"
available
"
,
"
What is available for installation?
"
),
(
"
install
"
,
"
Install a software environment
"
),
# ("reinstall", "Reinstall a package_set"),
#
("remove", "Remove a package set"),
(
"
remove
"
,
"
Remove a package set
"
),
# ("start-new", "Start a new MPSD software release version"),
(
"
status
"
,
"
Show status: what is installed?
"
),
(
"
prepare
"
,
"
Prepare installation of MPSD-release (dev only)
"
),
Loading