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
Commits
a8e16cc9
Commit
a8e16cc9
authored
1 year ago
by
Hans Fangohr
Browse files
Options
Downloads
Plain Diff
Merge branch 'try-init-command' into 'main'
Create init command See merge request
!83
parents
3c00266b
2543a48f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!83
Create init command
Pipeline
#374299
passed
1 year ago
Stage: test
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/mpsd_software_manager/mpsd_software.py
+58
-13
58 additions, 13 deletions
src/mpsd_software_manager/mpsd_software.py
tests/test_mpsd_software.py
+19
-0
19 additions, 0 deletions
tests/test_mpsd_software.py
with
78 additions
and
13 deletions
.gitignore
+
1
−
0
View file @
a8e16cc9
...
@@ -6,3 +6,4 @@ dev-23a/
...
@@ -6,3 +6,4 @@ dev-23a/
dist/
dist/
build/
build/
*.egg-info/
*.egg-info/
.mpsd-software-root
This diff is collapsed.
Click to expand it.
src/mpsd_software_manager/mpsd_software.py
+
58
−
13
View file @
a8e16cc9
...
@@ -82,6 +82,7 @@ config_vars = {
...
@@ -82,6 +82,7 @@ config_vars = {
"
metadata_tag_open
"
:
"
!<meta>
"
,
"
metadata_tag_open
"
:
"
!<meta>
"
,
"
metadata_tag_close
"
:
"
</meta>!
"
,
"
metadata_tag_close
"
:
"
</meta>!
"
,
"
spack_environments_repo
"
:
"
https://gitlab.gwdg.de/mpsd-cs/spack-environments.git
"
,
"
spack_environments_repo
"
:
"
https://gitlab.gwdg.de/mpsd-cs/spack-environments.git
"
,
"
init_file
"
:
"
.mpsd-software-root
"
,
}
}
...
@@ -1081,6 +1082,39 @@ def environment_status(mpsd_release: str, root_dir: Union[str, Path]) -> dict:
...
@@ -1081,6 +1082,39 @@ def environment_status(mpsd_release: str, root_dir: Union[str, Path]) -> dict:
return
toolchain_map
return
toolchain_map
def
initialize_environment
(
root_dir
:
Path
)
->
None
:
"""
Initialize the software environment.
This creates a hidden file ``.mpsd-software-root`` to tag the location for
as the root of the installation. All compiled files, logs etc are written in
or below this subdirectory.
Parameters
----------
root_dir : pathlib.Path
A Path object pointing to the current directory where the script was called.
"""
# check if the root_dir is not already initialized
init_file
=
root_dir
/
config_vars
[
"
init_file
"
]
if
init_file
.
exists
():
logging
.
getLogger
(
"
print
"
).
info
(
f
"
Error: Directory
{
str
(
root_dir
)
}
is already initialized.
"
)
sys
.
exit
(
1
)
else
:
# create the init file
init_file
.
touch
()
# note the execution in the execution summary log
# create the log file and fill it with the headers
record_script_execution_summary
(
root_dir
=
root_dir
)
# record the msg in the log file
record_script_execution_summary
(
root_dir
=
root_dir
,
msg
=
f
"
Initialising MPSD software instance at
{
root_dir
}
.
"
,
)
def
main
():
def
main
():
"""
Execute main entry point.
"""
"""
Execute main entry point.
"""
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
...
@@ -1104,6 +1138,7 @@ def main():
...
@@ -1104,6 +1138,7 @@ def main():
)
)
subparsers
.
required
=
True
subparsers
.
required
=
True
list_of_cmds
=
[
list_of_cmds
=
[
(
"
init
"
,
"
Initialise the MPSD software instance in the current directory
"
),
(
"
available
"
,
"
What is available for installation?
"
),
(
"
available
"
,
"
What is available for installation?
"
),
(
"
install
"
,
"
Install a software environment
"
),
(
"
install
"
,
"
Install a software environment
"
),
# ("reinstall", "Reinstall a package_set"),
# ("reinstall", "Reinstall a package_set"),
...
@@ -1132,11 +1167,13 @@ def main():
...
@@ -1132,11 +1167,13 @@ def main():
)
)
else
:
else
:
subp
.
add_argument
(
# all commands except init need a release version
"
release
"
,
if
cmd
!=
"
init
"
:
type
=
str
,
subp
.
add_argument
(
help
=
"
Release version to prepare, install, reinstall or remove
"
,
"
release
"
,
)
type
=
str
,
help
=
"
Release version to prepare, install, reinstall or remove
"
,
)
if
cmd
in
[
"
install
"
,
"
reinstall
"
,
"
remove
"
]:
if
cmd
in
[
"
install
"
,
"
reinstall
"
,
"
remove
"
]:
# "install" command needs additional documentation
# "install" command needs additional documentation
package_set_help
=
(
package_set_help
=
(
...
@@ -1166,21 +1203,29 @@ def main():
...
@@ -1166,21 +1203,29 @@ def main():
# root dir is the place where this script is called from
# root dir is the place where this script is called from
root_dir
=
Path
(
os
.
getcwd
())
root_dir
=
Path
(
os
.
getcwd
())
# set up logging for all actions except init
if
args
.
action
!=
"
init
"
:
log_file
=
get_installer_log_file_path
(
args
.
release
,
args
.
action
,
root_dir
)
else
:
log_file
=
None
set_up_logging
(
set_up_logging
(
args
.
loglevel
,
args
.
loglevel
,
get_installer_log_file_path
(
args
.
release
,
args
.
action
,
root_dir
)
,
log_file
,
)
)
# sanity check for common mistakes in command line arguments
# sanity check for common mistakes in command line arguments
if
args
.
release
.
endswith
(
"
/
"
):
# happens easily with autocompletion
if
args
.
action
!=
"
init
"
:
logging
.
error
(
if
args
.
release
.
endswith
(
"
/
"
):
# happens easily with autocompletion
f
"
You provided mpsd-release=
'
{
args
.
release
}
'
.
"
logging
.
error
(
f
"
Did you mean
'
{
args
.
release
.
removesuffix
(
'
/
'
)
}
'
?
"
f
"
You provided mpsd-release=
'
{
args
.
release
}
'
.
"
)
f
"
Did you mean
'
{
args
.
release
.
removesuffix
(
'
/
'
)
}
'
?
"
sys
.
exit
(
1
)
)
sys
.
exit
(
1
)
# Check the command and run related function
# Check the command and run related function
if
args
.
action
==
"
remove
"
:
if
args
.
action
==
"
init
"
:
initialize_environment
(
root_dir
)
elif
args
.
action
==
"
remove
"
:
remove_environment
(
args
.
release
,
root_dir
,
args
.
package_set
)
remove_environment
(
args
.
release
,
root_dir
,
args
.
package_set
)
elif
args
.
action
==
"
start-new
"
:
elif
args
.
action
==
"
start-new
"
:
start_new_environment
(
args
.
from_release
,
args
.
to_release
,
root_dir
)
start_new_environment
(
args
.
from_release
,
args
.
to_release
,
root_dir
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_mpsd_software.py
+
19
−
0
View file @
a8e16cc9
...
@@ -520,6 +520,25 @@ def test_remove_environment(tmp_path):
...
@@ -520,6 +520,25 @@ def test_remove_environment(tmp_path):
# done in test_install_environment_zlib
# done in test_install_environment_zlib
def
test_initialize_environment
(
tmp_path
):
"""
Test that init_file is created as expected.
"""
# test that the init file is created as expected
mod
.
initialize_environment
(
tmp_path
)
init_file
=
tmp_path
/
mod
.
config_vars
[
"
init_file
"
]
assert
init_file
.
exists
()
# ensure "Initialising MPSD software ..." is in the log file
log_file
=
tmp_path
/
mod
.
config_vars
[
"
cmd_log_file
"
]
with
open
(
log_file
,
"
r
"
)
as
f
:
assert
(
f
"
Initialising MPSD software instance at
{
tmp_path
}
"
)
in
f
.
read
()
# test that calling again results in warning and exit code 1
with
pytest
.
raises
(
SystemExit
)
as
pytest_wrapped_e
:
mod
.
initialize_environment
(
tmp_path
)
assert
pytest_wrapped_e
.
type
==
SystemExit
assert
pytest_wrapped_e
.
value
.
code
==
1
def
test_interface
(
tmp_path
):
def
test_interface
(
tmp_path
):
"""
Test other things (not implemented yet).
"""
"""
Test other things (not implemented yet).
"""
pass
pass
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment