Skip to content

Config

LUMEServicesSettings

Bases: BaseSettings

Settings describing configuration for default LUME-services provider objects.

Source code in lume_services/config.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class LUMEServicesSettings(BaseSettings):
    """Settings describing configuration for default LUME-services provider objects."""

    model_db: Optional[ModelDBConfig]
    results_db: Optional[MongodbResultsDBConfig]
    prefect: PrefectConfig
    mounted_filesystem: Optional[MountedFilesystem]
    backend: str = "local"
    # something wrong with pydantic literal parsing?
    # Literal["kubernetes", "local", "docker"] = "local"

    class Config:
        # env_file = '.env'
        # env_file_encoding = 'utf-8'
        validate_assignment = True
        env_prefix = "LUME_"
        env_nested_delimiter = "__"

configure(settings=None)

Configure method with default methods for lume-services using ModelDB and MongodbResultsDB. Populates the global _settings object.

Parameters:

Name Type Description Default
settings Optional[LUMEServicesSettings]

LUMEServicesSettings object holding the runtime configuration for services used by LUME-services.

None
Source code in lume_services/config.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def configure(settings: Optional[LUMEServicesSettings] = None):
    """Configure method with default methods for lume-services using ModelDB
    and MongodbResultsDB. Populates the global _settings object.

    Args:
        settings (Optional[LUMEServicesSettings]): LUMEServicesSettings object holding
            the runtime configuration for services used by LUME-services.

    """
    logger.info("Configuring LUME-services environment...")
    if settings is None:
        try:
            settings = LUMEServicesSettings()

        except ValidationError as e:
            raise EnvironmentNotConfiguredError(
                get_env_vars(LUMEServicesSettings), validation_error=e
            )

    # apply prefect config
    if settings.prefect is not None:
        settings.prefect.apply()

    global context, _settings
    model_db = None
    if settings.model_db is not None:
        model_db = ModelDB(settings.model_db)

    results_db = None
    if settings.results_db is not None:
        results_db = MongodbResultsDB(settings.results_db)

    # this could be moved to an enum
    if settings.backend is not None:
        if settings.backend == "kubernetes":
            backend = KubernetesBackend(config=settings.prefect)

        elif settings.backend == "docker":
            backend = DockerBackend(config=settings.prefect)

        elif settings.backend == "local":
            backend = LocalBackend()

        else:
            raise ValueError(f"Unsupported backend {settings.backend}")

    # default to local
    else:
        backend = LocalBackend()

    filesystems = [
        LocalFilesystem(),
    ]

    if settings.mounted_filesystem is not None:
        filesystems.append(settings.mounted_filesystem)

    context = Context(
        model_db=model_db,
        results_db=results_db,
        filesystems=filesystems,
        scheduling_backend=backend
    )
    _settings = settings
    logger.info("Environment configured.")
    logger.debug("Environment configured using %s", settings.dict())