Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dedal
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EBRAINS RI
Tech Hub
Platform
EBRAINS Software Distribution
dedal
Commits
a4f529d2
Commit
a4f529d2
authored
3 months ago
by
Adrian Ciu
Browse files
Options
Downloads
Patches
Plain Diff
esd-spack-installation: added spack env exceptions
parent
8ee65d4b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dedal/tests/spack_from_scratch_test.py
+16
-8
16 additions, 8 deletions
dedal/tests/spack_from_scratch_test.py
esd/error_handling/exceptions.py
+5
-0
5 additions, 0 deletions
esd/error_handling/exceptions.py
esd/spack_manager/SpackManager.py
+17
-9
17 additions, 9 deletions
esd/spack_manager/SpackManager.py
with
38 additions
and
17 deletions
dedal/tests/spack_from_scratch_test.py
+
16
−
8
View file @
a4f529d2
...
@@ -2,21 +2,30 @@ from pathlib import Path
...
@@ -2,21 +2,30 @@ from pathlib import Path
import
pytest
import
pytest
from
esd.error_handling.exceptions
import
BashCommandException
from
esd.error_handling.exceptions
import
BashCommandException
,
NoSpackEnvironmentException
from
esd.model.SpackModel
import
SpackModel
from
esd.model.SpackModel
import
SpackModel
from
esd.spack_manager.factory.SpackManagerScratch
import
SpackManagerScratch
from
esd.spack_manager.factory.SpackManagerScratch
import
SpackManagerScratch
def
test_spack_repo_exists_1
():
def
test_spack_repo_exists_1
():
spack_manager
=
SpackManagerScratch
()
assert
spack_manager
.
spack_repo_exists
(
'
ebrains-spack-builds
'
)
==
False
def
test_spack_repo_exists_2
():
install_dir
=
Path
(
'
./install
'
).
resolve
()
install_dir
=
Path
(
'
./install
'
).
resolve
()
env
=
SpackModel
(
'
ebrains-spack-builds
'
,
install_dir
)
env
=
SpackModel
(
'
ebrains-spack-builds
'
,
install_dir
)
spack_manager
=
SpackManagerScratch
(
env
=
env
)
spack_manager
=
SpackManagerScratch
(
env
=
env
)
assert
spack_manager
.
spack_repo_exists
(
env
.
env_name
)
==
False
with
pytest
.
raises
(
NoSpackEnvironmentException
):
spack_manager
.
spack_repo_exists
(
env
.
env_name
)
def
test_spack_repo_exists_2
():
# def test_spack_repo_exists_3():
spack_manager
=
SpackManagerScratch
()
# install_dir = Path('./install').resolve()
assert
spack_manager
.
spack_repo_exists
(
'
ebrains-spack-builds
'
)
==
False
# env = SpackModel('ebrains-spack-builds', install_dir)
# spack_manager = SpackManagerScratch(env=env)
# spack_manager.setup_spack_env()
# assert spack_manager.spack_repo_exists(env.env_name) == False
def
test_spack_from_scratch_setup_1
():
def
test_spack_from_scratch_setup_1
():
...
@@ -55,10 +64,9 @@ def test_spack_from_scratch_setup_4():
...
@@ -55,10 +64,9 @@ def test_spack_from_scratch_setup_4():
assert
spack_manager
.
spack_env_exists
()
==
True
assert
spack_manager
.
spack_env_exists
()
==
True
def
test_spack_
from_scratch_bash_error
():
def
test_spack_
not_a_valid_repo
():
env
=
SpackModel
(
'
ebrains-spack-builds
'
,
Path
(),
None
)
env
=
SpackModel
(
'
ebrains-spack-builds
'
,
Path
(),
None
)
repo
=
env
repo
=
env
#
spack_manager
=
SpackManagerScratch
(
env
=
env
,
repos
=
[
repo
],
system_name
=
'
ebrainslab
'
)
spack_manager
=
SpackManagerScratch
(
env
=
env
,
repos
=
[
repo
],
system_name
=
'
ebrainslab
'
)
with
pytest
.
raises
(
BashCommand
Exception
):
with
pytest
.
raises
(
NoSpackEnvironment
Exception
):
spack_manager
.
add_spack_repo
(
repo
.
path
,
repo
.
env_name
)
spack_manager
.
add_spack_repo
(
repo
.
path
,
repo
.
env_name
)
This diff is collapsed.
Click to expand it.
esd/error_handling/exceptions.py
+
5
−
0
View file @
a4f529d2
...
@@ -11,3 +11,8 @@ class BashCommandException(SpackException):
...
@@ -11,3 +11,8 @@ class BashCommandException(SpackException):
"""
"""
To be thrown when an invalid input is received.
To be thrown when an invalid input is received.
"""
"""
class
NoSpackEnvironmentException
(
SpackException
):
"""
To be thrown when an invalid input is received.
"""
\ No newline at end of file
This diff is collapsed.
Click to expand it.
esd/spack_manager/SpackManager.py
+
17
−
9
View file @
a4f529d2
...
@@ -2,7 +2,7 @@ import os
...
@@ -2,7 +2,7 @@ import os
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
from
pathlib
import
Path
from
pathlib
import
Path
from
esd.error_handling.exceptions
import
BashCommandException
from
esd.error_handling.exceptions
import
BashCommandException
,
NoSpackEnvironmentException
from
esd.logger.logger_builder
import
get_logger
from
esd.logger.logger_builder
import
get_logger
from
esd.model.SpackModel
import
SpackModel
from
esd.model.SpackModel
import
SpackModel
from
esd.utils.utils
import
run_command
,
git_clone_repo
from
esd.utils.utils
import
run_command
,
git_clone_repo
...
@@ -90,7 +90,7 @@ class SpackManager(ABC):
...
@@ -90,7 +90,7 @@ class SpackManager(ABC):
else
:
else
:
self
.
logger
.
debug
(
f
'
Spack repository
{
repo
.
env_name
}
already added
'
)
self
.
logger
.
debug
(
f
'
Spack repository
{
repo
.
env_name
}
already added
'
)
def
spack_repo_exists
(
self
,
repo_name
:
str
)
->
bool
:
def
spack_repo_exists
(
self
,
repo_name
:
str
)
->
bool
|
None
:
"""
Check if the given Spack repository exists.
"""
"""
Check if the given Spack repository exists.
"""
if
self
.
env
is
None
:
if
self
.
env
is
None
:
result
=
run_command
(
"
bash
"
,
"
-c
"
,
result
=
run_command
(
"
bash
"
,
"
-c
"
,
...
@@ -101,11 +101,15 @@ class SpackManager(ABC):
...
@@ -101,11 +101,15 @@ class SpackManager(ABC):
if
result
is
None
:
if
result
is
None
:
return
False
return
False
else
:
else
:
result
=
run_command
(
"
bash
"
,
"
-c
"
,
if
self
.
spack_env_exists
():
result
=
run_command
(
"
bash
"
,
"
-c
"
,
f
'
source
{
self
.
spack_setup_script
}
&& spack env activate -p
{
self
.
env_path
}
&& spack repo list
'
,
f
'
source
{
self
.
spack_setup_script
}
&& spack env activate -p
{
self
.
env_path
}
&& spack repo list
'
,
check
=
True
,
check
=
True
,
capture_output
=
True
,
text
=
True
,
logger
=
self
.
logger
,
capture_output
=
True
,
text
=
True
,
logger
=
self
.
logger
,
debug_msg
=
f
'
Checking if repository
{
repo_name
}
was added
'
)
debug_msg
=
f
'
Checking if repository
{
repo_name
}
was added
'
)
else
:
self
.
logger
.
debug
(
'
No spack environment defined
'
)
raise
NoSpackEnvironmentException
(
'
No spack environment defined
'
)
if
result
is
None
:
if
result
is
None
:
return
False
return
False
return
any
(
line
.
strip
().
endswith
(
repo_name
)
for
line
in
result
.
stdout
.
splitlines
())
return
any
(
line
.
strip
().
endswith
(
repo_name
)
for
line
in
result
.
stdout
.
splitlines
())
...
@@ -122,12 +126,16 @@ class SpackManager(ABC):
...
@@ -122,12 +126,16 @@ class SpackManager(ABC):
def
add_spack_repo
(
self
,
repo_path
:
Path
,
repo_name
:
str
):
def
add_spack_repo
(
self
,
repo_path
:
Path
,
repo_name
:
str
):
"""
Add the Spack repository if it does not exist.
"""
"""
Add the Spack repository if it does not exist.
"""
run_command
(
"
bash
"
,
"
-c
"
,
if
self
.
spack_env_exists
():
f
'
source
{
self
.
spack_setup_script
}
&& spack env activate -p
{
self
.
env_path
}
&& spack repo add
{
repo_path
}
/
{
repo_name
}
'
,
run_command
(
"
bash
"
,
"
-c
"
,
check
=
True
,
logger
=
self
.
logger
,
f
'
source
{
self
.
spack_setup_script
}
&& spack env activate -p
{
self
.
env_path
}
&& spack repo add
{
repo_path
}
/
{
repo_name
}
'
,
debug_msg
=
f
"
Added
{
repo_name
}
to spack environment
{
self
.
env
.
env_name
}
"
,
check
=
True
,
logger
=
self
.
logger
,
exception_msg
=
f
"
Failed to add
{
repo_name
}
to spack environment
{
self
.
env
.
env_name
}
"
,
debug_msg
=
f
"
Added
{
repo_name
}
to spack environment
{
self
.
env
.
env_name
}
"
,
exception
=
BashCommandException
)
exception_msg
=
f
"
Failed to add
{
repo_name
}
to spack environment
{
self
.
env
.
env_name
}
"
,
exception
=
BashCommandException
)
else
:
self
.
logger
.
debug
(
'
No spack environment defined
'
)
raise
NoSpackEnvironmentException
(
'
No spack environment defined
'
)
def
get_spack_installed_version
(
self
):
def
get_spack_installed_version
(
self
):
spack_version
=
run_command
(
"
bash
"
,
"
-c
"
,
f
'
source
{
self
.
spack_setup_script
}
&& spack --version
'
,
spack_version
=
run_command
(
"
bash
"
,
"
-c
"
,
f
'
source
{
self
.
spack_setup_script
}
&& spack --version
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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