Skip to content

Commit 3544756

Browse files
author
Vasileios Karakasis
committed
Address PR comments + other improvements
1 parent c032b7e commit 3544756

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

reframe/core/buildsystems.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from reframe.core.exceptions import BuildSystemError
1313

1414

15+
class _UndefinedType:
16+
'''Used as an initial value for undefined values instead of None.'''
17+
18+
19+
_Undefined = _UndefinedType()
20+
21+
1522
class BuildSystem(abc.ABC):
1623
'''The abstract base class of any build system.
1724
@@ -810,7 +817,7 @@ class Spack(BuildSystem):
810817
#:
811818
#: .. code-block:: bash
812819
#:
813-
#: spack env activate -d <environment directory>
820+
#: spack env activate -V -d <environment directory>
814821
#:
815822
#: ReFrame looks for environments in the test's
816823
#: :attr:`~reframe.core.pipeline.RegressionTest.sourcesdir`.
@@ -819,7 +826,7 @@ class Spack(BuildSystem):
819826
#:
820827
#: :type: :class:`str` or :class:`None`
821828
#: :default: :class:`None`
822-
environment = fields.TypedField(str, type(None))
829+
environment = fields.TypedField(typ.Str[r'\S+'], _UndefinedType)
823830

824831
#: The list of specs to build and install within the given environment.
825832
#:
@@ -852,15 +859,15 @@ class Spack(BuildSystem):
852859
def __init__(self):
853860
super().__init__()
854861
self.specs = []
855-
self.environment = None
862+
self.environment = _Undefined
856863
self.emit_load_cmds = True
857864
self.install_opts = []
858865
self._prefix_save = None
859866

860867
def emit_build_commands(self, environ):
861868
self._prefix_save = os.getcwd()
862-
if not self.environment:
863-
raise BuildSystemError(f"'environment' must not be empty")
869+
if self.environment is _Undefined:
870+
raise BuildSystemError(f'no Spack environment is defined')
864871

865872
ret = self._env_activate_cmds()
866873
if self.specs:
@@ -876,7 +883,7 @@ def emit_build_commands(self, environ):
876883

877884
def _env_activate_cmds(self):
878885
return [f'. $SPACK_ROOT/share/spack/setup-env.sh',
879-
f'spack env activate -d {self.environment}']
886+
f'spack env activate -V -d {self.environment}']
880887

881888
def prepare_cmds(self):
882889
cmds = self._env_activate_cmds()

unittests/test_buildsystems.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,12 @@ def test_spack(environ, tmp_path):
250250
with osext.change_dir(tmp_path):
251251
assert build_system.emit_build_commands(environ) == [
252252
f'. $SPACK_ROOT/share/spack/setup-env.sh',
253-
f'spack env activate -d {build_system.environment}',
253+
f'spack env activate -V -d {build_system.environment}',
254254
f'spack install -j 10'
255255
]
256256
assert build_system.prepare_cmds() == [
257257
f'. $SPACK_ROOT/share/spack/setup-env.sh',
258-
f'spack env activate -d {build_system.environment}',
258+
f'spack env activate -V -d {build_system.environment}',
259259
]
260260

261261

@@ -267,13 +267,13 @@ def test_spack_with_spec(environ, tmp_path):
267267
with osext.change_dir(tmp_path):
268268
assert build_system.emit_build_commands(environ) == [
269269
f'. $SPACK_ROOT/share/spack/setup-env.sh',
270-
f'spack env activate -d {build_system.environment}',
270+
f'spack env activate -V -d {build_system.environment}',
271271
f'spack add {specs_str}',
272272
f'spack install'
273273
]
274274
assert build_system.prepare_cmds() == [
275275
f'. $SPACK_ROOT/share/spack/setup-env.sh',
276-
f'spack env activate -d {build_system.environment}',
276+
f'spack env activate -V -d {build_system.environment}',
277277
f'spack load {specs_str}',
278278
]
279279

0 commit comments

Comments
 (0)