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
15e436de
Commit
15e436de
authored
1 year ago
by
Ashwin Kumar Karnad
Browse files
Options
Downloads
Patches
Plain Diff
first attempt at get_root_dir
parent
a8e16cc9
Branches
Branches containing commit
No related tags found
1 merge request
!89
Implement the init command
Pipeline
#374347
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mpsd_software_manager/mpsd_software.py
+68
-16
68 additions, 16 deletions
src/mpsd_software_manager/mpsd_software.py
with
68 additions
and
16 deletions
src/mpsd_software_manager/mpsd_software.py
+
68
−
16
View file @
15e436de
...
@@ -1115,6 +1115,49 @@ def initialize_environment(root_dir: Path) -> None:
...
@@ -1115,6 +1115,49 @@ def initialize_environment(root_dir: Path) -> None:
)
)
def
get_root_dir
()
->
Path
:
"""
Get the root directory of the installation.
Look for the hidden file ``.mpsd-software-root``
(defined in config_vars[
"
init_file
"
])
in the current directory, or any parent directory.
If found, return the path to the root directory
of the MPSD software instance.
If not found, exit with an error message.
Returns
-------
root_dir : pathlib.Path
A Path object pointing to the root directory of the installation.
This folder contains the hidden file ``.mpsd-software-root``,
``mpsd_releases`` ( for eg ``dev-23a``) and ``mpsd-spack-cache``.
"""
# check if the root_dir is not already initialized
script_call_dir
=
Path
.
cwd
()
init_file
=
script_call_dir
/
config_vars
[
"
init_file
"
]
if
not
init_file
.
exists
():
for
parent_folder
in
script_call_dir
.
parents
:
init_file
=
parent_folder
/
config_vars
[
"
init_file
"
]
if
init_file
.
exists
():
script_call_dir
=
parent_folder
return
script_call_dir
logging
.
getLogger
(
"
print
"
).
info
(
"
Error: Couldnt find MPSD software instance
"
"
in the current directory or any parent directory.
\n
"
f
"
Directory
{
str
(
script_call_dir
)
}
is not a MPSD software instance.
\n
"
"
Please run
'
mpsd-software init
'
to
"
"
initialise the software instance here,
\n
"
"
or switch to a directory which is already initialised.
\n
\n
"
f
"
Hint: Look for the hidden file
{
config_vars
[
'
init_file
'
]
}
"
"
to check if a directory is initialised
"
)
sys
.
exit
(
1
)
else
:
return
script_call_dir
def
main
():
def
main
():
"""
Execute main entry point.
"""
"""
Execute main entry point.
"""
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
...
@@ -1200,32 +1243,41 @@ def main():
...
@@ -1200,32 +1243,41 @@ def main():
# Carry out the action
# Carry out the action
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# Set up logging without file handle:
# this is used in the init action and for logging the
# get_root_dir() function
set_up_logging
(
args
.
loglevel
)
# Check if the action is init
# if so, call the init function and exit
if
args
.
action
==
"
init
"
:
initialize_environment
(
Path
(
os
.
getcwd
()))
sys
.
exit
(
0
)
# 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
=
get_root_dir
()
# set up logging for all actions except init
# set up logging ( with file handler) for all actions (except init)
if
args
.
action
!=
"
init
"
:
log_file
=
get_installer_log_file_path
(
log_file
=
get_installer_log_file_path
(
args
.
release
,
args
.
action
,
root_dir
)
args
.
release
,
else
:
args
.
action
,
log_file
=
None
root_dir
,
)
set_up_logging
(
set_up_logging
(
args
.
loglevel
,
args
.
loglevel
,
log_file
,
log_file
,
)
)
# sanity check for common mistakes in command line arguments
# sanity check for common mistakes in command line arguments
if
args
.
action
!=
"
init
"
:
if
args
.
release
.
endswith
(
"
/
"
):
# happens easily with autocompletion
if
args
.
release
.
endswith
(
"
/
"
):
# happens easily with autocompletion
logging
.
error
(
logging
.
error
(
f
"
You provided mpsd-release=
'
{
args
.
release
}
'
.
"
f
"
You provided mpsd-release=
'
{
args
.
release
}
'
.
"
f
"
Did you mean
'
{
args
.
release
.
removesuffix
(
'
/
'
)
}
'
?
"
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
==
"
init
"
:
if
args
.
action
==
"
remove
"
:
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.
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