Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/config_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ System Partition Configuration
:required: No
:default: ``{}``

User defined attributes of the system partition that will be accessible from the ReFrame tests.
By default it is an empty dictionary.
User defined attributes of the partition. This will be accessible through the :attr:`~reframe.core.systems.SystemPartition.extras` attribute of the :attr:`~reframe.core.pipeline.RegressionTest.current_partition`.

.. versionadded:: 3.5.0

Expand Down Expand Up @@ -582,6 +581,16 @@ They are associated with `system partitions <#system-partition-configuration>`__
Variables are set after the environment modules are loaded.


.. js:attribute:: .environments[].extras

:required: No
:default: ``{}``

User defined attributes of the environment. This will be accessible through the :attr:`~reframe.core.environments.Environment.extras` attribute of the :attr:`~reframe.core.pipeline.RegressionTest.current_environ`.

.. versionadded:: 3.9.1


.. js:attribute:: .environments[].cc

:required: No
Expand Down
17 changes: 15 additions & 2 deletions reframe/core/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class Environment(jsonext.JSONSerializable):
Users may not create :class:`Environment` objects directly.
'''

def __init__(self, name, modules=None, variables=None):
def __init__(self, name, modules=None, variables=None, extras=None):
modules = modules or []
variables = variables or []
self._name = name
self._modules = normalize_module_list(modules)
self._module_names = [m['name'] for m in self._modules]
self._variables = collections.OrderedDict(variables)
self._extras = extras or {}

@property
def name(self):
Expand Down Expand Up @@ -89,6 +90,17 @@ def variables(self):
'''
return util.MappingView(self._variables)

@property
def extras(self):
'''User defined properties defined in the configuration.

.. versionadded:: 3.9.1

:type: :class:`Dict[str, object]`
'''

return self._extras

def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented
Expand Down Expand Up @@ -161,6 +173,7 @@ def __init__(self,
name,
modules=None,
variables=None,
extras=None,
cc='cc',
cxx='CC',
ftn='ftn',
Expand All @@ -171,7 +184,7 @@ def __init__(self,
fflags=None,
ldflags=None,
**kwargs):
super().__init__(name, modules, variables)
super().__init__(name, modules, variables, extras)
self._cc = cc
self._cxx = cxx
self._ftn = ftn
Expand Down
7 changes: 3 additions & 4 deletions reframe/core/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,11 @@ def devices(self):

@property
def extras(self):
'''User defined attributes of the system.

By default, it is an empty dictionary.
'''User defined properties defined in the configuration.

.. versionadded:: 3.5.0

:type: :class:`object`
:type: :class:`Dict[str, object]`
'''
return self._extras

Expand Down Expand Up @@ -481,6 +479,7 @@ def create(cls, site_config):
name=e,
modules=site_config.get(f'environments/@{e}/modules'),
variables=site_config.get(f'environments/@{e}/variables'),
extras=site_config.get(f'environments/@{e}/extras'),
cc=site_config.get(f'environments/@{e}/cc'),
cxx=site_config.get(f'environments/@{e}/cxx'),
ftn=site_config.get(f'environments/@{e}/ftn'),
Expand Down
2 changes: 2 additions & 0 deletions reframe/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
"type": "array",
"items": {"type": "string"}
},
"extras": {"type": "object"},
"target_systems": {"$ref": "#/defs/system_ref"}
},
"required": ["name"],
Expand Down Expand Up @@ -494,6 +495,7 @@
"environments/cxxflags": [],
"environments/fflags": [],
"environments/ldflags": [],
"environments/extras": {},
"environments/target_systems": ["*"],
"general/check_search_path": ["${RFM_INSTALL_PREFIX}/checks/"],
"general/check_search_recursive": false,
Expand Down
8 changes: 8 additions & 0 deletions unittests/resources/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,21 @@
'modules': [
{'name': 'PrgEnv-gnu', 'collection': False, 'path': None}
],
'extras': {
'foo': 2,
'bar': 'y'
},
},
{
'name': 'PrgEnv-gnu',
'modules': ['PrgEnv-gnu'],
'cc': 'gcc',
'cxx': 'g++',
'ftn': 'gfortran',
'extras': {
'foo': 1,
'bar': 'x'
},
'target_systems': ['testsys:login']
},
{
Expand Down
5 changes: 5 additions & 0 deletions unittests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def test_select_subconfig():
assert site_config.get('environments/1/cxx') == 'CC'
assert (site_config.get('environments/@PrgEnv-cray/modules') ==
[{'name': 'PrgEnv-cray', 'collection': False, 'path': None}])
assert site_config.get('environments/@PrgEnv-gnu/extras') == {'foo': 1,
'bar': 'x'}
assert site_config.get('environments/@PrgEnv-cray/extras') == {}

assert len(site_config.get('general')) == 1
assert site_config.get('general/0/check_search_path') == ['a:b']

Expand Down Expand Up @@ -358,6 +362,7 @@ def test_system_create():
assert len(partition.environs) == 2
assert partition.environment('PrgEnv-gnu').cc == 'cc'
assert partition.environment('PrgEnv-gnu').cflags == []
assert partition.environment('PrgEnv-gnu').extras == {'foo': 2, 'bar': 'y'}

# Check resource instantiation
resource_spec = partition.get_resource('gpu', num_gpus_per_node=16)
Expand Down
21 changes: 18 additions & 3 deletions unittests/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def user_runtime(make_exec_ctx_g):
def env0():
return env.Environment(
'TestEnv1', ['testmod_foo'],
[('_var0', 'val1'), ('_var2', '$_var0'), ('_var3', '${_var1}')]
[('_var0', 'val1'), ('_var2', '$_var0'), ('_var3', '${_var1}')],
{'foo': 1, 'bar': 2}
)


Expand All @@ -74,8 +75,22 @@ def test_env_construction(base_environ, env0):
assert env0.variables['_var0'] == 'val1'

# No variable expansion, if environment is not loaded
env0.variables['_var2'] == '$_var0'
env0.variables['_var3'] == '${_var1}'
assert env0.variables['_var2'] == '$_var0'
assert env0.variables['_var3'] == '${_var1}'

# Assert extras
assert env0.extras == {'foo': 1, 'bar': 2}


def test_progenv_construction():
environ = env.ProgEnvironment('myenv',
modules=['modfoo'],
variables=[('var', 'val')],
extras={'foo': 'bar'})
assert environ.name == 'myenv'
assert environ.modules == ['modfoo']
assert environ.variables == {'var': 'val'}
assert environ.extras == {'foo': 'bar'}


def test_env_snapshot(base_environ, env0, env1):
Expand Down