Skip to content

settings

Generic strategy for adding configurations to the session.

NoneType = type(None) module-attribute

SettingsConfig

Bases: AttrDict

Configuration for a generic "settings" filter.

This strategy stores settings in the session such that they are available for other strategies. For this to work, this strategy should be added to the end of the pipeline (since it uses the initiate() method).

The settings are stored as a JSON string which can be accessed by its label.

Source code in oteapi_dlite/strategies/settings.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class SettingsConfig(AttrDict):
    """Configuration for a generic "settings" filter.

    This strategy stores settings in the session such that they are
    available for other strategies.  For this to work, this strategy
    should be added to the end of the pipeline (since it uses the
    `initiate()` method).

    The settings are stored as a JSON string which can be accessed
    by its label.

    """

    label: Annotated[
        str,
        Field(
            description=(
                "Label for accessing this configuration.  "
                "It should be unique."
            ),
        ),
    ]
    settings: Annotated[
        JsonValue,
        Field(
            description=(
                "The configurations to be stored, represented as a Python "
                "object that can be serialised to JSON."
            ),
        ),
    ]

label: Annotated[str, Field(description='Label for accessing this configuration. It should be unique.')] instance-attribute

settings: Annotated[JsonValue, Field(description='The configurations to be stored, represented as a Python object that can be serialised to JSON.')] instance-attribute

SettingsFilterConfig

Bases: FilterConfig

Settings strategy config.

Source code in oteapi_dlite/strategies/settings.py
48
49
50
51
52
53
54
class SettingsFilterConfig(FilterConfig):
    """Settings strategy config."""

    configuration: Annotated[
        SettingsConfig,
        Field(description="Settings strategy-specific configuration."),
    ]

configuration: Annotated[SettingsConfig, Field(description='Settings strategy-specific configuration.')] instance-attribute

SettingsStrategy

Generic settings strategy for storing settings for other strategies.

Registers strategies:

  • ("mediaType", "application/vnd.dlite-settings")
Source code in oteapi_dlite/strategies/settings.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@dataclass
class SettingsStrategy:
    """Generic settings strategy for storing settings for other
    strategies.

    **Registers strategies**:

    - `("mediaType", "application/vnd.dlite-settings")`

    """

    filter_config: SettingsFilterConfig

    def initialize(self) -> AttrDict:
        """Store settings."""
        config = self.filter_config.configuration

        return AttrDict(dlite_settings={config.label: config.settings})

    def get(self) -> AttrDict:
        """Do nothing."""
        return AttrDict()

filter_config: SettingsFilterConfig instance-attribute

get()

Do nothing.

Source code in oteapi_dlite/strategies/settings.py
76
77
78
def get(self) -> AttrDict:
    """Do nothing."""
    return AttrDict()

initialize()

Store settings.

Source code in oteapi_dlite/strategies/settings.py
70
71
72
73
74
def initialize(self) -> AttrDict:
    """Store settings."""
    config = self.filter_config.configuration

    return AttrDict(dlite_settings={config.label: config.settings})