# Copyright 2022-2026 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import ramble.language.shared_language
"""This package contains directives that can be used within a system.
Directives are functions that can be called inside a system
definition to modify then system, for example:
.. code-block:: python
class MySystem(System):
default_platform('c2')
In the above example, 'default_platform' is a ramble directive
"""
system_directive = SystemMeta.directive
[docs]
@system_directive("default_workflow_managers")
def default_workflow_manager(name, **kwargs):
"""Sets the default workflow manager for this system
Args:
name (str): The name of the default workflow manager
"""
def _execute_default_workflow_manager(obj):
obj.system_default_workflow_manager = name
return _execute_default_workflow_manager
[docs]
@system_directive(dicts=())
def default_package_manager(name, **kwargs):
"""Sets the default package manager for this system
Args:
name (str): The name of the default package manager
"""
def _execute_default_package_manager(obj):
obj.system_default_package_manager = name
return _execute_default_package_manager
[docs]
@system_directive(dicts="variable_defaults")
def variable_defaults(variable_definitions, when=None, **kwargs):
"""Defines default values for variables
Args:
variable_definitions (dict): Mapping of variable name to value
when (list | None): List of when conditions to apply to directive
"""
def _execute_variable_defaults(obj):
when_list = ramble.language.language_helpers.build_when_list(
when, obj, str(variable_definitions), "variable_defaults"
)
when_key = frozenset(when_list)
if when_key not in obj.variable_defaults:
obj.variable_defaults[when_key] = {}
obj.variable_defaults[when_key].update(variable_definitions)
return _execute_variable_defaults
[docs]
@system_directive(dicts=())
def system_family(*names: str, **kwargs):
"""Add a new family to this system
Args:
name (str): Name of family to apply to this system
"""
return ramble.language.shared_language.class_family(*names, **kwargs)